// React Components for Gopikrishna Chegoni's Portfolio — Simplified, Prioritized & Recruiter-Focused
const { useState, useEffect, useRef, useMemo } = React;

// Native SVG Icon Registry
const SVG_ICONS = {
  ExternalLink: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/>
    </svg>
  ),
  CheckCircle: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/>
    </svg>
  ),
  ArrowLeft: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/>
    </svg>
  ),
  ArrowUpRight: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <line x1="7" y1="17" x2="17" y2="7"/><polyline points="7 7 17 7 17 17"/>
    </svg>
  ),
  ChevronDown: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <polyline points="6 9 12 15 18 9"/>
    </svg>
  ),
  ChevronUp: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <polyline points="18 15 12 9 6 15"/>
    </svg>
  ),
  Menu: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="18" x2="21" y2="18"/>
    </svg>
  ),
  Github: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22"/>
    </svg>
  ),
  Linkedin: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M16 8a6 6 0 0 1 6 6v7h-4v-7a2 2 0 0 0-2-2 2 2 0 0 0-2 2v7h-4v-7a6 6 0 0 1 6-6z"/><rect x="2" y="9" width="4" height="12"/><circle cx="4" cy="4" r="2"/>
    </svg>
  ),
  GitFork: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <circle cx="12" cy="18" r="3"/><circle cx="6" cy="6" r="3"/><circle cx="18" cy="6" r="3"/><path d="M18 9v1a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V9"/><path d="M12 12v3"/>
    </svg>
  ),
  Mail: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"/><polyline points="22,6 12,13 2,6"/>
    </svg>
  ),
  Code: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>
    </svg>
  ),
  Close: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/>
    </svg>
  ),
  Search: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/>
    </svg>
  ),
  FileText: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 9"/>
    </svg>
  ),
  Terminal: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/>
    </svg>
  ),
  Cpu: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <rect x="4" y="4" width="16" height="16" rx="2"/><rect x="9" y="9" width="6" height="6"/><line x1="9" y1="1" x2="9" y2="4"/><line x1="15" y1="1" x2="15" y2="4"/><line x1="9" y1="20" x2="9" y2="23"/><line x1="15" y1="20" x2="15" y2="23"/><line x1="20" y1="9" x2="23" y2="9"/><line x1="20" y1="14" x2="23" y2="14"/><line x1="1" y1="9" x2="4" y2="9"/><line x1="1" y1="14" x2="4" y2="14"/>
    </svg>
  ),
  Layers: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <polygon points="12 2 2 7 12 12 22 7 12 2"/><polyline points="2 17 12 22 22 17"/><polyline points="2 12 12 17 22 12"/>
    </svg>
  ),
  Activity: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/>
    </svg>
  ),
  Sparkles: (p) => (
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <path d="M12 2l2.4 7.2L22 12l-7.6 2.8L12 22l-2.4-7.2L2 12l7.6-2.8z"/>
    </svg>
  ),
  Play: (p) => (
    <svg viewBox="0 0 24 24" fill="currentColor" stroke="none" {...p}>
      <polygon points="5 3 19 12 5 21 5 3"/>
    </svg>
  )
};

const Icon = ({ name, size = 18, className = "", style = {} }) => {
  const IconComponent = SVG_ICONS[name] || SVG_ICONS['Code'];
  return <IconComponent width={size} height={size} className={className} style={style} />;
};

// Scroll Reveal with IntersectionObserver
const ScrollReveal = ({ children, className = "" }) => {
  const ref = useRef(null);
  const [isVisible, setIsVisible] = useState(false);

  useEffect(() => {
    const el = ref.current;
    if (!el) return;

    const observer = new IntersectionObserver(
      ([entry]) => {
        if (entry.isIntersecting) {
          setIsVisible(true);
          observer.unobserve(el);
        }
      },
      { threshold: 0.05, rootMargin: '0px 0px -30px 0px' }
    );

    observer.observe(el);
    return () => observer.disconnect();
  }, []);

  return (
    <div
      ref={ref}
      className={`transition-all duration-700 ease-out transform ${
        isVisible ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-6'
      } ${className}`}
    >
      {children}
    </div>
  );
};

// Animated Number Counter
const AnimatedCounter = ({ value, duration = 1200, className = "" }) => {
  const ref = useRef(null);
  const [displayValue, setDisplayValue] = useState(value);
  const hasAnimated = useRef(false);

  const parsed = useMemo(() => {
    if (typeof value !== 'string' && typeof value !== 'number') return null;
    const str = String(value).trim();
    const match = str.match(/^([^0-9.]*)([0-9]+(?:\.[0-9]+)?)(.*)$/);
    if (!match) return null;
    const [, prefix, numStr, suffix] = match;
    const num = parseFloat(numStr);
    if (isNaN(num)) return null;
    const hasDecimal = numStr.includes('.');
    const decimals = hasDecimal ? numStr.split('.')[1].length : 0;
    return { prefix, targetNum: num, decimals, suffix };
  }, [value]);

  useEffect(() => {
    if (!parsed) return;
    const el = ref.current;
    if (!el) return;

    const prefersReduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
    if (prefersReduced) {
      setDisplayValue(value);
      return;
    }

    const observer = new IntersectionObserver(
      ([entry]) => {
        if (entry.isIntersecting && !hasAnimated.current) {
          hasAnimated.current = true;
          observer.unobserve(el);

          const startTime = performance.now();
          const { prefix, targetNum, decimals, suffix } = parsed;

          const animate = (currentTime) => {
            const elapsed = currentTime - startTime;
            const progress = Math.min(1, elapsed / duration);
            const easeProgress = 1 - Math.pow(1 - progress, 3);
            const currentNum = easeProgress * targetNum;

            const formattedNum = decimals > 0 
              ? currentNum.toFixed(decimals) 
              : Math.round(currentNum);

            setDisplayValue(`${prefix}${formattedNum}${suffix}`);

            if (progress < 1) {
              requestAnimationFrame(animate);
            } else {
              setDisplayValue(value);
            }
          };

          requestAnimationFrame(animate);
        }
      },
      { threshold: 0.15 }
    );

    observer.observe(el);
    return () => observer.disconnect();
  }, [parsed, value, duration]);

  if (!parsed) {
    return <span className={className}>{value}</span>;
  }

  return (
    <span ref={ref} className={className}>
      {hasAnimated.current ? displayValue : (displayValue || `${parsed.prefix}0${parsed.suffix}`)}
    </span>
  );
};

// Desktop-Only Custom Cursor (Disabled on Touch / Coarse Pointers)
const CustomCursor = () => {
  const [pos, setPos] = useState({ x: -100, y: -100 });
  const [isVisible, setIsVisible] = useState(false);
  const [isFinePointer, setIsFinePointer] = useState(false);

  useEffect(() => {
    const isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
    const hasFinePointer = window.matchMedia && window.matchMedia('(pointer: fine)').matches;
    if (isTouch || !hasFinePointer) {
      setIsFinePointer(false);
      return;
    }
    setIsFinePointer(true);

    const handleMouseMove = (e) => {
      setPos({ x: e.clientX, y: e.clientY });
      if (!isVisible) setIsVisible(true);
    };

    const handleMouseLeave = () => setIsVisible(false);

    window.addEventListener('mousemove', handleMouseMove, { passive: true });
    document.addEventListener('mouseleave', handleMouseLeave);
    return () => {
      window.removeEventListener('mousemove', handleMouseMove);
      document.removeEventListener('mouseleave', handleMouseLeave);
    };
  }, [isVisible]);

  if (!isFinePointer || !isVisible) return null;

  return (
    <div
      className="custom-cursor"
      style={{ left: `${pos.x}px`, top: `${pos.y}px` }}
    />
  );
};

// Scroll Progress Bar at Top of Viewport
const ScrollProgressBar = () => {
  const [progress, setProgress] = useState(0);

  useEffect(() => {
    const handleScroll = () => {
      const totalScroll = document.documentElement.scrollHeight - window.innerHeight;
      if (totalScroll > 0) {
        const currentProgress = (window.scrollY / totalScroll) * 100;
        setProgress(Math.min(100, Math.max(0, currentProgress)));
      }
    };

    window.addEventListener('scroll', handleScroll, { passive: true });
    return () => window.removeEventListener('scroll', handleScroll);
  }, []);

  return <div id="scroll-progress-bar" style={{ width: `${progress}%` }} />;
};

// 🎨 GIANT HIDDEN ARTWORK / PRINTED ART POSTER MARGINS: Massive cropped words spanning the viewport behind content
const PosterArtworkMargins = () => {
  const [scrollY, setScrollY] = useState(0);
  const [isWideScreen, setIsWideScreen] = useState(false);
  const rafRef = useRef(null);
  const targetScrollRef = useRef(0);
  const currentScrollRef = useRef(0);

  // 5 Iconic Words Anchoring Key Sections Down the Page
  const posterAnchors = useMemo(() => [
    { id: "think", left: "THI", right: "NK", full: "THINK", top: 280, parallaxFactor: 0.14 },
    { id: "build", left: "BU", right: "ILD", full: "BUILD", top: 1650, parallaxFactor: 0.16 },
    { id: "break", left: "BRE", right: "AK", full: "BREAK", top: 2950, parallaxFactor: 0.18 },
    { id: "learn", left: "LEA", right: "RN", full: "LEARN", top: 4150, parallaxFactor: 0.15 },
    { id: "ship", left: "SH", right: "IP", full: "SHIP", top: 5350, parallaxFactor: 0.16 },
    { id: "repeat", left: "REP", right: "EAT", full: "REPEAT", top: 6250, parallaxFactor: 0.14 },
  ], []);

  useEffect(() => {
    const checkWidth = () => {
      setIsWideScreen(window.innerWidth >= 1200);
    };
    checkWidth();

    const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

    const handleScroll = () => {
      targetScrollRef.current = window.scrollY || window.pageYOffset;
    };

    let isRunning = true;
    const animateScroll = () => {
      if (!isRunning) return;

      if (!prefersReducedMotion) {
        currentScrollRef.current += (targetScrollRef.current - currentScrollRef.current) * 0.1;
        setScrollY(currentScrollRef.current);
      } else {
        setScrollY(targetScrollRef.current);
      }

      rafRef.current = requestAnimationFrame(animateScroll);
    };

    window.addEventListener('resize', checkWidth, { passive: true });
    window.addEventListener('scroll', handleScroll, { passive: true });
    rafRef.current = requestAnimationFrame(animateScroll);

    return () => {
      isRunning = false;
      if (rafRef.current) cancelAnimationFrame(rafRef.current);
      window.removeEventListener('resize', checkWidth);
      window.removeEventListener('scroll', handleScroll);
    };
  }, []);

  if (!isWideScreen) return null;

  return (
    <div className="poster-artwork-layer" aria-hidden="true">
      {posterAnchors.map((item) => {
        // Calculate relative parallax displacement
        const offset = ((scrollY - item.top + 400) * item.parallaxFactor * -0.6).toFixed(1);

        return (
          <div
            key={item.id}
            className="poster-word-row"
            style={{
              top: `${item.top}px`,
              transform: `translate3d(0, ${offset}px, 0)`
            }}
          >
            {/* Subtle connecting axis hairline */}
            <div className="poster-axis-line" />

            {/* Left Fragment (e.g. THI, BU, BRE, LEA, SH) */}
            <span className="poster-frag-left">
              {item.left}
            </span>

            {/* Right Fragment (e.g. NK, ILD, AK, RN, IP) */}
            <span className="poster-frag-right">
              {item.right}
            </span>
          </div>
        );
      })}
    </div>
  );
};


// Aspect-Ratio-Preserving Image Component (Never crops, never distorts)
const ParallaxImage = ({ src, alt, className = "", style = {}, maxH, loading = "lazy", decoding = "async", ...props }) => {
  return (
    <div className="w-full relative flex items-center justify-center">
      <img
        src={src}
        alt={alt}
        loading={loading}
        decoding={decoding}
        style={{
          maxHeight: maxH || "none",
          ...style
        }}
        className={`w-full h-auto object-contain block mx-auto ${className}`}
        {...props}
      />
    </div>
  );
};

// Hardware / Browser / Editorial Frame Component (Aspect-Ratio-Preserving & 100% Uncropped)
const VisualFrame = ({ src, alt, frameType = "fullbleed", isPriority = false }) => {
  const loadingAttr = isPriority ? "eager" : "lazy";

  if (frameType === "macbook") {
    return (
      <div className="w-full relative mx-auto my-3 max-w-4xl">
        <div className="bg-[#1c1c1e] rounded-t-2xl p-2.5 sm:p-3 shadow-2xl border border-neutral-700/80">
          <div className="flex items-center justify-between px-2 pb-2.5 border-b border-neutral-800">
            <div className="flex items-center gap-1.5">
              <span className="w-2.5 h-2.5 rounded-full bg-[#ff5f56]"></span>
              <span className="w-2.5 h-2.5 rounded-full bg-[#ffbd2e]"></span>
              <span className="w-2.5 h-2.5 rounded-full bg-[#27c93f]"></span>
            </div>
            <div className="text-[10px] font-mono font-medium text-neutral-400">SmartDoc Parser — Inspection Engine</div>
            <div className="w-8"></div>
          </div>
          <div className="bg-[#0c0c0e] rounded-b-lg p-2 sm:p-3 flex items-center justify-center">
            <img
              src={src}
              alt={alt}
              loading={loadingAttr}
              decoding="async"
              className="w-full h-auto object-contain block mx-auto rounded shadow-sm"
            />
          </div>
        </div>
        <div className="w-[104%] -ml-[2%] h-3.5 bg-gradient-to-b from-[#d1d5db] to-[#9ca3af] rounded-b-xl border-t border-neutral-400 shadow-md relative flex justify-center">
          <div className="w-16 h-1 bg-[#6b7280] rounded-b-sm"></div>
        </div>
      </div>
    );
  }

  if (frameType === "browser") {
    return (
      <div className="w-full rounded-2xl bg-white border border-neutral-200/90 shadow-[0_10px_30px_-10px_rgba(0,0,0,0.08)] hover:shadow-[0_20px_40px_-12px_rgba(0,0,0,0.12)] transition-all duration-500 overflow-hidden relative group">
        <div className="px-4 py-2.5 bg-neutral-100/90 border-b border-neutral-200/80 flex items-center justify-between">
          <div className="flex items-center gap-1.5">
            <span className="w-2.5 h-2.5 rounded-full bg-neutral-300"></span>
            <span className="w-2.5 h-2.5 rounded-full bg-neutral-300"></span>
            <span className="w-2.5 h-2.5 rounded-full bg-neutral-300"></span>
          </div>
          <div className="bg-white/90 border border-neutral-200/70 rounded-md px-3 py-0.5 text-[10px] font-mono font-medium text-neutral-500 truncate max-w-[240px] text-center">
            taskflow.app/workspace/board
          </div>
          <div className="w-8"></div>
        </div>

        <div className="w-full bg-[#FAF9F5] p-2 sm:p-3 flex items-center justify-center">
          <img
            src={src}
            alt={alt}
            loading={loadingAttr}
            decoding="async"
            className="w-full h-auto object-contain block mx-auto rounded-b-xl"
          />
        </div>
      </div>
    );
  }

  return (
    <div className="w-full rounded-2xl bg-white border border-neutral-200/80 shadow-[0_6px_20px_-6px_rgba(0,0,0,0.05)] hover:shadow-[0_14px_30px_-8px_rgba(0,0,0,0.09)] transition-all duration-500 overflow-hidden relative group p-2 sm:p-3 flex items-center justify-center">
      <img
        src={src}
        alt={alt}
        loading={loadingAttr}
        decoding="async"
        className="w-full h-auto object-contain block mx-auto rounded-xl"
      />
    </div>
  );
};

// Lightbox Modal Component
const LightboxModal = ({ project, initialIndex = 0, onClose }) => {
  const images = [
    { src: project.hero || project.image, step: "OVERVIEW", caption: project.description || project.shortDescription },
    ...(project.gallery || [])
  ];

  const [currentIndex, setCurrentIndex] = useState(initialIndex);
  const totalCount = images.length;
  const currentItem = images[currentIndex] || images[0];
  const itemSrc = typeof currentItem === 'string' ? currentItem : currentItem.src;
  const itemStep = typeof currentItem === 'object' ? currentItem.step : `STEP ${String(currentIndex + 1).padStart(2, '0')}`;
  const itemCaption = typeof currentItem === 'object' ? currentItem.caption : '';

  const formattedIndex = String(currentIndex + 1).padStart(2, '0');
  const formattedTotal = String(totalCount).padStart(2, '0');

  const handleNext = () => setCurrentIndex((prev) => (prev === totalCount - 1 ? 0 : prev + 1));
  const handlePrev = () => setCurrentIndex((prev) => (prev === 0 ? totalCount - 1 : prev - 1));

  useEffect(() => {
    const handleKeyDown = (e) => {
      if (e.key === 'Escape') onClose();
      else if (e.key === 'ArrowRight') handleNext();
      else if (e.key === 'ArrowLeft') handlePrev();
    };
    window.addEventListener('keydown', handleKeyDown);
    return () => window.removeEventListener('keydown', handleKeyDown);
  }, [currentIndex, totalCount, onClose]);

  return (
    <div
      onClick={onClose}
      className="fixed inset-0 z-50 bg-[#F7F7F5]/96 backdrop-blur-2xl flex flex-col justify-between p-4 sm:p-8 animate-backdrop-fade text-[#111111] select-none overflow-hidden"
    >
      <div className="w-full max-w-6xl mx-auto flex flex-col items-center pt-2 gap-2" onClick={(e) => e.stopPropagation()}>
        <button
          onClick={onClose}
          className="p-2 text-neutral-500 hover:text-neutral-900 transition-colors rounded-full hover:bg-neutral-200/60 cursor-pointer"
          title="Close Viewer (ESC)"
        >
          <Icon name="Close" size={24} />
        </button>

        <div className="font-mono text-xs tracking-widest text-neutral-500 font-bold uppercase">
          {project.name || project.title} — {formattedIndex} / {formattedTotal}
        </div>
      </div>

      <div className="w-full max-w-6xl mx-auto flex-1 flex flex-col items-center justify-center py-4 relative group" onClick={(e) => e.stopPropagation()}>
        <button
          onClick={handlePrev}
          className="absolute left-2 sm:left-0 top-1/2 -translate-y-1/2 z-10 w-11 h-11 rounded-full bg-white/90 border border-neutral-300/80 shadow-lg text-neutral-700 hover:text-neutral-900 hover:bg-white hover:scale-105 transition-all flex items-center justify-center cursor-pointer"
          title="Previous Image (Left Arrow)"
        >
          <Icon name="ArrowLeft" size={18} />
        </button>

        <button
          onClick={handleNext}
          className="absolute right-2 sm:right-0 top-1/2 -translate-y-1/2 z-10 w-11 h-11 rounded-full bg-white/90 border border-neutral-300/80 shadow-lg text-neutral-700 hover:text-neutral-900 hover:bg-white hover:scale-105 transition-all flex items-center justify-center cursor-pointer"
          title="Next Image (Right Arrow)"
        >
          <Icon name="ArrowUpRight" size={18} style={{ transform: 'rotate(45deg)' }} />
        </button>

        <div className="w-full max-h-[74vh] flex items-center justify-center relative px-2">
          <img
            key={itemSrc}
            src={itemSrc}
            alt={itemStep}
            className="w-full h-auto object-contain max-h-[72vh] block rounded-2xl border border-neutral-300/80 shadow-[0_25px_60px_-15px_rgba(0,0,0,0.14)] mx-auto transition-all duration-300 bg-white animate-scale-expand"
          />
        </div>
      </div>

      <div className="w-full max-w-6xl mx-auto pb-3 space-y-3" onClick={(e) => e.stopPropagation()}>
        {itemCaption && (
          <p className="text-center text-xs text-neutral-600 max-w-2xl mx-auto leading-relaxed">
            <span className="font-semibold text-neutral-900 mr-2">{formattedIndex} / {formattedTotal} — {itemStep}:</span>
            {itemCaption}
          </p>
        )}

        {totalCount > 1 && (
          <div className="w-full py-1.5 flex items-center justify-center gap-2 overflow-x-auto no-scrollbar scroll-smooth">
            {images.map((img, idx) => {
              const isSelected = idx === currentIndex;
              const thumbSrc = typeof img === 'string' ? img : img.src;
              return (
                <button
                  key={idx}
                  onClick={() => setCurrentIndex(idx)}
                  className={`h-11 w-15 sm:h-12 sm:w-18 rounded-lg overflow-hidden border-2 transition-all flex-shrink-0 cursor-pointer ${
                    isSelected
                      ? 'border-neutral-900 shadow-md scale-105 opacity-100 ring-2 ring-neutral-900/20'
                      : 'border-neutral-300/60 opacity-50 hover:opacity-100 hover:border-neutral-500'
                  }`}
                  title={`Jump to image ${idx + 1}`}
                >
                  <img src={thumbSrc} alt={`Thumbnail ${idx + 1}`} className="w-full h-full object-cover" />
                </button>
              );
            })}
          </div>
        )}

        <div className="flex items-center justify-between text-xs font-semibold text-neutral-700 pt-2 border-t border-neutral-200/80">
          <button
            onClick={handlePrev}
            className="flex items-center gap-2 hover:text-neutral-900 px-4 py-2 rounded-full hover:bg-neutral-200/60 transition-all cursor-pointer"
          >
            <span>← Previous</span>
          </button>
          <span className="text-[11px] text-neutral-400 font-mono hidden sm:inline">USE ARROW KEYS OR SWIPE</span>
          <button
            onClick={handleNext}
            className="flex items-center gap-2 hover:text-neutral-900 px-4 py-2 rounded-full hover:bg-neutral-200/60 transition-all cursor-pointer"
          >
            <span>Next →</span>
          </button>
        </div>
      </div>
    </div>
  );
};

// Command Palette (⌘K / Ctrl+K)
const CommandPalette = ({ isOpen, onClose, onSelectProject, onOpenArchive, projects = [], profile = {} }) => {
  const [query, setQuery] = useState("");
  const inputRef = useRef(null);

  useEffect(() => {
    if (isOpen) {
      setTimeout(() => inputRef.current?.focus(), 50);
    } else {
      setQuery("");
    }
  }, [isOpen]);

  if (!isOpen) return null;

  const quickActions = [
    { label: "View Selected Work", icon: "Layers", action: () => { window.location.hash = "#work"; onClose(); } },
    { label: "View Experience", icon: "Activity", action: () => { window.location.hash = "#experience"; onClose(); } },
    { label: "Open Personal Archive (18 Moments)", icon: "Sparkles", action: () => { onOpenArchive(); onClose(); } },
    { label: "View Resume PDF", icon: "FileText", action: () => { window.open(profile?.resumeUrl || "assets/resume/Gopikrishna_Chegoni_Resume.pdf", "_blank"); onClose(); } },
    { label: "Open GitHub Profile", icon: "GitFork", action: () => { window.open(profile?.githubUrl || "https://github.com/gopikrishna818", "_blank"); onClose(); } },
    { label: "Copy Email Address", icon: "Mail", action: () => { navigator.clipboard?.writeText(profile?.email || "chegoni.gopikrishna@gmail.com"); alert("Email copied to clipboard!"); onClose(); } }
  ];

  const projectItems = projects.map(p => ({
    label: `${p.number || ''} ${p.name || p.title}`,
    category: p.category,
    icon: "Cpu",
    action: () => { onSelectProject(p); onClose(); }
  }));

  const allItems = [...quickActions, ...projectItems];
  const filtered = query.trim()
    ? allItems.filter(item => item.label.toLowerCase().includes(query.toLowerCase()) || item.category?.toLowerCase().includes(query.toLowerCase()))
    : allItems;

  return (
    <div className="fixed inset-0 z-50 bg-black/60 backdrop-blur-sm flex items-start justify-center pt-24 px-4 animate-backdrop-fade" onClick={onClose}>
      <div className="bg-white rounded-2xl border border-neutral-200/90 shadow-2xl w-full max-w-xl overflow-hidden animate-scale-expand" onClick={(e) => e.stopPropagation()}>
        <div className="p-3.5 border-b border-neutral-200/80 flex items-center gap-3">
          <Icon name="Search" size={18} className="text-neutral-400" />
          <input
            ref={inputRef}
            type="text"
            placeholder="Type a command or search projects, resume, archive..."
            value={query}
            onChange={(e) => setQuery(e.target.value)}
            className="w-full text-sm font-sans outline-none bg-transparent text-neutral-900 placeholder:text-neutral-400"
          />
          <kbd className="font-mono text-[10px] font-bold text-neutral-400 bg-neutral-100 border border-neutral-200 px-2 py-0.5 rounded">ESC</kbd>
        </div>

        <div className="max-h-80 overflow-y-auto p-2 space-y-1">
          {filtered.length === 0 ? (
            <div className="p-6 text-center text-xs text-neutral-400 font-mono">No matching results found</div>
          ) : (
            filtered.map((item, idx) => (
              <button
                key={idx}
                onClick={item.action}
                className="w-full px-3 py-2.5 rounded-xl hover:bg-neutral-100 flex items-center justify-between text-xs font-semibold text-neutral-800 transition-colors cursor-pointer group text-left"
              >
                <div className="flex items-center gap-3">
                  <Icon name={item.icon} size={15} className="text-neutral-400 group-hover:text-neutral-900" />
                  <span>{item.label}</span>
                </div>
                {item.category && (
                  <span className="font-mono text-[10px] text-neutral-400 font-normal">{item.category}</span>
                )}
              </button>
            ))
          )}
        </div>

        <div className="p-2.5 bg-neutral-50 border-t border-neutral-200/80 flex items-center justify-between text-[11px] font-mono text-neutral-400">
          <span>Shortcuts: ⌘K / Ctrl+K, ESC, R (Resume), G (GitHub)</span>
          <span>Gopikrishna Chegoni</span>
        </div>
      </div>
    </div>
  );
};

// FLOATING GLASS NAVIGATION BAR & RESPONSIVE MOBILE DRAWER
const Navbar = ({ profile = {}, onOpenArchive, onOpenCommandPalette }) => {
  const [isScrolled, setIsScrolled] = useState(false);
  const [activeSection, setActiveSection] = useState("home");
  const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
  const avatarSrc = "assets/clean/profile-avatar.webp";
  const resumeUrl = profile.resumeUrl || "assets/resume/Gopikrishna_Chegoni_Resume.pdf";
  const githubUrl = profile.githubUrl || "https://github.com/gopikrishna818";

  useEffect(() => {
    const handleScroll = () => {
      setIsScrolled(window.scrollY > 160);

      const sections = ['work', 'experience', 'about'];
      const scrollPos = window.scrollY + 200;
      for (const sec of sections) {
        const el = document.getElementById(sec);
        if (el) {
          const top = el.offsetTop;
          const height = el.offsetHeight;
          if (scrollPos >= top && scrollPos < top + height) {
            setActiveSection(sec);
            return;
          }
        }
      }
      if (window.scrollY < 300) setActiveSection("home");
    };

    window.addEventListener('scroll', handleScroll, { passive: true });
    return () => window.removeEventListener('scroll', handleScroll);
  }, []);

  return (
    <>
      {/* Top Clean Header */}
      <header className="w-full max-w-6xl mx-auto px-6 pt-8 pb-4 flex items-center justify-between text-xs tracking-wider">
        <a href="#" className="flex items-center gap-3 group cursor-pointer">
          {/* Bespoke Geometric GK Seal */}
          <div className="w-[38px] h-[38px] rounded-xl border border-neutral-300/90 bg-[#FAF9F6] flex items-center justify-center text-neutral-900 shadow-2xs transition-all duration-300 group-hover:scale-105 group-hover:border-neutral-900 flex-shrink-0">
            <svg width="22" height="22" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" className="transition-transform duration-300 group-hover:rotate-6">
              <circle cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="1.2" strokeOpacity="0.25" strokeDasharray="2 2" />
              {/* G */}
              <path d="M10 8.5C8.2 8.5 7 9.9 7 12C7 14.1 8.2 15.5 10 15.5C11.5 15.5 12.5 14.5 12.5 13H9.5" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/>
              {/* K */}
              <path d="M15 8.5V15.5M18.5 8.5L15 12L18.5 15.5" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/>
            </svg>
          </div>
          <div className="flex flex-col">
            <span className="font-black text-neutral-900 uppercase tracking-tight text-sm leading-tight group-hover:text-neutral-700 transition-colors">
              GOPIKRISHNA CHEGONI
            </span>
            <span className="text-[10px] font-semibold text-neutral-500 font-mono tracking-widest uppercase">
              AI / SOFTWARE ENGINEER
            </span>
          </div>
        </a>

        {/* Desktop Navigation Links */}
        <div className="hidden md:flex items-center gap-6 font-mono text-[11.5px] font-semibold text-neutral-600">
          <a href="#work" className="hover:text-neutral-900 transition-colors">WORK</a>
          <a href="#experience" className="hover:text-neutral-900 transition-colors">EXPERIENCE</a>
          <button onClick={onOpenArchive} className="hover:text-neutral-900 transition-colors font-semibold cursor-pointer uppercase font-mono">
            ARCHIVE
          </button>
          <a href="#about" className="hover:text-neutral-900 transition-colors">ABOUT</a>
          <a
            href={githubUrl}
            target="_blank"
            rel="noopener noreferrer"
            className="hover:text-neutral-900 transition-colors inline-flex items-center gap-0.5"
          >
            <span>GITHUB</span>
            <span className="text-[10px]">↗</span>
          </a>
          <a
            href={resumeUrl}
            target="_blank"
            rel="noopener noreferrer"
            className="inline-flex items-center gap-1 px-3.5 py-1.5 rounded-full bg-neutral-900 text-white hover:bg-neutral-800 transition-all font-mono text-[11px] font-bold shadow-2xs cursor-pointer"
          >
            <span>RESUME</span>
            <Icon name="ArrowUpRight" size={12} />
          </a>
        </div>

        {/* Mobile Header Buttons */}
        <div className="flex md:hidden items-center gap-2">
          <a
            href={resumeUrl}
            target="_blank"
            rel="noopener noreferrer"
            className="px-3 py-1.5 rounded-full bg-neutral-900 text-white font-mono text-[11px] font-bold"
          >
            RESUME ↗
          </a>
          <button
            onClick={() => setMobileMenuOpen(true)}
            className="p-2 rounded-xl border border-neutral-300 text-neutral-800 hover:bg-neutral-100 transition-colors"
            title="Open Menu"
          >
            <Icon name="Menu" size={18} />
          </button>
        </div>
      </header>

      {/* Floating Glass Capsule on Scroll */}
      <nav
        className={`fixed top-4 left-1/2 -translate-x-1/2 z-40 transition-all duration-500 select-none ${
          isScrolled ? 'opacity-100 translate-y-0 pointer-events-auto' : 'opacity-0 -translate-y-4 pointer-events-none'
        }`}
      >
        <div className="glass-capsule rounded-full px-4 py-2 flex items-center gap-4 text-xs font-semibold text-neutral-700 shadow-xl">
          <a href="#" className="flex items-center gap-2 pr-2 border-r border-neutral-200 group">
            <div className="w-5 h-5 rounded-md border border-neutral-300/80 bg-[#FAF9F6] flex items-center justify-center text-neutral-900 shadow-2xs">
              <svg width="12" height="12" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M10 8.5C8.2 8.5 7 9.9 7 12C7 14.1 8.2 15.5 10 15.5C11.5 15.5 12.5 14.5 12.5 13H9.5" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
                <path d="M15 8.5V15.5M18.5 8.5L15 12L18.5 15.5" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
              </svg>
            </div>
            <span className="font-bold text-neutral-900 hidden sm:inline text-[11px] tracking-tight uppercase">Gopikrishna</span>
          </a>

          <div className="hidden sm:flex items-center gap-4 text-[11px] font-bold">
            <a href="#work" className={`hover:text-neutral-900 transition-colors ${activeSection === 'work' ? 'text-neutral-900 font-black underline underline-offset-4' : 'text-neutral-500'}`}>WORK</a>
            <a href="#experience" className={`hover:text-neutral-900 transition-colors ${activeSection === 'experience' ? 'text-neutral-900 font-black underline underline-offset-4' : 'text-neutral-500'}`}>EXPERIENCE</a>
            <button onClick={onOpenArchive} className="text-neutral-500 hover:text-neutral-900 transition-colors cursor-pointer uppercase font-bold">ARCHIVE</button>
            <a href="#about" className={`hover:text-neutral-900 transition-colors ${activeSection === 'about' ? 'text-neutral-900 font-black underline underline-offset-4' : 'text-neutral-500'}`}>ABOUT</a>
          </div>

          <div className="flex items-center gap-2 sm:pl-2 sm:border-l sm:border-neutral-200">
            <button
              onClick={onOpenCommandPalette}
              className="p-1.5 text-neutral-400 hover:text-neutral-900 hover:bg-neutral-100 rounded-full transition-colors cursor-pointer"
              title="Search (⌘K)"
            >
              <Icon name="Search" size={14} />
            </button>
            <a
              href={resumeUrl}
              target="_blank"
              rel="noopener noreferrer"
              className="inline-flex items-center gap-1 px-3 py-1 rounded-full bg-neutral-900 text-white hover:bg-neutral-800 text-[10px] font-mono font-bold transition-all shadow-2xs"
            >
              <span>RESUME</span>
              <Icon name="ArrowUpRight" size={11} />
            </a>
          </div>
        </div>
      </nav>

      {/* Mobile Slide-Out Drawer Navigation */}
      {mobileMenuOpen && (
        <div className="fixed inset-0 z-50 bg-black/60 backdrop-blur-sm flex justify-end animate-backdrop-fade" onClick={() => setMobileMenuOpen(false)}>
          <div className="bg-[#F7F7F5] w-[80%] max-w-sm h-full p-6 shadow-2xl flex flex-col justify-between" onClick={(e) => e.stopPropagation()}>
            <div className="space-y-6">
              <div className="flex items-center justify-between border-b border-neutral-200 pb-4">
                <div className="font-mono text-xs font-bold text-neutral-400 uppercase">NAVIGATION</div>
                <button onClick={() => setMobileMenuOpen(false)} className="p-2 rounded-full hover:bg-neutral-200">
                  <Icon name="Close" size={20} />
                </button>
              </div>

              <div className="flex flex-col gap-4 text-base font-bold text-neutral-900 uppercase">
                <a href="#work" onClick={() => setMobileMenuOpen(false)} className="hover:text-neutral-600">Selected Work</a>
                <a href="#experience" onClick={() => setMobileMenuOpen(false)} className="hover:text-neutral-600">Experience & Education</a>
                <button onClick={() => { onOpenArchive(); setMobileMenuOpen(false); }} className="text-left hover:text-neutral-600 uppercase font-bold">Personal Archive (24)</button>
                <a href="#about" onClick={() => setMobileMenuOpen(false)} className="hover:text-neutral-600">About & Principles</a>
              </div>
            </div>

            <div className="space-y-3 pt-6 border-t border-neutral-200 font-mono text-xs">
              <a
                href={resumeUrl}
                target="_blank"
                rel="noopener noreferrer"
                className="w-full py-3 bg-neutral-900 text-white rounded-xl font-bold flex items-center justify-center gap-2"
              >
                <span>DOWNLOAD RESUME PDF</span>
                <Icon name="ArrowUpRight" size={14} />
              </a>
              <a
                href={githubUrl}
                target="_blank"
                rel="noopener noreferrer"
                className="w-full py-2.5 bg-white border border-neutral-300 rounded-xl font-semibold text-neutral-800 flex items-center justify-center gap-2"
              >
                <span>GITHUB PROFILE</span>
                <Icon name="ArrowUpRight" size={13} />
              </a>
            </div>
          </div>
        </div>
      )}
    </>
  );
};

// MINIMAL EDITORIAL PORTFOLIO COVER HERO (PORTFOLIO Typography + Centered Portrait + Identity + 2 Actions)
const HeroSection = ({ profile = {} }) => {
  const [mousePos, setMousePos] = useState({ x: 0, y: 0 });
  const [scrollY, setScrollY] = useState(0);
  const heroRef = React.useRef(null);

  const portraitSrc = "assets/clean/gopi-monochrome-portrait.webp?v=5";

  // Apple-like scroll-driven parallax interaction
  useEffect(() => {
    let rafId = null;
    const handleScroll = () => {
      if (rafId) cancelAnimationFrame(rafId);
      rafId = requestAnimationFrame(() => {
        const curY = window.scrollY;
        if (curY < 800) {
          setScrollY(curY);
        }
      });
    };

    window.addEventListener('scroll', handleScroll, { passive: true });
    return () => {
      window.removeEventListener('scroll', handleScroll);
      if (rafId) cancelAnimationFrame(rafId);
    };
  }, []);

  // Subtle interactive parallax on mouse move
  const handleMouseMove = (e) => {
    if (!heroRef.current) return;
    const rect = heroRef.current.getBoundingClientRect();
    const x = ((e.clientX - rect.left) / rect.width - 0.5) * 2;
    const y = ((e.clientY - rect.top) / rect.height - 0.5) * 2;
    setMousePos({ x, y });
  };

  const handleMouseLeave = () => {
    setMousePos({ x: 0, y: 0 });
  };

  // Parallax offsets
  const portraitOffsetY = scrollY * -0.22;
  const titleOffsetY = scrollY * -0.08;

  return (
    <section
      ref={heroRef}
      onMouseMove={handleMouseMove}
      onMouseLeave={handleMouseLeave}
      className="hero-cover-root min-h-[88vh] sm:min-h-[94vh] flex flex-col justify-between items-center px-3 sm:px-4 pt-3 sm:pt-4 pb-6 sm:pb-8 select-none relative overflow-hidden"
      id="home"
    >
      {/* Background Ambience: Subtle Fine Grid */}
      <div className="hero-light-grid" />

      {/* Main Visual Centerpiece: Giant PORTFOLIO Title + Overlapping Centered Portrait + Refined Statement */}
      <div className="w-full max-w-7xl mx-auto flex-1 flex flex-col justify-center items-center relative z-10 my-auto">
        <div className="relative w-full flex justify-center items-center">
          
          {/* 01. HUGE "PORTFOLIO" TYPOGRAPHY (Layered Behind Portrait) */}
          <div 
            className="hero-giant-title-wrapper w-full text-center pointer-events-none select-none animate-hero-title-reveal"
            style={{
              transform: `translate3d(calc(-50% + ${mousePos.x * -3}px), calc(-50% + ${mousePos.y * -2 + titleOffsetY}px), 0)`
            }}
          >
            <h1 className="hero-giant-title">
              PORTFOLIO
            </h1>
          </div>

          {/* 02. REAL MONOCHROME PORTRAIT (Subtly Moves Upward with Apple-like Parallax) */}
          <div
            className="hero-cover-portrait-wrapper animate-hero-portrait-reveal"
            style={{
              transform: `translate3d(${mousePos.x * 5}px, ${mousePos.y * 3 + portraitOffsetY}px, 0)`
            }}
          >
            <img
              src={portraitSrc}
              alt="Gopikrishna Chegoni"
              className="hero-cover-portrait-img"
              loading="eager"
              fetchPriority="high"
              decoding="async"
            />
          </div>
        </div>

        {/* 03. CLEAR, STRONG HIERARCHY UNDERNEATH PORTRAIT */}
        <div className="-mt-10 sm:-mt-20 md:-mt-22 lg:-mt-24 text-center relative z-30 animate-hero-content-reveal max-w-2xl mx-auto space-y-2 sm:space-y-2.5 px-3">
          {/* Small refined identification */}
          <div className="font-mono text-[10.5px] sm:text-xs font-bold text-neutral-500 uppercase tracking-[0.28em] sm:tracking-[0.38em]">
            GOPIKRISHNA CHEGONI
          </div>

          {/* Main Statement */}
          <h2 className="text-lg sm:text-2xl md:text-3xl font-black text-neutral-900 tracking-tight uppercase leading-tight">
            AI &amp; SOFTWARE ENGINEER
          </h2>

          {/* Supporting sentence */}
          <p className="text-xs sm:text-sm md:text-[15px] text-neutral-600 font-normal leading-relaxed max-w-lg mx-auto">
            {profile.subheadline || profile.headline || "Driven by curiosity about how intelligent systems learn, reason, and interact with the physical world."}
          </p>

          {/* Single Direct Action CTA */}
          <div className="flex items-center justify-center pt-2 sm:pt-3">
            <a
              href="#work"
              className="inline-flex items-center gap-2 px-5 py-2.5 sm:px-7 sm:py-3 rounded-full bg-neutral-900 text-white font-mono text-[11px] sm:text-xs font-bold hover:bg-neutral-800 hover:scale-[1.02] active:scale-[0.98] transition-all shadow-sm group cursor-pointer"
            >
              <span>VIEW WORK</span>
              <span className="transition-transform group-hover:translate-x-0.5 group-hover:translate-y-0.5">↘</span>
            </a>
          </div>
        </div>
      </div>
    </section>
  );
};

// 4 PROOF METRICS STRIP (Selected & Defensible)
const EngineeringProofStrip = ({ items = [] }) => {
  if (!items || items.length === 0) return null;

  return (
    <section className="w-full max-w-6xl mx-auto px-6 py-4">
      <ScrollReveal>
        <div className="bg-white border border-neutral-200/90 rounded-2xl p-5 sm:p-6 shadow-2xs grid grid-cols-2 md:grid-cols-4 gap-6 divide-y sm:divide-y-0 sm:divide-x divide-neutral-100">
          {items.map((stat, idx) => (
            <div key={idx} className={`pt-4 sm:pt-0 ${idx > 0 ? 'sm:pl-6' : ''} space-y-1`}>
              <div className="font-mono text-2xl sm:text-3xl font-black text-neutral-900 tracking-tight">
                <AnimatedCounter value={stat.value} duration={1400} />
              </div>
              <div className="font-mono text-[10.5px] font-bold text-neutral-800 uppercase tracking-wider">
                {stat.label}
              </div>
              <div className="text-[11px] text-neutral-500 font-normal leading-tight">
                {stat.sub}
              </div>
            </div>
          ))}
        </div>
      </ScrollReveal>
    </section>
  );
};

// PROJECT 01 — AI LEAD GEN (HERO FLAGSHIP COMPOSITION)
const FlagshipLeadGenCard = ({ project, onOpenProject }) => {
  const telemetry = project.telemetry || {};

  const leadFlowNodes = [
    { name: "Lead", sub: "Inbound Form", color: "bg-blue-400" },
    { name: "AI", sub: "Gemini Script", color: "bg-purple-400" },
    { name: "Voice", sub: "Retell Call", color: "bg-emerald-400" },
    { name: "CRM", sub: "Supabase DB", color: "bg-amber-400" }
  ];

  return (
    <article
      onClick={() => onOpenProject(project)}
      className="py-12 border-b border-neutral-200/80 space-y-8 cursor-pointer group select-none project-card-interactive"
    >
      <div className="space-y-3">
        <div className="flex items-center justify-between text-xs text-neutral-500 font-semibold tracking-wider">
          <div className="flex flex-wrap items-center gap-3">
            <span className="font-mono text-2xl font-black text-neutral-900">01</span>
            <span>/</span>
            <span className="uppercase text-neutral-700 font-bold">{project.category}</span>
            <span>·</span>
            <span className="text-neutral-900 font-mono text-[11px] font-bold bg-amber-100 text-amber-900 px-2.5 py-0.5 rounded border border-amber-300">
              FEATURED PROJECT
            </span>
            <span>·</span>
            <span className="font-mono text-[11px] text-neutral-600 font-bold">
              My role: {project.myRole || "AI Automation + Backend"}
            </span>
          </div>
          <span className="text-xs font-bold text-neutral-500 group-hover:text-neutral-900 transition-colors flex items-center gap-1">
            <span>VIEW CASE STUDY</span>
            <Icon name="ArrowUpRight" size={14} className="transition-transform group-hover:translate-x-0.5 group-hover:-translate-y-0.5" />
          </span>
        </div>

        <h2 className="text-3xl sm:text-5xl font-black text-neutral-900 tracking-tight leading-tight uppercase group-hover:translate-x-1 transition-transform">
          {project.name || project.title}
        </h2>
        <p className="text-lg sm:text-2xl font-medium text-neutral-800 tracking-tight leading-snug max-w-3xl">
          {project.description || project.shortDescription}
        </p>

        {/* 3-Second Metrics Strip */}
        <div className="flex flex-wrap items-center gap-3 pt-1 font-mono text-xs font-bold text-neutral-700">
          <span className="bg-white border border-neutral-200 px-3 py-1 rounded-full shadow-2xs text-emerald-800">
            500+ calls/day
          </span>
          <span className="bg-white border border-neutral-200 px-3 py-1 rounded-full shadow-2xs">
            &lt;30s response
          </span>
          <span className="bg-white border border-neutral-200 px-3 py-1 rounded-full shadow-2xs text-emerald-800">
            98.4% delivery
          </span>
        </div>
      </div>

      {/* Flagship Visual with Animated Flow & Screenshot */}
      <div className="w-full relative rounded-3xl overflow-hidden bg-neutral-900 border border-neutral-800 shadow-xl group-hover:shadow-2xl transition-all duration-500">
        <div className="p-4 sm:p-5 bg-neutral-950 border-b border-neutral-800">
          <div className="flex items-center justify-between font-mono text-[10px] sm:text-xs text-neutral-400 uppercase mb-3">
            <div className="flex items-center gap-2">
              <span className="w-2 h-2 rounded-full bg-emerald-400 animate-pulse"></span>
              <span className="font-bold text-neutral-200">AUTONOMOUS LEAD FLOW</span>
            </div>
            <span className="text-neutral-500 font-mono hidden sm:inline">LEAD → AI → VOICE → CRM</span>
          </div>

          <div className="flex items-center justify-between gap-1 sm:gap-3">
            {leadFlowNodes.map((node, i) => (
              <React.Fragment key={i}>
                <div className="flex-1 bg-neutral-900/90 border border-neutral-800 hover:border-neutral-700 rounded-xl p-2.5 sm:p-3 text-center transition-all">
                  <div className="flex items-center justify-center gap-1.5">
                    <span className={`w-2 h-2 rounded-full ${node.color}`}></span>
                    <span className="font-mono text-xs sm:text-sm font-bold text-white uppercase">{node.name}</span>
                  </div>
                  <div className="text-[10px] font-mono text-neutral-400 truncate mt-0.5 hidden sm:block">{node.sub}</div>
                </div>

                {i < leadFlowNodes.length - 1 && (
                  <div className="w-6 sm:w-14 relative flex items-center justify-center flex-shrink-0">
                    <div className="w-full h-[2px] bg-neutral-800 rounded-full relative overflow-hidden">
                      <div className="anim-dot-x" style={{ animationDelay: `${i * 0.5}s` }}></div>
                    </div>
                  </div>
                )}
              </React.Fragment>
            ))}
          </div>
        </div>

        <div className="p-3 sm:p-6 bg-neutral-950/80 flex items-center justify-center">
          <img
            src={project.hero || project.image}
            alt={project.name || "AI Lead Gen Workflow"}
            loading="lazy"
            decoding="async"
            className="w-full h-auto object-contain block rounded-2xl border border-neutral-800 shadow-xl mx-auto"
          />
        </div>

        <div className="p-4 sm:p-6 bg-neutral-950/90 border-t border-neutral-800 grid grid-cols-2 sm:grid-cols-4 gap-4 font-mono text-white">
          <div>
            <div className="text-xl sm:text-2xl font-black text-emerald-400">
              <AnimatedCounter value={telemetry.dailyCalls || "500+"} duration={1300} />
            </div>
            <div className="text-[10px] text-neutral-400 uppercase">Daily Outbound Calls</div>
          </div>
          <div>
            <div className="text-xl sm:text-2xl font-black text-white">{telemetry.responseLatency || "<30s"}</div>
            <div className="text-[10px] text-neutral-400 uppercase">Response Latency</div>
          </div>
          <div>
            <div className="text-xl sm:text-2xl font-black text-emerald-400">
              <AnimatedCounter value={telemetry.deliveryRate || "98.4%"} duration={1400} />
            </div>
            <div className="text-[10px] text-neutral-400 uppercase">Delivery Success</div>
          </div>
          <div>
            <div className="text-xs sm:text-sm font-bold text-neutral-300 pt-1">Gemini + Retell</div>
            <div className="text-[10px] text-neutral-400 uppercase">AI Voice Stack</div>
          </div>
        </div>
      </div>
    </article>
  );
};

// PROJECT 02 — SMARTDOC (DOCUMENT INTELLIGENCE SHOWCASE COMPOSITION)
const SmartDocShowcaseCard = ({ project, onOpenProject }) => {
  const showcase = project.showcase || {};
  const sampleInvoice = showcase.sampleInvoice || {};
  const extractedJson = showcase.extractedJson || {};

  return (
    <article
      onClick={() => onOpenProject(project)}
      className="py-12 border-b border-neutral-200/80 space-y-8 cursor-pointer group select-none project-card-interactive"
    >
      <div className="space-y-3">
        <div className="flex items-center justify-between text-xs text-neutral-500 font-semibold tracking-wider">
          <div className="flex flex-wrap items-center gap-3">
            <span className="font-mono text-2xl font-black text-neutral-900">02</span>
            <span>/</span>
            <span className="uppercase text-neutral-700 font-bold">{project.category}</span>
            <span>·</span>
            <span className="text-neutral-700 font-mono text-[11px] font-bold bg-neutral-100 px-2 py-0.5 rounded border border-neutral-200">
              DOCUMENT INTELLIGENCE
            </span>
            <span>·</span>
            <span className="font-mono text-[11px] text-neutral-600 font-bold">
              My role: {project.myRole || "Document AI + Backend"}
            </span>
          </div>
          <span className="text-xs font-bold text-neutral-500 group-hover:text-neutral-900 transition-colors flex items-center gap-1">
            <span>VIEW CASE STUDY</span>
            <Icon name="ArrowUpRight" size={14} className="transition-transform group-hover:translate-x-0.5 group-hover:-translate-y-0.5" />
          </span>
        </div>

        <h2 className="text-3xl sm:text-5xl font-black text-neutral-900 tracking-tight leading-tight uppercase group-hover:translate-x-1 transition-transform">
          {project.name || project.title}
        </h2>
        <p className="text-lg sm:text-2xl font-medium text-neutral-800 tracking-tight leading-snug max-w-3xl">
          {project.description || project.shortDescription}
        </p>

        <div className="flex flex-wrap items-center gap-3 pt-1 font-mono text-xs font-bold text-neutral-700">
          <span className="bg-white border border-neutral-200 px-3 py-1 rounded-full shadow-2xs text-cyan-900">
            98.0% accuracy
          </span>
          <span className="bg-white border border-neutral-200 px-3 py-1 rounded-full shadow-2xs">
            85% turnaround reduction
          </span>
          <span className="bg-white border border-neutral-200 px-3 py-1 rounded-full shadow-2xs">
            1.6s / page latency
          </span>
        </div>
      </div>

      {/* Side-by-Side: INVOICE (with scan line) → EXTRACTED DATA */}
      <div className="bg-white border border-neutral-200/90 rounded-3xl p-6 sm:p-8 shadow-md hover:shadow-xl transition-all duration-500 space-y-6">
        <div className="flex items-center justify-between font-mono text-xs font-bold border-b border-neutral-200/80 pb-4">
          <div className="flex items-center gap-2 text-neutral-800">
            <span className="bg-neutral-900 text-white px-2.5 py-1 rounded text-[11px]">INVOICE SCAN</span>
            <span className="text-neutral-400">→</span>
            <span className="bg-cyan-100 text-cyan-900 px-2.5 py-1 rounded text-[11px] border border-cyan-300/60">EXTRACTED SCHEMA</span>
          </div>
          <div className="flex items-center gap-2 text-[11px] text-neutral-500">
            <span className="w-2 h-2 rounded-full bg-cyan-500 animate-pulse"></span>
            <span className="font-bold text-neutral-900">98.0% ACCURACY</span>
          </div>
        </div>

        <div className="grid grid-cols-1 md:grid-cols-12 gap-6 items-stretch">
          <div className="md:col-span-6 bg-[#FCFCFA] border border-neutral-200/90 rounded-2xl p-5 sm:p-6 space-y-4 font-mono text-xs relative overflow-hidden shadow-2xs">
            <div className="invoice-scan-glow"></div>
            <div className="invoice-scan-line"></div>

            <div className="flex items-center justify-between border-b border-neutral-200 pb-3">
              <div className="flex items-center gap-2">
                <span className="w-2 h-2 rounded-full bg-red-400"></span>
                <span className="font-bold text-neutral-900 text-xs sm:text-sm">TAX INVOICE</span>
              </div>
              <span className="text-neutral-400 text-[11px]">{sampleInvoice.invoiceNo || "INV-2025-0842"}</span>
            </div>

            <div className="space-y-2 text-neutral-600 text-[11px] leading-relaxed">
              <div className="flex justify-between"><span className="text-neutral-400">VENDOR:</span> <span className="font-semibold text-neutral-900">{sampleInvoice.vendor || "Apex Industrial Tech Ltd"}</span></div>
              <div className="flex justify-between"><span className="text-neutral-400">ISSUE DATE:</span> <span>{sampleInvoice.date || "14-08-2025"}</span></div>
              <div className="flex justify-between"><span className="text-neutral-400">TAX ID:</span> <span>{sampleInvoice.taxId || "GSTIN29ABCDE1234F1Z5"}</span></div>
            </div>

            <div className="border-t border-neutral-200 pt-3 space-y-1.5 text-[10.5px]">
              <div className="flex justify-between font-bold text-neutral-500 pb-1 border-b border-neutral-100">
                <span>ITEM</span>
                <span>QTY · AMOUNT</span>
              </div>
              {(sampleInvoice.lineItems || [
                { desc: "High-Speed Sensor Module", qty: 4, total: 66000 },
                { desc: "Firmware Calibration License", qty: 1, total: 18200 }
              ]).map((it, idx) => (
                <div key={idx} className="flex justify-between text-neutral-700">
                  <span className="truncate max-w-[65%]">{it.desc}</span>
                  <span>{it.qty} × ₹{it.total?.toLocaleString()}</span>
                </div>
              ))}
            </div>

            <div className="border-t border-neutral-200 pt-3 flex justify-between font-bold text-neutral-900 text-xs sm:text-sm">
              <span>GRAND TOTAL:</span>
              <span className="text-neutral-900 font-black">₹{sampleInvoice.grandTotal?.toLocaleString() || "99,356"}</span>
            </div>
          </div>

          <div className="md:col-span-6 bg-neutral-950 rounded-2xl p-5 sm:p-6 space-y-3 text-white font-mono text-[11px] shadow-inner flex flex-col justify-between">
            <div className="flex items-center justify-between border-b border-neutral-800 pb-3">
              <span className="font-bold text-neutral-300">EXTRACTED DATA (PYDANTIC SCHEMA)</span>
              <span className="text-cyan-400 font-bold bg-cyan-950/80 border border-cyan-500/40 px-2 py-0.5 rounded text-[10px]">
                CONFIDENCE: 98.2%
              </span>
            </div>

            <pre className="text-cyan-300 text-[10.5px] sm:text-[11px] leading-relaxed overflow-x-auto flex-1 py-1">
{JSON.stringify(extractedJson, null, 2)}
            </pre>

            <div className="pt-2 border-t border-neutral-800 flex items-center justify-between text-[10px] text-neutral-400">
              <span>VALIDATION: <strong className="text-cyan-400">PASSED</strong></span>
              <span>ENGINE: DocTR + PaddleOCR</span>
            </div>
          </div>
        </div>
      </div>
    </article>
  );
};

// PROJECT 03 — TASKFLOW (PRODUCT & INTERACTIVE KANBAN COMPOSITION)
const TaskFlowShowcaseCard = ({ project, onOpenProject }) => {
  const telemetry = project.telemetry || {};
  const [activeStage, setActiveStage] = useState(0);

  useEffect(() => {
    const timer = setInterval(() => {
      setActiveStage((prev) => (prev + 1) % 3);
    }, 2400);
    return () => clearInterval(timer);
  }, []);

  const stages = ["TO DO", "IN PROGRESS", "DONE"];

  return (
    <article
      onClick={() => onOpenProject(project)}
      className="py-12 border-b border-neutral-200/80 space-y-8 cursor-pointer group select-none project-card-interactive"
    >
      <div className="space-y-3">
        <div className="flex items-center justify-between text-xs text-neutral-500 font-semibold tracking-wider">
          <div className="flex flex-wrap items-center gap-3">
            <span className="font-mono text-2xl font-black text-neutral-900">03</span>
            <span>/</span>
            <span className="uppercase text-neutral-700 font-bold">{project.category}</span>
            <span>·</span>
            <span className="text-neutral-700 font-mono text-[11px] font-bold bg-neutral-100 px-2 py-0.5 rounded border border-neutral-200">
              OPTIMISTIC UI & KANBAN
            </span>
            <span>·</span>
            <span className="font-mono text-[11px] text-neutral-600 font-bold">
              My role: {project.myRole || "Full-Stack Development"}
            </span>
          </div>
          <span className="text-xs font-bold text-neutral-500 group-hover:text-neutral-900 transition-colors flex items-center gap-1">
            <span>VIEW CASE STUDY</span>
            <Icon name="ArrowUpRight" size={14} className="transition-transform group-hover:translate-x-0.5 group-hover:-translate-y-0.5" />
          </span>
        </div>

        <h2 className="text-3xl sm:text-5xl font-black text-neutral-900 tracking-tight leading-tight uppercase group-hover:translate-x-1 transition-transform">
          {project.name || project.title}
        </h2>
        <p className="text-lg sm:text-2xl font-medium text-neutral-800 tracking-tight leading-snug max-w-3xl">
          {project.description || project.shortDescription}
        </p>

        <div className="flex flex-wrap items-center gap-3 pt-1 font-mono text-xs font-bold text-neutral-700">
          <span className="bg-white border border-neutral-200 px-3 py-1 rounded-full shadow-2xs text-purple-900">
            &lt;50ms UI updates
          </span>
          <span className="bg-white border border-neutral-200 px-3 py-1 rounded-full shadow-2xs">
            JWT auth middleware
          </span>
          <span className="bg-white border border-neutral-200 px-3 py-1 rounded-full shadow-2xs">
            MongoDB indexing
          </span>
        </div>
      </div>

      {/* Browser Chrome Frame with Moving Card Kanban */}
      <div className="w-full rounded-3xl bg-white border border-neutral-200/90 shadow-lg hover:shadow-2xl transition-all duration-500 overflow-hidden">
        <div className="px-5 py-3 bg-[#F4F4F0] border-b border-neutral-200/80 flex items-center justify-between">
          <div className="flex items-center gap-2">
            <span className="w-3 h-3 rounded-full bg-[#ff5f56]"></span>
            <span className="w-3 h-3 rounded-full bg-[#ffbd2e]"></span>
            <span className="w-3 h-3 rounded-full bg-[#27c93f]"></span>
          </div>
          <div className="bg-white border border-neutral-200/80 rounded-lg px-4 py-1 font-mono text-[11px] font-medium text-neutral-500 flex items-center gap-2">
            <span className="text-neutral-400">https://</span>
            <span>taskflow.app/workspace/board</span>
          </div>
          <div className="font-mono text-[11px] text-neutral-400 font-semibold">REACT 18 · OPTIMISTIC UI</div>
        </div>

        <div className="px-6 py-3 bg-white border-b border-neutral-200/80 flex items-center justify-between font-mono text-xs">
          <div className="flex items-center gap-3">
            <span className="text-neutral-400 text-[11px] uppercase font-bold">STATE FLOW:</span>
            {stages.map((stage, idx) => (
              <React.Fragment key={stage}>
                <span
                  className={`px-2.5 py-0.5 rounded font-bold transition-all ${
                    activeStage === idx
                      ? 'bg-neutral-900 text-white shadow-2xs scale-105'
                      : 'text-neutral-400'
                  }`}
                >
                  {stage}
                </span>
                {idx < stages.length - 1 && <span className="text-neutral-300">→</span>}
              </React.Fragment>
            ))}
          </div>
          <div className="text-[11px] text-purple-700 font-bold hidden sm:block">
            {activeStage === 0 && "Card Queued in Backlog"}
            {activeStage === 1 && "Card in Active Development"}
            {activeStage === 2 && "Card Completed & Verified"}
          </div>
        </div>

        <div className="p-6 bg-[#FAFAF8] space-y-4">
          <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
            <div className="bg-white border border-neutral-200/90 rounded-2xl p-4 space-y-3 shadow-2xs">
              <div className="flex items-center justify-between font-mono text-xs font-bold text-neutral-600 border-b border-neutral-100 pb-2">
                <span>TO DO</span>
                <span className="bg-neutral-100 px-2 py-0.5 rounded text-[10px]">{activeStage === 0 ? 2 : 1}</span>
              </div>
              <div className="space-y-2.5 min-h-[140px]">
                {activeStage === 0 && (
                  <div className="p-3 bg-white border-2 border-neutral-900 rounded-xl space-y-1.5 shadow-md animate-scale-expand transition-all">
                    <div className="flex items-center justify-between">
                      <span className="font-mono text-[10px] font-bold text-neutral-500">TF-102</span>
                      <span className="bg-neutral-100 text-neutral-800 px-2 py-0.5 rounded text-[9px] font-bold font-mono">TO DO</span>
                    </div>
                    <div className="text-xs font-bold text-neutral-900">Implement Webhook Queue Router</div>
                    <div className="flex items-center justify-between font-mono text-[10px] text-neutral-400 pt-1">
                      <span>Backend</span>
                      <span className="text-neutral-700 font-semibold">Gopi</span>
                    </div>
                  </div>
                )}
                <div className="p-3 bg-[#FDFCFA] border border-neutral-200/70 rounded-xl space-y-1.5 opacity-70">
                  <div className="text-xs font-medium text-neutral-700">CLAHE Filter Optimization</div>
                  <div className="flex items-center justify-between font-mono text-[10px] text-neutral-400">
                    <span>AI / ML</span>
                    <span>Alex</span>
                  </div>
                </div>
              </div>
            </div>

            <div className="bg-white border border-neutral-200/90 rounded-2xl p-4 space-y-3 shadow-2xs">
              <div className="flex items-center justify-between font-mono text-xs font-bold text-neutral-600 border-b border-neutral-100 pb-2">
                <span>IN PROGRESS</span>
                <span className="bg-purple-100 text-purple-700 px-2 py-0.5 rounded text-[10px]">{activeStage === 1 ? 2 : 1}</span>
              </div>
              <div className="space-y-2.5 min-h-[140px]">
                {activeStage === 1 && (
                  <div className="p-3 bg-white border-2 border-purple-600 rounded-xl space-y-1.5 shadow-md animate-scale-expand transition-all">
                    <div className="flex items-center justify-between">
                      <span className="font-mono text-[10px] font-bold text-purple-600">TF-102</span>
                      <span className="bg-purple-100 text-purple-800 px-2 py-0.5 rounded text-[9px] font-bold font-mono">IN PROGRESS ⚡</span>
                    </div>
                    <div className="text-xs font-bold text-neutral-900">Implement Webhook Queue Router</div>
                    <div className="flex items-center justify-between font-mono text-[10px] text-neutral-400 pt-1">
                      <span>Backend</span>
                      <span className="text-purple-700 font-semibold">Gopi</span>
                    </div>
                  </div>
                )}
                <div className="p-3 bg-[#FDFCFA] border border-neutral-200/70 rounded-xl space-y-1.5 opacity-70">
                  <div className="text-xs font-medium text-neutral-700">JWT Refresh Token Middleware</div>
                  <div className="flex items-center justify-between font-mono text-[10px] text-neutral-400">
                    <span>Security</span>
                    <span>Dev</span>
                  </div>
                </div>
              </div>
            </div>

            <div className="bg-white border border-neutral-200/90 rounded-2xl p-4 space-y-3 shadow-2xs">
              <div className="flex items-center justify-between font-mono text-xs font-bold text-neutral-600 border-b border-neutral-100 pb-2">
                <span>DONE</span>
                <span className="bg-emerald-100 text-emerald-700 px-2 py-0.5 rounded text-[10px]">{activeStage === 2 ? 3 : 2}</span>
              </div>
              <div className="space-y-2.5 min-h-[140px]">
                {activeStage === 2 && (
                  <div className="p-3 bg-white border-2 border-emerald-500 rounded-xl space-y-1.5 shadow-md animate-scale-expand transition-all">
                    <div className="flex items-center justify-between">
                      <span className="font-mono text-[10px] font-bold text-emerald-600">TF-102</span>
                      <span className="bg-emerald-100 text-emerald-800 px-2 py-0.5 rounded text-[9px] font-bold font-mono">DONE ✓</span>
                    </div>
                    <div className="text-xs font-bold text-neutral-900">Implement Webhook Queue Router</div>
                    <div className="flex items-center justify-between font-mono text-[10px] text-neutral-400 pt-1">
                      <span>Backend</span>
                      <span className="text-emerald-700 font-semibold">Gopi</span>
                    </div>
                  </div>
                )}
                <div className="p-3 bg-[#FDFCFA] border border-neutral-200/70 rounded-xl space-y-1.5 opacity-70">
                  <div className="text-xs font-medium text-neutral-700">DocTR Layout Parser Integration</div>
                  <div className="flex items-center justify-between font-mono text-[10px] text-neutral-400">
                    <span>AI / ML</span>
                    <span>Gopi</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div className="p-4 bg-white border-t border-neutral-200 flex flex-wrap items-center justify-between gap-4 font-mono text-xs text-neutral-600">
          <div className="flex items-center gap-4">
            <span><strong>Auth:</strong> {telemetry.authSystem || "JWT + Cookies"}</span>
            <span>·</span>
            <span><strong>Database:</strong> {telemetry.dbEngine || "MongoDB Indexing"}</span>
          </div>
          <div className="text-neutral-900 font-bold">
            {telemetry.syncStrategy || "Optimistic UI"}
          </div>
        </div>
      </div>
    </article>
  );
};

// SECONDARY PROJECTS GRID (04 & 05 Unified Stream)
const SecondaryProjectsGrid = ({ projects = [], onOpenProject }) => {
  if (!projects || projects.length === 0) return null;

  return (
    <div className="pt-10 pb-6 space-y-6">
      <div className="flex items-center justify-between border-b border-neutral-200/80 pb-3">
        <div className="font-mono text-xs font-bold text-neutral-900 uppercase tracking-wider">
          ADDITIONAL SYSTEMS (04 &amp; 05)
        </div>
        <span className="font-mono text-[10px] text-neutral-400 uppercase tracking-widest hidden sm:inline">
          RETRIEVAL &amp; GENERATIVE ARCHITECTURES
        </span>
      </div>

      <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
        {projects.map((proj) => {
          const tags = proj.cleanTags || proj.actualTechnologies || [];

          return (
            <ScrollReveal key={proj.id}>
              <div
                onClick={() => onOpenProject(proj)}
                className="bg-white border border-neutral-200/90 hover:border-neutral-400/90 rounded-2xl p-6 sm:p-7 space-y-5 shadow-2xs hover:shadow-xs transition-all duration-300 cursor-pointer group select-none flex flex-col justify-between h-full project-card-interactive"
              >
                <div className="space-y-4">
                  {/* Top metadata row */}
                  <div className="flex items-center justify-between text-xs font-mono">
                    <div className="flex items-center gap-2">
                      <span className="font-mono text-xl font-black text-neutral-900">{proj.number}</span>
                      <span className="text-neutral-300">/</span>
                      <span className="text-[11px] font-bold text-neutral-600 uppercase tracking-wider">
                        {proj.category || "AI SYSTEMS"}
                      </span>
                    </div>
                    <span className="bg-neutral-100 group-hover:bg-neutral-200 text-neutral-700 px-2.5 py-0.5 rounded-full font-mono font-bold text-[10px] tracking-wider transition-colors">
                      {proj.badge || "SYSTEM"}
                    </span>
                  </div>

                  {/* Title & Role */}
                  <div className="space-y-1">
                    <h3 className="text-lg sm:text-xl font-black text-neutral-900 uppercase tracking-tight group-hover:text-neutral-800 transition-colors">
                      {proj.name || proj.title}
                    </h3>
                    <div className="font-mono text-[11px] text-neutral-500 font-semibold">
                      My role: {proj.myRole || "AI Engineering"}
                    </div>
                  </div>

                  {/* Description */}
                  <p className="text-xs sm:text-sm text-neutral-600 leading-relaxed font-normal">
                    {proj.description || proj.shortDescription}
                  </p>

                  {/* Technology Tags */}
                  {tags.length > 0 && (
                    <div className="flex flex-wrap gap-1.5 pt-1">
                      {tags.map((t, idx) => (
                        <span
                          key={idx}
                          className="font-mono text-[11px] font-semibold text-neutral-600 bg-neutral-100 px-2.5 py-0.5 rounded-md"
                        >
                          {t}
                        </span>
                      ))}
                    </div>
                  )}
                </div>

                {/* Footer Action */}
                <div className="pt-4 border-t border-neutral-100 flex items-center justify-between font-mono text-xs font-bold text-neutral-900">
                  <span>VIEW CASE STUDY</span>
                  <span className="transition-transform group-hover:translate-x-1">→</span>
                </div>
              </div>
            </ScrollReveal>
          );
        })}
      </div>
    </div>
  );
};

// Backwards compatibility alias
const ExperimentsSection = SecondaryProjectsGrid;

// PROFESSIONAL EXPERIENCE SECTION (Impact-First Engineering Accomplishments)
const ExperienceSection = ({ experience = [], timeline = [] }) => {
  return (
    <section id="experience" className="w-full max-w-6xl mx-auto px-6 py-14 space-y-10 border-t border-neutral-200/80">
      <ScrollReveal className="space-y-1.5">
        <div className="text-[11px] font-mono font-bold text-neutral-400 uppercase tracking-widest">
          EXPERIENCE &amp; TRACK RECORD
        </div>
        <h2 className="text-2xl sm:text-3xl font-black text-neutral-900 uppercase tracking-tight">
          Professional Experience
        </h2>
      </ScrollReveal>

      {/* Experience Cards */}
      <div className="grid grid-cols-1 gap-6">
        {experience.map((exp) => {
          const metrics = exp.metrics || [
            { value: "10K+", label: "records processed" },
            { value: "30%", label: "redundancy reduction" }
          ];
          const techPill = exp.techPill || (exp.technologies ? exp.technologies.slice(0, 4).join(" · ") : "Python · PaddleOCR · OpenCV · FastAPI");
          const bullets = exp.bullets || [
            "Built automated OCR document parsing pipelines utilizing PaddleOCR & OpenCV to extract structured fields from scanned PDFs.",
            "Engineered duplicate-detection algorithms and FastAPI endpoints across 10,000+ asset records, cutting data redundancy by 30%.",
            "Designed structured data annotation workflows and validated extraction accuracy against challenging edge-case document layouts."
          ];

          return (
            <ScrollReveal key={exp.id}>
              <div className="bg-white border border-neutral-200/90 rounded-3xl p-6 sm:p-8 shadow-xs hover:shadow-md transition-all duration-300 space-y-6">
                
                {/* 01. Strongest Header: Title — Company */}
                <div className="flex flex-col sm:flex-row sm:items-baseline justify-between gap-2 border-b border-neutral-100 pb-5">
                  <h3 className="text-xl sm:text-2xl font-black text-neutral-900 uppercase tracking-tight flex flex-wrap items-center gap-2">
                    <span>{exp.role.toUpperCase()}</span>
                    <span className="text-neutral-300 font-light">—</span>
                    <span className="text-neutral-700">{exp.company.toUpperCase()}</span>
                  </h3>
                  <div className="font-mono text-xs font-semibold text-neutral-400 uppercase tracking-wider">
                    {exp.type} · {exp.period}
                  </div>
                </div>

                {/* 02. Immediately: Key Accomplishment Metrics + Tech Stack */}
                <div className="grid grid-cols-1 sm:grid-cols-3 gap-3.5">
                  {metrics.map((m, i) => (
                    <div key={i} className="bg-[#F9F9F7] border border-neutral-200/80 rounded-2xl px-4 py-3.5 flex items-center gap-3">
                      <div className="font-mono text-2xl font-black text-neutral-900">
                        {m.value}
                      </div>
                      <div className="font-mono text-xs text-neutral-600 font-medium leading-tight">
                        {m.label}
                      </div>
                    </div>
                  ))}

                  <div className="bg-[#F9F9F7] border border-neutral-200/80 rounded-2xl px-4 py-3.5 flex items-center">
                    <div className="font-mono text-xs text-neutral-800 font-bold tracking-tight">
                      {techPill}
                    </div>
                  </div>
                </div>

                {/* 03. 2–3 Concise Impact Bullets */}
                <div className="space-y-2.5 pt-1">
                  {bullets.map((b, i) => (
                    <div key={i} className="flex items-start gap-3 text-sm sm:text-[14.5px] text-neutral-700 leading-relaxed font-normal">
                      <span className="text-neutral-400 font-mono text-xs pt-0.5 select-none font-bold">0{i + 1}</span>
                      <span>{b}</span>
                    </div>
                  ))}
                </div>

              </div>
            </ScrollReveal>
          );
        })}
      </div>

      {/* Editorial Horizontal Progression Timeline */}
      <ScrollReveal className="space-y-5 pt-4">
        <div className="flex items-center justify-between border-b border-neutral-200/80 pb-2.5">
          <div className="text-[11px] font-mono font-bold text-neutral-400 uppercase tracking-widest">
            CAREER &amp; EDUCATION PROGRESSION
          </div>
          <div className="font-mono text-[11px] text-neutral-400 uppercase tracking-wider hidden sm:block">
            2020 → 2026
          </div>
        </div>

        {/* Desktop Connected Horizontal Progression Track: 2020 ─── 2023 ─── 2024 ─── 2025 ─── 2026 */}
        <div className="hidden lg:grid grid-cols-5 gap-3.5 items-center relative mb-3">
          {timeline.map((item, idx) => (
            <div key={idx} className="relative flex items-center">
              {/* Connecting Line Segment to next node */}
              {idx < timeline.length - 1 && (
                <div className="absolute left-6 right-[-14px] top-1/2 -translate-y-1/2 h-[2px] bg-neutral-200/90 z-0" />
              )}
              
              {/* Year Node Badge */}
              <div className={`relative z-10 inline-flex items-center gap-2 px-3 py-1 rounded-full border shadow-2xs ${
                item.year === '2026' 
                  ? 'bg-neutral-900 text-white border-neutral-900' 
                  : 'bg-white text-neutral-900 border-neutral-200/90'
              }`}>
                <span className={`w-1.5 h-1.5 rounded-full ${
                  item.year === '2026' ? 'bg-emerald-400 animate-pulse' : 'bg-neutral-400'
                }`} />
                <span className="font-mono text-xs font-black tracking-tight">{item.year}</span>
              </div>
            </div>
          ))}
        </div>

        {/* Small Milestone Cards Underneath */}
        <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-3.5">
          {timeline.map((item, idx) => (
            <div
              key={idx}
              className={`bg-white border rounded-2xl p-4 space-y-2 shadow-2xs hover:shadow-xs hover:border-neutral-300 transition-all duration-200 flex flex-col justify-between ${
                item.year === '2026' ? 'border-neutral-900/20 ring-1 ring-neutral-900/5' : 'border-neutral-200/80'
              }`}
            >
              {/* Mobile-only Year Header when top progression track is hidden */}
              <div className="lg:hidden flex items-center justify-between pb-1 border-b border-neutral-100">
                <span className="font-mono text-sm font-black text-neutral-900">{item.year}</span>
                {item.year === '2026' && (
                  <span className="font-mono text-[9px] font-bold text-emerald-600 bg-emerald-50 px-2 py-0.5 rounded-full uppercase">
                    ACTIVE
                  </span>
                )}
              </div>

              <div className="space-y-1">
                <div className="font-bold text-xs sm:text-[13px] text-neutral-900 leading-snug tracking-tight">
                  {item.title}
                </div>
                <p className="text-[11px] text-neutral-500 leading-relaxed font-normal">
                  {item.subtitle}
                </p>
              </div>
            </div>
          ))}
        </div>
      </ScrollReveal>
    </section>
  );
};

// COMPACT TECH STACK SECTION (No Subjective Level Ratings)
const ToolsIBuildWith = ({ techStack = [] }) => {
  if (!techStack || techStack.length === 0) return null;

  return (
    <section className="w-full max-w-6xl mx-auto px-6 py-12 space-y-6 border-t border-neutral-200/80">
      <ScrollReveal className="space-y-1.5">
        <div className="text-[11px] font-mono font-bold text-neutral-400 uppercase tracking-widest">
          TECHNICAL TOOLKIT
        </div>
        <h2 className="text-2xl sm:text-3xl font-black text-neutral-900 uppercase tracking-tight">
          Tech Stack
        </h2>
      </ScrollReveal>

      <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
        {techStack.map((group, idx) => (
          <ScrollReveal key={idx}>
            <div className="bg-white border border-neutral-200/80 rounded-2xl p-5 space-y-3 shadow-2xs h-full">
              <div className="font-mono text-xs font-bold text-neutral-900 uppercase tracking-wider border-b border-neutral-100 pb-2">
                {group.category}
              </div>
              <div className="flex flex-wrap gap-1.5">
                {(group.items || []).map((item, i) => (
                  <span
                    key={i}
                    className="font-mono text-xs font-semibold text-neutral-700 bg-neutral-100 hover:bg-neutral-200 px-2.5 py-1 rounded-md transition-colors"
                  >
                    {item}
                  </span>
                ))}
              </div>
            </div>
          </ScrollReveal>
        ))}
      </div>
    </section>
  );
};

// TWO-TIER PROJECT CASE STUDY MODAL (Instant Recruiter Scan + Progressive Deep Dive)
const FullScreenProjectViewModal = ({ project, allProjects = [], onClose, onSwitchProject }) => {
  const [lightboxIndex, setLightboxIndex] = useState(null);
  const [isDeepDiveOpen, setIsDeepDiveOpen] = useState(false);
  const [selectedNode, setSelectedNode] = useState(null);

  const heroSrc = project.hero || project.image;
  const chapters = project.chapters || [];
  const galleryItems = project.gallery || [];
  const currentIndex = allProjects.findIndex(p => p.id === project.id);
  const numberStr = project.number || String(currentIndex + 1).padStart(2, '0');
  const prevProject = currentIndex > 0 ? allProjects[currentIndex - 1] : null;
  const nextProject = currentIndex < allProjects.length - 1 ? allProjects[currentIndex + 1] : null;

  useEffect(() => {
    document.body.style.overflow = 'hidden';
    const handleKeyDown = (e) => {
      if (e.key === 'Escape' && lightboxIndex === null) onClose();
    };
    window.addEventListener('keydown', handleKeyDown);
    return () => {
      document.body.style.overflow = '';
      window.removeEventListener('keydown', handleKeyDown);
    };
  }, [lightboxIndex, onClose]);

  const cleanTechList = (project.actualTechnologies || project.cleanTags || []).join(" · ");

  return (
    <div key={project.id} className="fixed inset-0 z-50 bg-[#F7F7F5] overflow-y-auto animate-project-backdrop text-[#111111] selection:bg-[#111111] selection:text-white">
      {/* Sticky Top Bar */}
      <div className="sticky top-0 z-40 bg-[#F7F7F5]/90 backdrop-blur-md border-b border-neutral-200/80 px-6 py-4 animate-project-header">
        <div className="max-w-5xl mx-auto flex items-center justify-between font-mono text-xs font-semibold">
          <button
            onClick={onClose}
            className="inline-flex items-center gap-2 text-neutral-600 hover:text-neutral-900 transition-colors px-3 py-1.5 rounded-full hover:bg-neutral-200/60 cursor-pointer"
          >
            <Icon name="ArrowLeft" size={16} />
            <span>Back to work</span>
          </button>

          <div className="text-neutral-500 font-bold uppercase hidden sm:block">
            {numberStr} / {project.name || project.title}
          </div>

          <button
            onClick={onClose}
            className="p-2 text-neutral-500 hover:text-neutral-900 transition-colors rounded-full hover:bg-neutral-200/60 cursor-pointer"
            title="Close View (ESC)"
          >
            <Icon name="Close" size={20} />
          </button>
        </div>
      </div>

      {/* Main Container */}
      <div className="max-w-5xl mx-auto px-6 py-12 space-y-12">
        {/* TIER 1: FAST RECRUITER SUMMARY (Scannable in 20 seconds) */}
        <div className="space-y-6">
          <div className="space-y-3">
            <div className="flex flex-wrap items-center gap-3 text-xs text-neutral-500 font-semibold tracking-wider">
              <span className="font-mono text-2xl font-black text-neutral-900">{numberStr}</span>
              <span>/</span>
              <span className="uppercase text-neutral-700 font-bold">{project.category}</span>
              <span>·</span>
              <span className="text-neutral-900 font-mono text-[11px] font-bold bg-neutral-200 px-2.5 py-0.5 rounded">
                {project.badge || "BUILT PROJECT"}
              </span>
            </div>

            <h1 className="text-3xl sm:text-6xl font-black text-neutral-900 tracking-tight leading-[0.98] uppercase">
              {project.name || project.title}
            </h1>

            <p className="text-lg sm:text-2xl font-medium text-neutral-800 tracking-tight leading-snug">
              {project.description || project.shortDescription}
            </p>

            {/* My Role & Key Metrics Strip */}
            <div className="flex flex-wrap items-center gap-3 pt-2 font-mono text-xs font-bold">
              <span className="bg-neutral-900 text-white px-3 py-1 rounded-full">
                My role: {project.myRole || "Engineering Lead"}
              </span>
              {project.metricsSummary && (
                <span className="bg-emerald-50 border border-emerald-300 text-emerald-900 px-3 py-1 rounded-full">
                  {project.metricsSummary}
                </span>
              )}
            </div>
          </div>

          {/* Large Visual Showcase Frame */}
          <div
            className="w-full cursor-pointer animate-project-hero-expand"
            onClick={() => setLightboxIndex(0)}
          >
            <VisualFrame
              src={heroSrc}
              alt={`${project.name || project.title} Showcase`}
              frameType={project.id === "smartdoc-parser" ? "macbook" : project.id === "taskflow-saas" ? "browser" : "fullbleed"}
              isPriority={true}
            />
          </div>

          {/* The Problem & What I Built (Crisp Recruiter Breakdown) */}
          <div className="grid grid-cols-1 md:grid-cols-12 gap-6 pt-2">
            {/* The Problem */}
            <div className="md:col-span-5 bg-white border border-neutral-200/80 p-6 rounded-2xl shadow-xs space-y-2.5">
              <div className="text-[11px] font-bold tracking-widest text-neutral-400 uppercase font-mono flex items-center gap-2">
                <span className="w-2 h-2 rounded-full bg-amber-500"></span>
                <span>THE PROBLEM</span>
              </div>
              <p className="text-sm text-neutral-700 leading-relaxed">
                {project.problem}
              </p>
            </div>

            {/* What I Built */}
            <div className="md:col-span-7 bg-white border border-neutral-200/80 p-6 rounded-2xl shadow-xs space-y-2.5">
              <div className="text-[11px] font-bold tracking-widest text-neutral-400 uppercase font-mono flex items-center gap-2">
                <span className="w-2 h-2 rounded-full bg-emerald-500"></span>
                <span>WHAT I BUILT</span>
              </div>
              <ul className="space-y-2 text-xs sm:text-sm text-neutral-700 leading-relaxed list-disc list-inside">
                {(project.whatIBuilt || [project.solution]).map((point, idx) => (
                  <li key={idx} className="leading-snug">{point}</li>
                ))}
              </ul>
            </div>
          </div>

          {/* Core Tech Stack & Action Links */}
          <div className="bg-white border border-neutral-200/80 p-6 rounded-2xl shadow-xs flex flex-col sm:flex-row sm:items-center justify-between gap-4">
            <div className="space-y-1">
              <div className="text-[10px] font-mono font-bold text-neutral-400 uppercase tracking-widest">
                CORE TECH
              </div>
              <div className="font-mono text-xs sm:text-sm font-semibold text-neutral-900">
                {cleanTechList}
              </div>
            </div>

            <div className="flex flex-wrap items-center gap-3">
              {project.repositoryUrl && (
                <a
                  href={project.repositoryUrl}
                  target="_blank"
                  rel="noopener noreferrer"
                  className="inline-flex items-center gap-2 px-5 py-2.5 rounded-full bg-neutral-900 hover:bg-neutral-800 text-white font-mono text-xs font-bold uppercase tracking-wider transition-all shadow-2xs"
                >
                  <span>SOURCE CODE (GITHUB)</span>
                  <Icon name="ArrowUpRight" size={13} />
                </a>
              )}
            </div>
          </div>
        </div>

        {/* TIER 2: PROGRESSIVE DISCLOSURE — "Technical Deep Dive ↓" */}
        <div className="pt-4 border-t border-neutral-200/80 space-y-6">
          <div className="flex items-center justify-center">
            <button
              onClick={() => setIsDeepDiveOpen((prev) => !prev)}
              className="inline-flex items-center gap-3 px-8 py-3.5 rounded-full bg-white border-2 border-neutral-900 text-neutral-900 hover:bg-neutral-900 hover:text-white font-mono text-xs font-black uppercase tracking-wider transition-all shadow-sm cursor-pointer"
            >
              <span>{isDeepDiveOpen ? "HIDE TECHNICAL DEEP DIVE ↑" : "TECHNICAL DEEP DIVE ↓"}</span>
              <Icon name={isDeepDiveOpen ? "ChevronUp" : "ChevronDown"} size={16} />
            </button>
          </div>

          {isDeepDiveOpen && (
            <div className="space-y-12 animate-scale-expand pt-4">
              {/* Architecture Layer & Node Inspector */}
              {project.architectureNodes && project.architectureNodes.length > 0 && (
                <div className="bg-white border border-neutral-200/90 rounded-3xl p-6 sm:p-8 shadow-xs space-y-5">
                  <div className="flex flex-col sm:flex-row sm:items-center justify-between border-b border-neutral-100 pb-3 gap-2">
                    <div>
                      <div className="font-mono text-xs font-bold text-neutral-400 uppercase tracking-widest">
                        SYSTEM ARCHITECTURE LAYER
                      </div>
                      <h3 className="text-lg font-black text-neutral-900 uppercase tracking-tight">
                        Pipeline Nodes & Data Flow
                      </h3>
                    </div>
                    <span className="font-mono text-[11px] text-neutral-400">CLICK TO INSPECT NODE</span>
                  </div>

                  <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3">
                    {project.architectureNodes.map((node, i) => {
                      const isSelected = selectedNode?.name === node.name;
                      return (
                        <div
                          key={i}
                          onClick={() => setSelectedNode(node)}
                          className={`p-3.5 rounded-2xl border transition-all cursor-pointer space-y-1.5 ${
                            isSelected
                              ? 'bg-neutral-900 text-white border-neutral-900 shadow-md'
                              : 'bg-[#F9F9F7] text-neutral-800 border-neutral-200/80 hover:border-neutral-400'
                          }`}
                        >
                          <div className="flex items-center justify-between font-mono text-[9.5px] uppercase">
                            <span className={isSelected ? 'text-neutral-300' : 'text-neutral-400'}>{node.type}</span>
                            <span className={isSelected ? 'text-emerald-400 font-bold' : 'text-neutral-500 font-bold'}>{node.latency}</span>
                          </div>
                          <div className="font-bold text-xs sm:text-sm">{node.name}</div>
                          <p className={`text-[11px] leading-relaxed ${isSelected ? 'text-neutral-200' : 'text-neutral-600'}`}>
                            {node.role}
                          </p>
                        </div>
                      );
                    })}
                  </div>
                </div>
              )}



              {/* Challenge & Breakthrough */}
              {project.challenge && (
                <div className="bg-white border border-neutral-200/80 p-6 rounded-2xl shadow-xs space-y-3">
                  <div className="text-[11px] font-bold tracking-widest text-neutral-400 uppercase font-mono flex items-center justify-between border-b border-neutral-100 pb-2">
                    <span>TECHNICAL CHALLENGE & BREAKTHROUGH</span>
                    <span className="text-neutral-600 font-semibold">{project.challenge.title}</span>
                  </div>

                  <div className="grid grid-cols-1 md:grid-cols-2 gap-4 pt-1">
                    <div className="space-y-1">
                      <div className="text-xs font-bold text-neutral-400 uppercase font-mono">Engineering Roadblock</div>
                      <p className="text-xs sm:text-sm text-neutral-700 leading-relaxed">
                        {project.challenge.description}
                      </p>
                    </div>

                    <div className="space-y-1 border-t md:border-t-0 md:border-l border-neutral-200/60 pt-3 md:pt-0 md:pl-4">
                      <div className="text-xs font-bold text-neutral-900 uppercase font-mono flex items-center gap-1.5">
                        <Icon name="CheckCircle" size={13} className="text-emerald-600" />
                        <span>How I Overcame It</span>
                      </div>
                      <p className="text-xs sm:text-sm text-neutral-700 leading-relaxed font-medium">
                        {project.challenge.overcame}
                      </p>
                    </div>
                  </div>
                </div>
              )}

              {/* Engineering Decisions & Trade-Offs */}
              {project.decisions && project.decisions.length > 0 && (
                <div className="space-y-3">
                  <div className="text-[11px] font-mono font-bold text-neutral-400 uppercase tracking-widest border-b border-neutral-200/80 pb-2">
                    ENGINEERING DECISIONS & TRADE-OFF LOG
                  </div>

                  <div className="grid grid-cols-1 md:grid-cols-3 gap-3">
                    {project.decisions.map((d, i) => (
                      <div key={i} className="bg-white border border-neutral-200/80 rounded-2xl p-4 space-y-2 shadow-2xs">
                        <div className="font-bold text-xs sm:text-sm text-neutral-900 leading-snug">{d.decision}</div>
                        <div className="space-y-0.5">
                          <div className="font-mono text-[9.5px] font-bold text-neutral-400 uppercase">Reason</div>
                          <p className="text-xs text-neutral-600 leading-relaxed">{d.reason}</p>
                        </div>
                        <div className="space-y-0.5 border-t border-neutral-100 pt-1.5">
                          <div className="font-mono text-[9.5px] font-bold text-amber-700 uppercase">Trade-off</div>
                          <p className="text-xs text-neutral-500 leading-relaxed">{d.tradeoff}</p>
                        </div>
                      </div>
                    ))}
                  </div>
                </div>
              )}

              {/* What Didn't Work */}
              {project.whatDidntWork && (
                <div className="bg-[#FAF9F5] border border-amber-200/80 rounded-2xl p-5 space-y-2.5">
                  <div className="font-mono text-xs font-bold text-amber-800 uppercase tracking-wider flex items-center gap-2">
                    <span>⚠️ WHAT DIDN'T WORK & HOW IT WAS RESOLVED</span>
                  </div>
                  <div className="grid grid-cols-1 md:grid-cols-2 gap-3 text-xs text-neutral-700 leading-relaxed">
                    <div>
                      <strong className="text-neutral-900 block mb-0.5">Initial Hurdle:</strong>
                      {project.whatDidntWork.hurdle}
                    </div>
                    <div className="border-t md:border-t-0 md:border-l border-amber-200/60 pt-2 md:pt-0 md:pl-3">
                      <strong className="text-emerald-800 block mb-0.5">Technical Resolution:</strong>
                      {project.whatDidntWork.fix}
                    </div>
                  </div>
                </div>
              )}

              {/* STAR Method Breakdown */}
              {project.starMethod && (
                <div className="space-y-3">
                  <div className="flex items-center justify-between text-[11px] font-bold tracking-widest text-neutral-400 uppercase border-b border-neutral-200/60 pb-2">
                    <span>REAL-WORLD IMPACT (STAR METHOD)</span>
                    <span className="font-mono text-[10px]">VERIFIED RECORD</span>
                  </div>

                  <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3">
                    <div className="bg-white border border-neutral-200/80 p-4 rounded-2xl space-y-1">
                      <div className="font-mono text-xs font-bold text-neutral-400 uppercase">S — SITUATION</div>
                      <p className="text-xs text-neutral-600 leading-relaxed">{project.starMethod.situation}</p>
                    </div>

                    <div className="bg-white border border-neutral-200/80 p-4 rounded-2xl space-y-1">
                      <div className="font-mono text-xs font-bold text-neutral-400 uppercase">T — TASK</div>
                      <p className="text-xs text-neutral-600 leading-relaxed">{project.starMethod.task}</p>
                    </div>

                    <div className="bg-white border border-neutral-200/80 p-4 rounded-2xl space-y-1">
                      <div className="font-mono text-xs font-bold text-neutral-400 uppercase">A — ACTION</div>
                      <p className="text-xs text-neutral-600 leading-relaxed">{project.starMethod.action}</p>
                    </div>

                    <div className="bg-neutral-900 text-white p-4 rounded-2xl space-y-1 shadow-sm">
                      <div className="font-mono text-xs font-bold text-neutral-400 uppercase">R — RESULT</div>
                      <p className="text-xs text-neutral-200 font-medium leading-relaxed">{project.starMethod.result}</p>
                    </div>
                  </div>
                </div>
              )}

              {/* Chapters & Workflow Gallery */}
              {chapters.length > 0 && (
                <div className="space-y-10 pt-2">
                  {chapters.map((chap, chapIdx) => {
                    const isFullWidth = chap.layout === "large" || chap.items.length === 1;

                    return (
                      <div key={chapIdx} className="space-y-4">
                        <div className="flex items-center justify-between text-[11px] font-bold tracking-widest text-neutral-400 uppercase border-b border-neutral-200/60 pb-2">
                          <span>{chap.title}</span>
                          <span className="font-mono text-[10px]">CLICK SCREEN TO EXPAND ↗</span>
                        </div>

                        <div className={`grid gap-6 ${isFullWidth ? 'grid-cols-1' : 'grid-cols-1 md:grid-cols-2'}`}>
                          {chap.items.map((item, itemIdx) => {
                            const globalIdx = galleryItems.findIndex((it) => it.src === item.src);
                            const activeIdx = globalIdx >= 0 ? globalIdx : itemIdx;
                            return (
                              <div
                                key={itemIdx}
                                onClick={() => setLightboxIndex(activeIdx + 1)}
                                className="cursor-pointer group space-y-2"
                              >
                                <VisualFrame
                                  src={item.src}
                                  alt={item.step}
                                  frameType={project.id === "smartdoc-parser" ? "macbook" : project.id === "taskflow-saas" ? "browser" : "fullbleed"}
                                />
                                <div className="space-y-0.5 px-1">
                                  <div className="text-xs font-semibold text-neutral-900 group-hover:text-neutral-600 transition-colors flex items-center justify-between">
                                    <span><span className="font-mono font-bold">0{activeIdx + 1} / 0{galleryItems.length}</span> — {item.step}</span>
                                    <span className="text-[10px] font-semibold text-neutral-400 opacity-0 group-hover:opacity-100 transition-opacity">VIEW</span>
                                  </div>
                                  {item.caption && (
                                    <p className="text-xs text-neutral-500 leading-relaxed">{item.caption}</p>
                                  )}
                                </div>
                              </div>
                            );
                          })}
                        </div>
                      </div>
                    );
                  })}
                </div>
              )}
            </div>
          )}
        </div>

        {/* Dual Previous / Next Navigation Controls */}
        <div className="pt-8 pb-4 border-t border-neutral-200/80 flex items-center justify-between font-semibold text-xs sm:text-sm">
          {prevProject ? (
            <button
              onClick={() => { setLightboxIndex(null); setIsDeepDiveOpen(false); onSwitchProject(prevProject); }}
              className="inline-flex items-center gap-2 text-neutral-700 hover:text-neutral-900 transition-colors cursor-pointer text-left group"
            >
              <Icon name="ArrowLeft" size={16} className="text-neutral-400 group-hover:text-neutral-900 transition-all" />
              <div>
                <div className="text-[10px] font-mono font-bold text-neutral-400 uppercase tracking-widest">PREVIOUS</div>
                <div className="font-bold uppercase tracking-wide group-hover:underline">{prevProject.number || ''} {prevProject.name || prevProject.title}</div>
              </div>
            </button>
          ) : <div></div>}

          {nextProject ? (
            <button
              onClick={() => { setLightboxIndex(null); setIsDeepDiveOpen(false); onSwitchProject(nextProject); }}
              className="inline-flex items-center gap-2 text-neutral-700 hover:text-neutral-900 transition-colors cursor-pointer text-right group"
            >
              <div>
                <div className="text-[10px] font-mono font-bold text-neutral-400 uppercase tracking-widest">NEXT</div>
                <div className="font-bold uppercase tracking-wide group-hover:underline">{nextProject.number || ''} {nextProject.name || nextProject.title} →</div>
              </div>
              <Icon name="ArrowUpRight" size={16} className="text-neutral-400 group-hover:text-neutral-900 transition-all" />
            </button>
          ) : <div></div>}
        </div>
      </div>

      {lightboxIndex !== null && (
        <LightboxModal
          project={project}
          initialIndex={lightboxIndex}
          onClose={() => setLightboxIndex(null)}
        />
      )}
    </div>
  );
};

// PROJECT GALLERY CONTAINER (HOMEPAGE)
const ProjectGallery = ({ projects = [], experiments = [], selectedProject, setSelectedProject }) => {
  const p1 = projects[0];
  const p2 = projects[1];
  const p3 = projects[2];

  const allProjectsList = [...projects, ...experiments];

  return (
    <section id="work" className="w-full max-w-6xl mx-auto px-6 pt-6 pb-6 relative">
      <div className="text-xs font-mono font-bold tracking-widest text-neutral-400 uppercase border-b border-neutral-200/80 pb-3 flex items-center justify-between">
        <span>SELECTED WORK (01 — 05)</span>
        <span className="text-[11px] text-neutral-400 font-semibold hidden sm:inline">5 PRODUCTION &amp; RESEARCH SYSTEMS</span>
      </div>

      {p1 && <FlagshipLeadGenCard project={p1} onOpenProject={setSelectedProject} />}
      {p2 && <SmartDocShowcaseCard project={p2} onOpenProject={setSelectedProject} />}
      {p3 && <TaskFlowShowcaseCard project={p3} onOpenProject={setSelectedProject} />}

      <SecondaryProjectsGrid projects={experiments} onOpenProject={setSelectedProject} />

      {selectedProject && (
        <FullScreenProjectViewModal
          project={selectedProject}
          allProjects={allProjectsList}
          onClose={() => setSelectedProject(null)}
          onSwitchProject={setSelectedProject}
        />
      )}
    </section>
  );
};

// ABOUT & FINAL CTA SECTION (Editorial Spread + Connect CTA)
const AboutSection = ({ profile = {}, onOpenArchive }) => {
  const [copied, setCopied] = useState(false);
  const [arrowPos, setArrowPos] = useState({ x: 0, y: 0 });
  const [isArrowHovered, setIsArrowHovered] = useState(false);
  const ctaRef = useRef(null);

  const emailStr = profile.email || "chegoni.gopikrishna@gmail.com";

  const handleCopyEmail = () => {
    if (navigator.clipboard) {
      navigator.clipboard.writeText(emailStr);
      setCopied(true);
      setTimeout(() => setCopied(false), 2000);
    }
  };

  const handleMouseMove = (e) => {
    if (!ctaRef.current) return;
    const rect = ctaRef.current.getBoundingClientRect();
    const centerX = rect.left + rect.width / 2;
    const centerY = rect.top + rect.height / 2;
    const deltaX = (e.clientX - centerX) * 0.035;
    const deltaY = (e.clientY - centerY) * 0.035;
    setArrowPos({ x: deltaX, y: deltaY });
  };

  const handleMouseLeave = () => {
    setArrowPos({ x: 0, y: 0 });
    setIsArrowHovered(false);
  };

  return (
    <section id="about" className="w-full max-w-6xl mx-auto px-6 pt-16 pb-16 space-y-16 border-t border-neutral-200/80">

      {/* 01. Magazine Editorial Spread (No heavy box container) */}
      <ScrollReveal className="space-y-8">
        
        {/* Section Header */}
        <div className="space-y-1.5 border-b border-neutral-200/80 pb-4">
          <div className="text-[11px] font-mono font-bold tracking-widest text-neutral-400 uppercase">
            07 / PERSPECTIVE &amp; BACKGROUND
          </div>
          <h2 className="text-2xl sm:text-4xl font-black text-neutral-900 uppercase tracking-tight">
            Built on Curiosity &amp; Algorithmic Rigor
          </h2>
        </div>

        {/* 2-Column Editorial Flow */}
        <div className="grid grid-cols-1 lg:grid-cols-12 gap-8 lg:gap-14 items-start">
          
          {/* LEFT: Editorial Narrative */}
          <div className="lg:col-span-7 space-y-5">
            <p className="font-serif italic text-lg sm:text-xl text-neutral-900 leading-snug">
              "Passionate about building intelligent systems, machine learning pipelines, and reliable full-stack software."
            </p>

            <p className="font-sans text-sm sm:text-[15px] text-neutral-600 font-normal leading-relaxed">
              {profile.about || "I graduated in Computer Science and Engineering with a specialization in Data Science, achieving an 8.42 CGPA. I am proficient in Python, machine learning, backend engineering, and modern full-stack development. I enjoy solving algorithmic challenges, building reliable software systems, and turning practical ideas into production-ready applications."}
            </p>
          </div>

          {/* RIGHT: Proof, Status & Archive Trigger */}
          <div className="lg:col-span-5 space-y-4">
            
            {/* Live Availability Pill */}
            <div className="bg-white border border-neutral-200/90 rounded-2xl p-4 flex items-center justify-between shadow-2xs">
              <div className="flex items-center gap-2.5">
                <span className="w-2 h-2 rounded-full bg-emerald-500 animate-pulse"></span>
                <span className="font-mono text-xs font-bold text-neutral-900 uppercase">
                  AVAILABLE FOR OPPORTUNITIES
                </span>
              </div>
              <span className="font-mono text-[10px] text-neutral-400 font-semibold uppercase">
                HYDERABAD, IN
              </span>
            </div>

            {/* 3 Minimal Milestone Strips */}
            <div className="space-y-2">
              <div className="bg-white border border-neutral-200/80 rounded-xl px-4 py-3 flex items-center justify-between">
                <div>
                  <div className="font-mono text-[9.5px] font-bold text-neutral-400 uppercase">EDUCATION</div>
                  <div className="font-bold text-xs sm:text-sm text-neutral-900">B.Tech in CS &amp; Data Science</div>
                </div>
                <span className="font-mono text-[11px] text-neutral-500 font-semibold">8.42 CGPA · 2024</span>
              </div>

              <div className="bg-white border border-neutral-200/80 rounded-xl px-4 py-3 flex items-center justify-between">
                <div>
                  <div className="font-mono text-[9.5px] font-bold text-neutral-400 uppercase">ALGORITHMS</div>
                  <div className="font-bold text-xs sm:text-sm text-neutral-900">100+ Problems Solved</div>
                </div>
                <span className="font-mono text-[11px] text-neutral-500 font-semibold">LeetCode &amp; GFG</span>
              </div>

              <div className="bg-white border border-neutral-200/80 rounded-xl px-4 py-3 flex items-center justify-between">
                <div>
                  <div className="font-mono text-[9.5px] font-bold text-neutral-400 uppercase">COMPETITION RANK</div>
                  <div className="font-bold text-xs sm:text-sm text-neutral-900">CodeKaze AIR 992</div>
                </div>
                <span className="font-mono text-[11px] text-emerald-700 font-bold bg-emerald-50 px-2 py-0.5 rounded">Top 0.1%</span>
              </div>
            </div>

            {/* Tactile Archive Trigger */}
            {onOpenArchive && (
              <button
                onClick={onOpenArchive}
                className="w-full bg-[#111111] hover:bg-neutral-800 text-white rounded-2xl p-4 flex items-center justify-between font-mono text-xs font-bold transition-all shadow-xs group cursor-pointer"
              >
                <div className="flex items-center gap-2">
                  <Icon name="Layers" size={14} className="text-emerald-400" />
                  <span>EXPLORE ARCHIVE (18 MOMENTS)</span>
                </div>
                <span className="transition-transform group-hover:translate-x-1">→</span>
              </button>
            )}

          </div>

        </div>
      </ScrollReveal>

      {/* Large Final CTA Canvas */}
      <ScrollReveal>
        <div
          ref={ctaRef}
          onMouseMove={handleMouseMove}
          onMouseLeave={handleMouseLeave}
          className="space-y-8 bg-white border border-neutral-200/90 rounded-3xl p-8 sm:p-12 shadow-sm"
        >
          <div className="flex flex-col md:flex-row md:items-center justify-between gap-6 relative">
            <div className="space-y-3 max-w-2xl">
              <div className="text-xs font-mono font-bold tracking-widest text-neutral-400 uppercase">
                LET'S CONNECT
              </div>
              <h2 className="text-4xl sm:text-6xl font-black text-neutral-900 tracking-tight leading-[1.02] uppercase">
                Let's build something<br />
                worth shipping
              </h2>
            </div>

            <div
              onMouseEnter={() => setIsArrowHovered(true)}
              onMouseLeave={() => setIsArrowHovered(false)}
              onClick={() => window.location.href = `mailto:${emailStr}`}
              style={{
                transform: `translate3d(${arrowPos.x}px, ${arrowPos.y}px, 0)`,
                transition: isArrowHovered ? 'transform 0.1s ease-out, color 0.3s, opacity 0.3s' : 'transform 0.4s ease-out, color 0.3s, opacity 0.3s'
              }}
              className={`select-none cursor-pointer text-7xl sm:text-[140px] font-extralight leading-none tracking-tighter transition-all flex items-center justify-start md:justify-end min-w-[140px] ${
                isArrowHovered ? "text-neutral-900 opacity-90 scale-105" : "text-neutral-300 opacity-40 hover:opacity-70"
              }`}
              title="Send email"
            >
              {isArrowHovered ? "→→" : "→"}
            </div>
          </div>

          {/* Obvious Primary Action & Direct Contact Details */}
          <div className="pt-6 border-t border-neutral-200/80 flex flex-col sm:flex-row sm:items-center justify-between gap-5">
            <div className="flex flex-col sm:flex-row sm:items-center gap-3.5">
              <a
                href={`mailto:${emailStr}`}
                className="inline-flex items-center justify-center gap-1.5 px-4 py-2 sm:px-5 sm:py-2.5 rounded-full bg-neutral-900 text-white font-mono text-[11px] sm:text-xs font-bold hover:bg-neutral-800 hover:scale-[1.02] active:scale-[0.98] transition-all shadow-2xs group cursor-pointer w-fit"
              >
                <span>GET IN TOUCH</span>
                <span className="transition-transform group-hover:translate-x-0.5 group-hover:-translate-y-0.5 text-[10px]">↗</span>
              </a>

              <div className="flex items-center gap-2.5">
                <span className="font-mono text-xs sm:text-[13px] font-medium text-neutral-700">
                  {emailStr}
                </span>
                <button
                  onClick={handleCopyEmail}
                  className="font-mono text-[10px] font-bold text-neutral-400 hover:text-neutral-900 bg-neutral-100 hover:bg-neutral-200/70 px-2 py-0.5 rounded transition-colors uppercase tracking-wider cursor-pointer"
                  title="Copy email address"
                >
                  {copied ? "COPIED!" : "COPY"}
                </button>
              </div>
            </div>

            <div className="font-mono text-[11px] text-neutral-400 font-medium uppercase tracking-wider">
              HYDERABAD, INDIA · AVAILABLE WORLDWIDE
            </div>
          </div>
        </div>
      </ScrollReveal>
    </section>
  );
};

// PERSONAL ARCHIVE MODAL (Exact 24 Moments)
const ArchiveModal = ({ archiveData, onClose }) => {
  const [activeTab, setActiveTab] = useState("ALL");
  const [activeLightboxImage, setActiveLightboxImage] = useState(null);
  const [activeCertificate, setActiveCertificate] = useState(null);

  const archive = archiveData || (window.PORTFOLIO_DATA && window.PORTFOLIO_DATA.archive) || {};
  const hackathons = archive.hackathons || [];
  const graduation = archive.graduation || [];
  const certifications = archive.certifications || [];
  const resume = archive.resume || {};

  useEffect(() => {
    document.body.style.overflow = 'hidden';
    const handleKeyDown = (e) => {
      if (e.key === 'Escape') {
        if (activeCertificate) setActiveCertificate(null);
        else if (activeLightboxImage) setActiveLightboxImage(null);
        else onClose();
      }
    };
    window.addEventListener('keydown', handleKeyDown);
    return () => {
      document.body.style.overflow = '';
      window.removeEventListener('keydown', handleKeyDown);
    };
  }, [activeLightboxImage, activeCertificate, onClose]);

  const scrollToSection = (sectionId) => {
    setActiveTab(sectionId);
    if (sectionId === "ALL") {
      const top = document.getElementById("archive-hero-top");
      if (top) top.scrollIntoView({ behavior: 'smooth' });
    } else {
      const el = document.getElementById(`archive-sec-${sectionId.toLowerCase()}`);
      if (el) el.scrollIntoView({ behavior: 'smooth' });
    }
  };

  return (
    <div className="fixed inset-0 z-50 bg-[#F7F7F5] overflow-y-auto animate-backdrop-fade text-[#111111] selection:bg-[#111111] selection:text-white">
      <div className="sticky top-0 z-40 bg-[#F7F7F5]/90 backdrop-blur-md border-b border-neutral-200/80 px-6 py-4">
        <div className="max-w-6xl mx-auto flex items-center justify-between font-mono text-xs font-semibold">
          <button
            onClick={onClose}
            className="inline-flex items-center gap-2 text-neutral-600 hover:text-neutral-900 transition-colors px-3 py-1.5 rounded-full hover:bg-neutral-200/60 cursor-pointer"
          >
            <Icon name="ArrowLeft" size={16} />
            <span>Back to work</span>
          </button>

          <div className="hidden md:flex items-center gap-2 bg-white border border-neutral-200/90 p-1 rounded-full shadow-2xs">
            {["ALL", "GRADUATION", "CERTIFICATIONS", "HACKATHONS", "RESUME"].map((tab) => (
              <button
                key={tab}
                onClick={() => scrollToSection(tab)}
                className={`px-3 py-1 rounded-full text-[11px] font-bold transition-all cursor-pointer ${
                  activeTab === tab
                    ? "bg-neutral-900 text-white shadow-2xs"
                    : "text-neutral-500 hover:text-neutral-900 hover:bg-neutral-100"
                }`}
              >
                {tab}
              </button>
            ))}
          </div>

          <button
            onClick={onClose}
            className="p-2 text-neutral-500 hover:text-neutral-900 transition-colors rounded-full hover:bg-neutral-200/60 cursor-pointer"
            title="Close Archive (ESC)"
          >
            <Icon name="Close" size={20} />
          </button>
        </div>
      </div>

      <div id="archive-hero-top" className="max-w-6xl mx-auto px-6 py-14 space-y-20">
        <div className="space-y-3 max-w-4xl">
          <div className="font-mono text-xs font-bold text-neutral-400 tracking-widest uppercase flex items-center gap-2">
            <span className="w-2 h-2 rounded-full bg-neutral-900"></span>
            <span>PERSONAL ARCHIVE — 18 MOMENTS</span>
          </div>

          <h1 className="text-3xl sm:text-6xl font-black text-neutral-900 tracking-tight leading-[0.98] uppercase">
            Graduation · Certifications · Hackathons · Milestones
          </h1>

          <p className="text-base sm:text-xl text-neutral-600 font-normal leading-relaxed pt-1">
            Commencement milestones (Class of 2024), 11 verified credentials, 5 hackathon moments, and software engineering curriculum vitae.
          </p>
        </div>

        {/* 01 / GRADUATION */}
        <div id="archive-sec-graduation" className="space-y-6 scroll-mt-24">
          <div className="flex flex-col sm:flex-row sm:items-end justify-between border-b border-neutral-200/80 pb-3 gap-2">
            <div>
              <div className="font-mono text-2xl font-black text-neutral-900">01</div>
              <h2 className="text-2xl sm:text-3xl font-black text-neutral-900 uppercase tracking-tight">GRADUATION</h2>
            </div>
            <p className="text-xs sm:text-sm text-neutral-500 max-w-md font-normal">
              Class of 2024 · B.Tech in Computer Science & Data Science (August 2020 – May 2024).
            </p>
          </div>

          <div className="space-y-6 bg-white border border-neutral-200/80 p-6 sm:p-10 rounded-3xl">
            {graduation.map((grad, i) => (
              <div
                key={grad.id || i}
                onClick={() => setActiveLightboxImage({ src: grad.image, title: grad.title, caption: grad.caption })}
                className="grid grid-cols-1 md:grid-cols-12 gap-6 items-center cursor-pointer group"
              >
                <div className={`md:col-span-7 ${i % 2 === 1 ? 'md:order-2' : ''}`}>
                  <div className="rounded-2xl overflow-hidden border border-neutral-200/80 shadow-md group-hover:shadow-xl transition-all duration-500">
                    <img
                      src={grad.image}
                      alt={grad.title}
                      className="w-full h-auto object-cover max-h-[440px] transition-transform duration-500 group-hover:scale-105"
                    />
                  </div>
                </div>
                <div className={`md:col-span-5 space-y-3 ${i % 2 === 1 ? 'md:order-1' : ''}`}>
                  <div className="font-mono text-xs font-bold text-neutral-400 uppercase tracking-widest">
                    GRADUATION · {grad.year}
                  </div>
                  <h3 className="text-2xl sm:text-3xl font-extrabold text-neutral-900 tracking-tight leading-tight">
                    {grad.title}
                  </h3>
                  <p className="text-sm text-neutral-600 font-normal leading-relaxed">
                    {grad.degree} — {grad.caption}
                  </p>
                  <div className="text-xs font-bold text-neutral-900 flex items-center gap-1 group-hover:translate-x-1 transition-transform">
                    <span>VIEW MOMENT</span>
                    <span>→</span>
                  </div>
                </div>
              </div>
            ))}
          </div>
        </div>

        {/* 02 / CERTIFICATIONS */}
        <div id="archive-sec-certifications" className="space-y-6 pt-6 scroll-mt-24">
          <div className="flex flex-col sm:flex-row sm:items-end justify-between border-b border-neutral-200/80 pb-3 gap-2">
            <div>
              <div className="font-mono text-2xl font-black text-neutral-900">02</div>
              <h2 className="text-2xl sm:text-3xl font-black text-neutral-900 uppercase tracking-tight">CERTIFICATIONS</h2>
            </div>
            <p className="text-xs sm:text-sm text-neutral-500 max-w-md font-normal">
              11 verified credentials with direct PDF records.
            </p>
          </div>

          <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
            {certifications.map((cert) => (
              <div
                key={cert.id}
                onClick={() => setActiveCertificate(cert)}
                className="document-shelf-card p-5 space-y-4 flex flex-col justify-between cursor-pointer group bg-white border border-neutral-200/80 rounded-2xl shadow-2xs hover:shadow-md transition-all"
              >
                <div className="w-full h-44 rounded-xl overflow-hidden bg-neutral-100 border border-neutral-200/80 shadow-2xs relative flex items-center justify-center">
                  <img
                    src={cert.image}
                    alt={cert.title}
                    loading="lazy"
                    className="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"
                  />
                  <div className="absolute top-2.5 right-2.5 bg-neutral-900/90 backdrop-blur-md text-white font-mono text-[9px] font-bold px-2 py-0.5 rounded-md uppercase tracking-wider">
                    {cert.badge}
                  </div>
                </div>

                <div className="space-y-2 flex-1 flex flex-col justify-between">
                  <div>
                    <div className="font-mono text-[10px] font-bold text-neutral-400 uppercase tracking-widest">
                      {cert.type} · {cert.year}
                    </div>
                    <h4 className="text-sm font-bold text-neutral-900 group-hover:text-neutral-700 transition-colors line-clamp-2 mt-0.5">
                      {cert.title}
                    </h4>
                    <p className="text-xs text-neutral-500 mt-1 font-medium">{cert.issuer}</p>
                  </div>

                  <div className="pt-3 border-t border-neutral-100 flex items-center justify-between text-xs font-semibold text-neutral-800">
                    <span className="group-hover:underline">VIEW CERTIFICATE</span>
                    <Icon name="ArrowUpRight" size={14} className="text-neutral-400 group-hover:text-neutral-900 transition-colors" />
                  </div>
                </div>
              </div>
            ))}
          </div>
        </div>

        {/* 03 / HACKATHONS (Moved below Certifications) */}
        <div id="archive-sec-hackathons" className="space-y-6 pt-6 scroll-mt-24">
          <div className="flex flex-col sm:flex-row sm:items-end justify-between border-b border-neutral-200/80 pb-3 gap-2">
            <div>
              <div className="font-mono text-2xl font-black text-neutral-900">03</div>
              <h2 className="text-2xl sm:text-3xl font-black text-neutral-900 uppercase tracking-tight">HACKATHONS</h2>
            </div>
            <p className="text-xs sm:text-sm text-neutral-500 max-w-md font-normal">
              5 curated moments from national coding competitions, team hackathons, and live AI project showcases.
            </p>
          </div>

          <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
            {hackathons.map((item, idx) => (
              <div
                key={item.id || idx}
                onClick={() => setActiveLightboxImage({ src: item.image, title: item.title, caption: item.caption })}
                className="group space-y-2.5 cursor-pointer"
              >
                <div className="w-full rounded-2xl overflow-hidden bg-white border border-neutral-200/80 shadow-xs group-hover:shadow-lg transition-all duration-500 transform group-hover:-translate-y-1">
                  <img
                    src={item.image}
                    alt={item.title}
                    loading="lazy"
                    className="w-full h-auto object-cover max-h-[360px] transition-transform duration-500 group-hover:scale-105"
                  />
                </div>
                <div className="space-y-0.5 px-1">
                  <div className="flex items-center justify-between text-xs font-semibold text-neutral-900 group-hover:text-neutral-600 transition-colors">
                    <span>{item.title}</span>
                    <span className="font-mono text-[11px] text-neutral-400">{item.year}</span>
                  </div>
                  <p className="text-xs text-neutral-500 font-normal leading-relaxed">{item.caption}</p>
                </div>
              </div>
            ))}
          </div>
        </div>

        {/* 04 / RESUME */}
        <div id="archive-sec-resume" className="space-y-6 pt-6 pb-12 scroll-mt-24">
          <div className="flex flex-col sm:flex-row sm:items-end justify-between border-b border-neutral-200/80 pb-3 gap-2">
            <div>
              <div className="font-mono text-2xl font-black text-neutral-900">04</div>
              <h2 className="text-2xl sm:text-3xl font-black text-neutral-900 uppercase tracking-tight">RESUME</h2>
            </div>
            <p className="text-xs sm:text-sm text-neutral-500 max-w-md font-normal">
              Gopikrishna Chegoni — Single page technical curriculum vitae.
            </p>
          </div>

          <div className="bg-white border border-neutral-200/90 rounded-3xl p-6 sm:p-10 shadow-sm max-w-3xl mx-auto space-y-6 text-center">
            <div className="space-y-1.5">
              <div className="font-mono text-xs font-bold text-neutral-400 uppercase tracking-widest">
                VERIFIED DOCUMENT
              </div>
              <h3 className="text-2xl sm:text-3xl font-black text-neutral-900 uppercase tracking-tight">
                GOPIKRISHNA CHEGONI
              </h3>
              <p className="text-xs sm:text-sm text-neutral-600 font-medium">
                AI / Software Engineer · B.Tech CS & Data Science (Class of 2024)
              </p>
            </div>

            <div
              onClick={() => window.open(resume.pdfUrl, '_blank')}
              className="w-full rounded-2xl overflow-hidden border border-neutral-200/80 shadow-md cursor-pointer hover:shadow-xl transition-all duration-500 max-h-[580px] relative group"
            >
              <img
                src={resume.previewImage}
                alt="Gopikrishna Chegoni Resume Preview"
                className="w-full h-auto object-contain mx-auto transition-transform duration-500 group-hover:scale-[1.01]"
              />
              <div className="absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors flex items-center justify-center">
                <span className="opacity-0 group-hover:opacity-100 transition-opacity bg-neutral-900 text-white font-mono text-xs font-bold px-4 py-2 rounded-full shadow-lg">
                  OPEN FULL RESUME PDF ↗
                </span>
              </div>
            </div>

            <div className="pt-2 flex flex-wrap items-center justify-center gap-3">
              <a
                href={resume.pdfUrl}
                target="_blank"
                rel="noopener noreferrer"
                className="inline-flex items-center gap-2 px-7 py-3.5 rounded-full bg-neutral-900 hover:bg-neutral-800 text-white font-bold text-xs uppercase tracking-wider transition-all shadow-md cursor-pointer"
              >
                <span>VIEW FULL RESUME</span>
                <Icon name="ArrowUpRight" size={14} />
              </a>

              <a
                href={resume.pdfUrl}
                download="Gopikrishna_Chegoni_Resume.pdf"
                className="inline-flex items-center gap-2 px-7 py-3.5 rounded-full bg-white border border-neutral-300 hover:border-neutral-900 text-neutral-900 font-bold text-xs uppercase tracking-wider transition-all cursor-pointer"
              >
                <span>DOWNLOAD CV (PDF)</span>
              </a>
            </div>
          </div>
        </div>
      </div>

      {activeCertificate && (
        <div className="fixed inset-0 z-50 bg-black/80 backdrop-blur-md flex items-center justify-center p-4 sm:p-8 animate-backdrop-fade" onClick={() => setActiveCertificate(null)}>
          <div className="bg-white rounded-3xl p-6 max-w-4xl w-full space-y-5 relative border border-neutral-200 shadow-2xl max-h-[90vh] overflow-y-auto" onClick={(e) => e.stopPropagation()}>
            <div className="flex items-center justify-between border-b border-neutral-200 pb-3">
              <div>
                <div className="font-mono text-[10px] font-bold text-neutral-400 uppercase tracking-widest">
                  {activeCertificate.type} · {activeCertificate.year}
                </div>
                <h3 className="text-base sm:text-lg font-bold text-neutral-900">{activeCertificate.title}</h3>
              </div>
              <button onClick={() => setActiveCertificate(null)} className="p-2 rounded-full hover:bg-neutral-100 cursor-pointer">
                <Icon name="Close" size={20} />
              </button>
            </div>

            <div className="rounded-2xl overflow-hidden border border-neutral-200 max-h-[58vh] flex items-center justify-center bg-neutral-100">
              <img src={activeCertificate.image} alt={activeCertificate.title} className="w-full h-auto object-contain max-h-[56vh]" />
            </div>

            <div className="flex items-center justify-between pt-1 text-xs font-semibold">
              <span className="text-neutral-500">Issuer: <strong className="text-neutral-900">{activeCertificate.issuer}</strong></span>
              {activeCertificate.pdf && (
                <a href={activeCertificate.pdf} target="_blank" rel="noopener noreferrer" className="inline-flex items-center gap-1 text-neutral-900 hover:underline">
                  <span>OPEN ORIGINAL PDF</span>
                  <Icon name="ArrowUpRight" size={14} />
                </a>
              )}
            </div>
          </div>
        </div>
      )}

      {activeLightboxImage && (
        <div className="fixed inset-0 z-50 bg-black/90 backdrop-blur-md flex flex-col justify-between p-6 animate-backdrop-fade" onClick={() => setActiveLightboxImage(null)}>
          <div className="flex items-center justify-between text-white max-w-6xl mx-auto w-full pt-2" onClick={(e) => e.stopPropagation()}>
            <div className="font-mono text-xs text-neutral-300 font-bold uppercase">{activeLightboxImage.title}</div>
            <button onClick={() => setActiveLightboxImage(null)} className="p-2 text-white hover:text-neutral-300 cursor-pointer">
              <Icon name="Close" size={24} />
            </button>
          </div>

          <div className="flex-1 flex items-center justify-center my-4" onClick={(e) => e.stopPropagation()}>
            <img src={activeLightboxImage.src} alt={activeLightboxImage.title} className="max-h-[80vh] max-w-full object-contain rounded-2xl border border-white/20 shadow-2xl" />
          </div>

          {activeLightboxImage.caption && (
            <p className="text-center text-xs text-neutral-300 max-w-xl mx-auto pb-2" onClick={(e) => e.stopPropagation()}>
              {activeLightboxImage.caption}
            </p>
          )}
        </div>
      )}
    </div>
  );
};

// EDITORIAL TWO-COLUMN FOOTER (Refined & Understated)
const FooterSection = ({ profile = {} }) => {
  const resumeUrl = profile.resumeUrl || "assets/resume/Gopikrishna_Chegoni_Resume.pdf";
  const githubUrl = profile.githubUrl || "https://github.com/gopikrishna818";
  const linkedinUrl = profile.linkedinUrl || "https://www.linkedin.com/in/gopikrishnachegoni";
  const emailStr = profile.email || "chegoni.gopikrishna@gmail.com";

  const socialLinks = [
    { label: "GitHub", href: githubUrl, icon: "Github", external: true },
    { label: "LinkedIn", href: linkedinUrl, icon: "Linkedin", external: true },
    { label: "Email", href: `mailto:${emailStr}`, icon: "Mail", external: false },
    { label: "Resume", href: resumeUrl, icon: "FileText", external: true },
  ];

  return (
    <footer className="w-full max-w-6xl mx-auto px-6 pt-14 pb-8 sm:pt-16 sm:pb-10 border-t border-neutral-200/80 space-y-8 sm:space-y-10">
      
      {/* 2-Column Editorial Grid: Left Identity, Right Connection Links */}
      <div className="grid grid-cols-1 md:grid-cols-12 gap-6 md:gap-8 items-start">
        
        {/* LEFT COLUMN: Identity & Availability */}
        <div className="md:col-span-7 space-y-2.5">
          <div className="space-y-1">
            <h2 className="text-base sm:text-[17px] font-bold text-neutral-900 uppercase tracking-tight">
              {profile.name || "GOPIKRISHNA CHEGONI"}
            </h2>
            <p className="font-mono text-[10.5px] sm:text-[11px] text-neutral-400 font-normal tracking-wider uppercase">
              AI / SOFTWARE ENGINEER · HYDERABAD, INDIA
            </p>
          </div>

          <div className="pt-1">
            <div className="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full bg-emerald-50 border border-emerald-200/70 text-emerald-800 font-mono text-[10.5px] font-bold">
              <span className="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"></span>
              <span>AVAILABLE FOR OPPORTUNITIES</span>
            </div>
          </div>
        </div>

        {/* RIGHT COLUMN: Let's Connect & Compact Horizontal Icons */}
        <div className="md:col-span-5 space-y-2.5 md:pl-6 lg:pl-12">
          <div className="text-[10.5px] font-mono font-bold text-neutral-400 uppercase tracking-widest border-b border-neutral-100 pb-1.5">
            LET'S CONNECT
          </div>

          {/* 4 Compact Horizontal Icons Side by Side */}
          <div className="flex items-center gap-4 sm:gap-4.5 pt-1">
            {socialLinks.map((item, idx) => (
              <a
                key={idx}
                href={item.href}
                target={item.external ? "_blank" : undefined}
                rel={item.external ? "noopener noreferrer" : undefined}
                aria-label={item.label}
                title={item.label}
                className="text-neutral-500 hover:text-neutral-900 hover:-translate-y-0.5 transition-all duration-200 p-1 -m-1 inline-flex items-center justify-center cursor-pointer"
              >
                <Icon name={item.icon} size={19} />
              </a>
            ))}
          </div>
        </div>

      </div>

      {/* Bottom Editorial Copyright & Metadata Bar with Bespoke Monogram Seal */}
      <div className="pt-6 border-t border-neutral-200/60 flex flex-col sm:flex-row sm:items-center justify-between gap-4 font-mono text-[10.5px] sm:text-[11px] text-neutral-400 tracking-wider uppercase">
        <div className="flex items-center gap-3">
          {/* Bespoke Geometric GK Monogram Seal */}
          <div className="w-7 h-7 rounded-lg border border-neutral-300/80 bg-[#FAF9F6] flex items-center justify-center text-neutral-800 shadow-2xs group cursor-default" title="GK — Gopikrishna Chegoni">
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" className="transition-transform duration-300 group-hover:scale-110">
              <circle cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="1.2" strokeOpacity="0.25" strokeDasharray="2 2" />
              {/* G */}
              <path d="M10 8.5C8.2 8.5 7 9.9 7 12C7 14.1 8.2 15.5 10 15.5C11.5 15.5 12.5 14.5 12.5 13H9.5" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/>
              {/* K */}
              <path d="M15 8.5V15.5M18.5 8.5L15 12L18.5 15.5" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/>
            </svg>
          </div>
          <span>© 2026 GOPIKRISHNA CHEGONI</span>
        </div>

        <div className="flex items-center gap-2.5">
          <span>17.3850° N, 78.4867° E · HYDERABAD, IN</span>
          <span className="hidden sm:inline text-neutral-300">/</span>
          <span className="text-emerald-700 font-bold hidden sm:inline">AVAILABLE FOR ROLES</span>
        </div>
      </div>

    </footer>
  );
};

// Expose Components onto window.PortfolioComponents
window.PortfolioComponents = {
  CustomCursor,
  ScrollProgressBar,
  PosterArtworkMargins,
  CommandPalette,
  AnimatedCounter,
  Navbar,
  HeroSection,
  EngineeringProofStrip,
  ExperienceSection,
  ProjectGallery,
  ToolsIBuildWith,
  AboutSection,
  ArchiveModal,
  FooterSection
};
