"use client";

import { useTranslations, useLocale } from 'next-intl';
import Link from 'next/link';
import { motion, useInView, AnimatePresence } from 'framer-motion';
import { useRef, useEffect, useState } from 'react';
import Image from 'next/image';
import { useModal } from '@/context/ModalContext';
import CharacterAnalysis from './CharacterAnalysis';
import { ChevronDown } from "lucide-react";

// ClientOnly wrapper için helper bileşen
function ClientOnly({ children, fallback = null }: { children: React.ReactNode, fallback?: React.ReactNode }) {
  const [isClient, setIsClient] = useState(false);
  
  useEffect(() => {
    setIsClient(true);
  }, []);
  
  return isClient ? <>{children}</> : <>{fallback}</>;
}

// Animasyon ile beliren yazılar için özel bileşen
const FadeInText = ({
  children,
  delay = 0,
  className = "",
}: {
  children: React.ReactNode;
  delay?: number;
  className?: string;
}) => {
  return (
    <motion.div
      initial={{ opacity: 0, y: 20 }}
      animate={{ opacity: 1, y: 0 }}
      transition={{ duration: 0.5, delay }}
      className={className}
    >
      {children}
    </motion.div>
  );
};

export default function Hero() {
  const t = useTranslations('hero');
  const locale = useLocale();
  const containerRef = useRef<HTMLElement>(null);
  const videoRef = useRef<HTMLVideoElement>(null);
  const isInView = useInView(containerRef, { once: false });
  const [mousePosition, setMousePosition] = useState({ x: 0, y: 0 });
  const [selectedFeature, setSelectedFeature] = useState<string | null>(null);
  const [videoLoaded, setVideoLoaded] = useState(false);
  const [videoError, setVideoError] = useState(false);
  const [isMobile, setIsMobile] = useState(false);
  const [isTablet, setIsTablet] = useState(false);
  const { openModal } = useModal();
  
  // Karakter analizi popup'ını kontrol etmek için state ekliyoruz
  const [showCharacterAnalysis, setShowCharacterAnalysis] = useState(false);
  
  // Link oluşturma helper'ı (mevcut dil için)
  const createLocalizedHref = (path: string) => `/${locale}${path}`;
  
  // Cihaz tipi tespiti
  useEffect(() => {
    const checkScreenSize = () => {
      setIsMobile(window.innerWidth < 768);
      setIsTablet(window.innerWidth >= 768 && window.innerWidth < 1024);
    };
    
    checkScreenSize();
    window.addEventListener('resize', checkScreenSize);
    return () => window.removeEventListener('resize', checkScreenSize);
  }, []);
  
  // Video yükleme kontrolü
  useEffect(() => {
    // Mobil cihazlarda video optimizasyonu
    if (isMobile) {
      // Sadece düşük çözünürlüklü video yükle veya poster göster
      if (videoRef.current) {
        videoRef.current.preload = "metadata"; // Sadece metadata yükle
      }
    } else {
      const videoElement = videoRef.current;
      
      if (videoElement) {
        const handleLoad = () => {
          // Safari için test - bazı cihazlarda loadeddata çalışmayabilir
          if (videoElement.readyState >= 3) {
            setVideoLoaded(true);
          }
        };
        
        const handleError = () => setVideoError(true);
        
        // Yükleme olaylarını dinle
        videoElement.addEventListener('loadeddata', handleLoad);
        videoElement.addEventListener('canplay', handleLoad);
        videoElement.addEventListener('error', handleError);
        
        // Performans için: sadece video görünür olduğunda oynat
        if ('IntersectionObserver' in window) {
          const observer = new IntersectionObserver(
            (entries) => {
              entries.forEach(entry => {
                if (entry.isIntersecting) {
                  if (videoElement.paused) {
                    // Video oynatma hatalarını yakala
                    videoElement.play()
                      .catch(() => {
                        console.warn('Video autoplay failed');
                        setVideoError(true);
                      });
                  }
                } else {
                  if (!videoElement.paused) videoElement.pause();
                }
              });
            },
            { threshold: 0.1 }
          );
          
          observer.observe(videoElement);
          return () => {
            videoElement.removeEventListener('loadeddata', handleLoad);
            videoElement.removeEventListener('canplay', handleLoad);
            videoElement.removeEventListener('error', handleError);
            observer.disconnect();
          };
        }
        
        return () => {
          videoElement.removeEventListener('loadeddata', handleLoad);
          videoElement.removeEventListener('canplay', handleLoad);
          videoElement.removeEventListener('error', handleError);
        };
      }
    }
  }, [isMobile]);
  
  // Yükleme durumunda videonun manual olarak oynatılması için
  useEffect(() => {
    if (!isMobile && videoRef.current) {
      const videoElement = videoRef.current;
      
      // Sayfa görünür olduğunda videoyu oynatmaya çalış
      if (document.visibilityState === 'visible') {
        videoElement.play().catch(() => {
          console.warn('Video autoplay failed on page load');
          setVideoError(true);
        });
      }
      
      // Sayfa görünürlüğü değiştiğinde video durumunu güncelle
      const handleVisibilityChange = () => {
        if (document.visibilityState === 'visible') {
          videoElement.play().catch(() => {});
        } else {
          videoElement.pause();
        }
      };
      
      document.addEventListener('visibilitychange', handleVisibilityChange);
      return () => {
        document.removeEventListener('visibilitychange', handleVisibilityChange);
      };
    }
  }, [isMobile]);

  // Mouse pozisyonunu izleme
  useEffect(() => {
    const handleMouseMove = (e: MouseEvent) => {
      setMousePosition({
        x: e.clientX,
        y: e.clientY
      });
    };
    
    window.addEventListener('mousemove', handleMouseMove);
    
    return () => {
      window.removeEventListener('mousemove', handleMouseMove);
    };
  }, []);
  
  // Popup'ı kapatmak için dışa tıklama
  useEffect(() => {
    if (selectedFeature) {
      const handleClickOutside = (event: MouseEvent | TouchEvent) => {
        // Tıklama veya dokunmanın popup dışında ve özellik kartı dışında olup olmadığını kontrol et
        const target = event.target as Element;
        if (!target.closest('.feature-popup') && !target.closest('.feature-card')) {
          setSelectedFeature(null);
        }
      };
      
      // Hem tıklama hem de dokunma olayları için dinleyiciler ekle
      document.addEventListener('mousedown', handleClickOutside);
      document.addEventListener('touchstart', handleClickOutside);
      
      return () => {
        document.removeEventListener('mousedown', handleClickOutside);
        document.removeEventListener('touchstart', handleClickOutside);
      };
    }
  }, [selectedFeature]);
  
  // Öne çıkan özelliklerin listesi
  const features = [
    { id: 'innovation', icon: '/icons/innovation.svg', label: locale === 'tr' ? 'İnovasyon' : 'Innovation' },
    { id: 'mentor', icon: '/icons/mentor.svg', label: locale === 'tr' ? 'Mentorluk' : 'Mentorship' },
    { id: 'investment', icon: '/icons/investment.svg', label: locale === 'tr' ? 'Yatırım' : 'Investment' },
    { id: 'global', icon: '/icons/global.svg', label: locale === 'tr' ? 'Global Erişim' : 'Global Access' },
  ];
  
  // Animasyon varyantları
  const titleVariants = {
    hidden: { opacity: 0, y: 20 },
    visible: {
      opacity: 1,
      y: 0,
      transition: {
        duration: 0.8,
        ease: [0.22, 1, 0.36, 1]
      }
    }
  };
  
  const subtitleVariants = {
    hidden: { opacity: 0, y: 20 },
    visible: {
      opacity: 1,
      y: 0,
      transition: {
        duration: 0.8,
        delay: 0.2,
        ease: [0.22, 1, 0.36, 1]
      }
    }
  };
  
  const buttonVariants = {
    hidden: { opacity: 0, y: 20 },
    visible: {
      opacity: 1,
      y: 0,
      transition: {
        duration: 0.6,
        delay: 0.4
      }
    },
    hover: {
      scale: 1.05,
      boxShadow: "0 10px 25px -5px rgba(59, 130, 246, 0.5)",
      transition: {
        duration: 0.2
      }
    },
    tap: {
      scale: 0.98
    }
  };
  
  const containerVariants = {
    hidden: { opacity: 0 },
    visible: {
      opacity: 1,
      transition: {
        staggerChildren: 0.1
      }
    }
  };
  
  const itemVariants = {
    hidden: { opacity: 0, y: 20 },
    visible: (index: number) => ({
      opacity: 1,
      y: 0,
      transition: {
        duration: 0.6,
        delay: 0.2 + (index * 0.1)
      }
    })
  };
  
  const popupVariants = {
    hidden: { opacity: 0, scale: 0.8, y: 10 },
    visible: { 
      opacity: 1, 
      scale: 1, 
      y: 0,
      transition: {
        type: "spring",
        damping: 20,
        stiffness: 300
      }
    },
    exit: { 
      opacity: 0, 
      scale: 0.8, 
      y: 10,
      transition: {
        duration: 0.2
      }
    }
  };
  
  const calculateParallaxValue = (factor: number) => {
    const x = (mousePosition.x / window.innerWidth - 0.5) * factor;
    const y = (mousePosition.y / window.innerHeight - 0.5) * factor;
    return { x, y };
  };

  // Popup içeriğini alır
  const getFeatureDescription = (featureId: string) => {
    if (t(`featureDescriptions.${featureId}`, { defaultValue: '' })) {
      return t(`featureDescriptions.${featureId}`);
    }
    return locale === 'tr' ? 
      'Bu özellik hakkında daha fazla bilgi yakında eklenecektir.' : 
      'More information about this feature will be added soon.';
  };

  // Aşağı kaydırmak için başvuru
  const aboutRef = useRef<HTMLDivElement>(null);

  // Aşağı kaydırma işlevi
  const scrollToAbout = () => {
    aboutRef.current?.scrollIntoView({ behavior: "smooth" });
  };

  return (
    <section className="relative min-h-screen flex items-center overflow-hidden" ref={containerRef} id="hero">
      {/* Video Arka Plan */}
      <div className="video-container absolute inset-0 z-0">
        {!videoError && (
          <>
            <video
              ref={videoRef}
              autoPlay
              loop
              muted
              playsInline
              preload={isMobile ? "metadata" : "auto"}
              className={`absolute min-w-full min-h-full object-cover w-auto h-auto top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 ${videoLoaded ? 'opacity-85' : 'opacity-0'} transition-opacity duration-2000 filter blur-[2.5px]`}
              poster="/herovideo/poster.jpg"
            >
              <source src="/herovideo/video.mp4" type="video/mp4" />
            </video>
            
            {/* Video üzerine ek görsel efekt katmanı */}
            <div className={`absolute inset-0 bg-gradient-to-t from-slate-900/60 via-slate-900/20 to-transparent mix-blend-overlay ${videoLoaded ? 'opacity-100' : 'opacity-0'} transition-opacity duration-2000`}></div>
            <div className={`absolute inset-0 bg-blue-600/10 mix-blend-color-dodge ${videoLoaded ? 'opacity-50' : 'opacity-0'} transition-opacity duration-2000`}></div>
            <div className={`absolute inset-0 bg-gradient-to-br from-transparent via-indigo-600/5 to-transparent mix-blend-screen ${videoLoaded ? 'opacity-70' : 'opacity-0'} transition-opacity duration-2000`}></div>
          </>
        )}
        
        {/* Yedek arka plan (Video yüklenemediğinde veya mobil cihazda video yüklenmediğinde) */}
        <motion.div
          className={`absolute inset-0 animate-gradient bg-gradient-to-br from-slate-900 via-blue-950 to-indigo-950 ${videoLoaded ? 'opacity-0' : 'opacity-100'} transition-opacity duration-2000`}
          initial={{ opacity: 1 }}
          animate={{ opacity: videoLoaded ? 0 : 1 }}
          transition={{ duration: 1.8 }}
        />
      </div>
      
      {/* Arka plan overlay - Modernize edildi */}
      <div className="absolute inset-0 z-0">
        {/* Arka plan gradyantı - Overlay ve blur iyileştirildi */}
        <div className="absolute inset-0 bg-gradient-to-b from-slate-900/65 via-blue-950/55 to-indigo-950/65 backdrop-blur-[5px]"></div>
        
        {/* Arka plan daireleri */}
        <motion.div 
          className="absolute top-[-10%] right-[-5%] w-[50vw] h-[50vw] rounded-full bg-blue-600/10 blur-3xl"
          animate={{
            y: [0, -20, 0],
            x: [0, 20, 0],
            scale: [1, 1.1, 1]
          }}
          transition={{
            duration: 15,
            repeat: Infinity,
            repeatType: "reverse",
            type: "tween"
          }}
        />
        
        <motion.div 
          className="absolute bottom-[-10%] left-[-5%] w-[40vw] h-[40vw] rounded-full bg-indigo-600/10 blur-3xl"
          animate={{
            y: [0, 20, 0],
            x: [0, -20, 0],
            scale: [1, 1.2, 1]
          }}
          transition={{
            duration: 18,
            repeat: Infinity,
            repeatType: "reverse",
            delay: 2,
            type: "tween"
          }}
        />
        
        {/* Işık parıltıları */}
        <div className="absolute top-0 left-0 w-full h-full overflow-hidden opacity-30 mix-blend-screen">
          <div className="absolute top-1/4 left-1/4 w-1 h-1 bg-white rounded-full glow-small"></div>
          <div className="absolute top-3/4 left-2/3 w-2 h-2 bg-white rounded-full glow-medium"></div>
          <div className="absolute top-1/3 left-3/4 w-1 h-1 bg-white rounded-full glow-small"></div>
          <div className="absolute top-2/3 left-1/5 w-1 h-1 bg-white rounded-full glow-small"></div>
          <div className="absolute top-1/2 left-1/2 w-3 h-3 bg-white rounded-full glow-large"></div>
        </div>
        
        {/* 3D ızgara */}
        <div className="absolute inset-0 flex items-center justify-center opacity-10">
          <div className="w-full h-[1px] bg-gradient-to-r from-transparent via-blue-400 to-transparent"></div>
          <div className="w-full h-[1px] bg-gradient-to-r from-transparent via-blue-400 to-transparent absolute top-1/4"></div>
          <div className="w-full h-[1px] bg-gradient-to-r from-transparent via-blue-400 to-transparent absolute top-2/4"></div>
          <div className="w-full h-[1px] bg-gradient-to-r from-transparent via-blue-400 to-transparent absolute top-3/4"></div>
          
          <div className="h-full w-[1px] bg-gradient-to-b from-transparent via-blue-400 to-transparent"></div>
          <div className="h-full w-[1px] bg-gradient-to-b from-transparent via-blue-400 to-transparent absolute left-1/4"></div>
          <div className="h-full w-[1px] bg-gradient-to-b from-transparent via-blue-400 to-transparent absolute left-2/4"></div>
          <div className="h-full w-[1px] bg-gradient-to-b from-transparent via-blue-400 to-transparent absolute left-3/4"></div>
        </div>
        
        {/* Gezinen ışık noktaları - ClientOnly içine alındı */}
        <ClientOnly>
          {Array.from({ length: 40 }).map((_, i) => (
            <motion.div
              key={`particle-${i}`}
              className="absolute w-1 h-1 bg-white rounded-full shadow-glow"
              initial={{
                x: Math.random() * 600 - 300,
                y: Math.random() * 600 - 300,
                opacity: 0
              }}
              animate={{
                x: Math.random() * 600 - 300,
                y: Math.random() * 600 - 300,
                opacity: [0, 0.7, 0]
              }}
              transition={{
                duration: 8 + Math.random() * 10,
                repeat: Infinity,
                delay: i * 0.2
              }}
            />
          ))}
        </ClientOnly>
      </div>

      <div className="container mx-auto px-4 sm:px-6 lg:px-8 py-24 relative z-10">
        <div className="grid grid-cols-1 lg:grid-cols-12 gap-8 md:gap-12 items-center">
          {/* Sol içerik alanı: Başlık ve Alt Başlık */}
          <div className="lg:col-span-5 flex flex-col items-center lg:items-start text-center lg:text-left">
            <FadeInText delay={0.2} className="overflow-hidden">
              <motion.h1
                className="text-3xl sm:text-4xl md:text-5xl lg:text-6xl font-bold leading-tight mb-4 bg-clip-text text-transparent bg-gradient-to-r from-white to-blue-200"
                variants={titleVariants}
                initial="hidden"
                animate={isInView ? "visible" : "hidden"}
              >
                {t('title')}
              </motion.h1>
            </FadeInText>
            
            <FadeInText delay={0.4} className="mt-6">
              <motion.p
                className="text-lg sm:text-xl md:text-2xl text-blue-200/90 mb-4 sm:mb-6 font-light"
                variants={subtitleVariants}
                initial="hidden"
                animate={isInView ? "visible" : "hidden"}
              >
                {t('subtitle')}
              </motion.p>
            </FadeInText>
            
            <FadeInText delay={0.6} className="text-sm sm:text-base md:text-lg text-blue-100/80 mb-6 sm:mb-10">
              <motion.p
                variants={subtitleVariants}
                initial="hidden"
                animate={isInView ? "visible" : "hidden"}
                transition={{ delay: 0.3 }}
              >
                {t('description')}
              </motion.p>
            </FadeInText>
            
            <FadeInText delay={0.8} className="mt-10">
              <div className="flex flex-col sm:flex-row gap-4 w-full sm:w-auto">
                <a 
                  href="https://gm2.ifollow.com.tr/register" 
                  target="_blank" 
                  rel="noopener noreferrer"
                  className="w-full sm:w-auto"
                >
                  <motion.button
                    className="w-full py-3 sm:py-4 px-6 sm:px-8 rounded-full bg-gradient-to-r from-blue-600 to-indigo-600 text-white font-medium shadow-blue-500/20 shadow-xl backdrop-blur-sm border border-white/10 flex items-center justify-center"
                    variants={buttonVariants}
                    initial="hidden"
                    animate={isInView ? "visible" : "hidden"}
                    whileHover="hover"
                    whileTap="tap"
                  >
                    <span>{t('applyButton')}</span>
                    <svg className="w-4 h-4 sm:w-5 sm:h-5 ml-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                      <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M17 8l4 4m0 0l-4 4m4-4H3"></path>
                    </svg>
                  </motion.button>
                </a>
                
                <motion.button
                  className="w-full py-3 sm:py-4 px-6 sm:px-8 rounded-full bg-white/5 backdrop-blur-md text-white border border-white/10 font-medium hover:bg-white/10 transition-colors flex items-center justify-center"
                  variants={buttonVariants}
                  initial="hidden"
                  animate={isInView ? "visible" : "hidden"}
                  whileHover={{ scale: 1.05 }}
                  whileTap={{ scale: 0.98 }}
                  onClick={() => setShowCharacterAnalysis(true)}
                >
                  <span>{locale === 'tr' ? 'Karakter Analizi Yap' : 'Take Character Analysis'}</span>
                  <ChevronDown size={18} className="ml-2" />
                </motion.button>
              </div>
            </FadeInText>
            
            {/* Mobil için Özellik Kartları */}
            {isMobile && (
              <motion.div 
                className="grid grid-cols-2 gap-4 mt-12 w-full"
                variants={containerVariants}
                initial="hidden"
                animate="visible"
              >
                {features.map((feature, index) => (
                  <motion.div
                    key={feature.id}
                    className="feature-card backdrop-blur-lg bg-white/10 rounded-xl p-3 border border-white/20 shadow-xl flex flex-col items-center text-center active:bg-white/20 transition-colors"
                    variants={itemVariants}
                    initial={{ opacity: 0, y: 20 }}
                    animate={{ opacity: 1, y: 0 }}
                    transition={{ 
                      delay: 0.2 * index,
                      duration: 0.5
                    }}
                    onClick={() => setSelectedFeature(feature.id)}
                    onTouchStart={() => {}} // Boş dokunma işleyicisi ekleyerek iOS'ta tıklama olayı sorununu düzeltir
                  >
                    <div className="w-12 h-12 flex items-center justify-center bg-gradient-to-br from-blue-500 to-indigo-600 rounded-full mb-2">
                      <img src={feature.icon} alt={feature.label} className="w-6 h-6" />
                    </div>
                    <span className="text-sm text-white font-medium">{feature.label}</span>
                  </motion.div>
                ))}
              </motion.div>
            )}
          </div>
          
          {/* Sağ içerik alanı: Özellik Kartları (Sadece masaüstünde) */}
          <div className="lg:col-span-7 relative hidden sm:block">
            <motion.div 
              className="relative h-[300px] md:h-[400px] lg:h-[500px]"
              style={{ 
                transformStyle: 'preserve-3d',
                transform: `rotateX(${-mousePosition.y / 100}deg) rotateY(${mousePosition.x / 100}deg)`
              }}
            >
              {/* Yörüngeler - Parlak çemberler */}
              <div className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2">
                <motion.div 
                  className="w-[300px] md:w-[360px] lg:w-[440px] h-[300px] md:h-[360px] lg:h-[440px] border border-blue-500/20 rounded-full absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
                  animate={{ rotate: 360 }}
                  transition={{ duration: 60, repeat: Infinity, ease: "linear" }}
                />
                
                <motion.div 
                  className="w-[240px] md:w-[300px] lg:w-[360px] h-[240px] md:h-[300px] lg:h-[360px] border border-indigo-500/20 rounded-full absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
                  animate={{ rotate: -360 }}
                  transition={{ duration: 45, repeat: Infinity, ease: "linear" }}
                />
                
                <motion.div 
                  className="w-[180px] md:w-[240px] lg:w-[280px] h-[180px] md:h-[240px] lg:h-[280px] border border-purple-500/20 rounded-full absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
                  animate={{ rotate: 360 }}
                  transition={{ duration: 30, repeat: Infinity, ease: "linear" }}
                />
              </div>
              
              {/* Özellik kartları - Yeniden düzenlenmiş */}
              {features.map((feature, index) => {
                const angles = [45, 135, 225, 315]; // Kartların açıları (sağ üst, sol üst, sol alt, sağ alt)
                const angle = angles[index] * (Math.PI / 180);
                const radius = 140; // Tablet için daha küçük radius
                const radiusMd = 160; // Medium ekranlar için orta radius
                const radiusLg = 180; // Large ekranlar için daha büyük radius
                
                // Responsive radius hesaplama - window.innerWidth'i doğrudan kullanmıyoruz
                // Bunun yerine isMobile state'ini kullanıyoruz
                const finalRadius = isMobile ? radius : 
                                   isTablet ? radiusMd : radiusLg;
                                   
                const x = Math.cos(angle) * finalRadius;
                const y = Math.sin(angle) * finalRadius;
                
                return (
                  <motion.div
                    key={feature.id}
                    className={`feature-card absolute w-36 md:w-40 lg:w-48 backdrop-blur-lg bg-white/10 rounded-xl p-3 md:p-4 lg:p-5 border border-white/20 shadow-xl flex flex-col items-center text-center cursor-pointer ${selectedFeature === feature.id ? 'ring-2 ring-blue-500' : ''}`}
                    style={{ 
                      left: `calc(50% + ${x}px)`, 
                      top: `calc(50% + ${y}px)`, 
                      transform: 'translate(-50%, -50%)',
                    }}
                    initial={{ opacity: 0, scale: 0.5 }}
                    animate={isInView ? { 
                      opacity: 1, 
                      scale: 1,
                      transition: { delay: 0.3 + (index * 0.2), duration: 0.5 } 
                    } : { opacity: 0, scale: 0.5 }}
                    whileHover={{ 
                      scale: 1.1, 
                      boxShadow: "0 0 20px 5px rgba(59, 130, 246, 0.3)",
                      transition: { duration: 0.2 }
                    }}
                    onClick={() => setSelectedFeature(feature.id)}
                  >
                    <div className="w-12 md:w-14 lg:w-16 h-12 md:h-14 lg:h-16 flex items-center justify-center bg-gradient-to-br from-blue-500 to-indigo-600 rounded-full mb-2 md:mb-3 lg:mb-4">
                      <img src={feature.icon} alt={feature.label} className="w-6 md:w-7 lg:w-8 h-6 md:h-7 lg:h-8" />
                    </div>
                    <span className="text-sm md:text-base lg:text-lg text-white font-medium">{feature.label}</span>
                  </motion.div>
                );
              })}
              
              {/* Özellik Açıklama Popup'ları - Ortada daha okunaklı */}
              <AnimatePresence>
                {selectedFeature && (
                  <motion.div
                    className="feature-popup absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-30 w-[90%] max-w-md bg-gradient-to-br from-slate-800/95 to-slate-900/95 backdrop-blur-xl p-6 sm:p-8 rounded-xl border border-white/10 shadow-2xl"
                    variants={popupVariants}
                    initial="hidden"
                    animate="visible"
                    exit="exit"
                  >
                    <div className="flex items-start justify-between mb-6">
                      <div className="flex items-center">
                        <div className="w-10 sm:w-12 h-10 sm:h-12 flex items-center justify-center bg-gradient-to-br from-blue-500 to-indigo-600 rounded-full mr-3 sm:mr-4">
                          <img 
                            src={features.find(f => f.id === selectedFeature)?.icon || '/icons/innovation.svg'} 
                            alt={features.find(f => f.id === selectedFeature)?.label || 'Feature'} 
                            className="w-5 sm:w-6 h-5 sm:h-6" 
                          />
                        </div>
                        <h3 className="text-lg sm:text-xl font-semibold text-white">
                          {features.find(f => f.id === selectedFeature)?.label || 'Feature'}
                        </h3>
                      </div>
                      <button 
                        onClick={() => setSelectedFeature(null)}
                        className="text-white/60 hover:text-white transition-colors p-2 -mr-2 -mt-2"
                        aria-label={locale === 'tr' ? 'Kapat' : 'Close'}
                      >
                        <svg className="w-5 sm:w-6 h-5 sm:h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                          <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M6 18L18 6M6 6l12 12" />
                        </svg>
                      </button>
                    </div>
                    
                    <p className="text-base sm:text-lg text-blue-100/90 mb-6 leading-relaxed">
                      {getFeatureDescription(selectedFeature)}
                    </p>
                    
                    <div className="flex justify-end">
                      <motion.button
                        className="px-4 sm:px-6 py-2 sm:py-3 rounded-full bg-gradient-to-r from-blue-600 to-indigo-600 text-white text-sm sm:text-base font-medium"
                        whileHover={{ scale: 1.05 }}
                        whileTap={{ scale: 0.95 }}
                        onClick={() => setSelectedFeature(null)}
                      >
                        {locale === 'tr' ? 'Kapat' : 'Close'}
                      </motion.button>
                    </div>
                    
                    {/* Dekoratif daire arka planda */}
                    <div className="absolute -top-16 -right-16 w-64 h-64 bg-blue-500/10 rounded-full blur-3xl -z-10"></div>
                    <div className="absolute -bottom-16 -left-16 w-64 h-64 bg-indigo-500/10 rounded-full blur-3xl -z-10"></div>
                  </motion.div>
                )}
              </AnimatePresence>
            </motion.div>
          </div>
        </div>
      </div>
      
      {/* Dalga efekti alt kısım - Sayfa ilerisine uyumlu yeni tasarım */}
      <div className="absolute -bottom-1 left-0 right-0 z-10">
        <svg className="w-full h-24" preserveAspectRatio="none" viewBox="0 0 1440 74" fill="none" xmlns="http://www.w3.org/2000/svg">
          <path d="M0,24 C240,59 480,74 720,64 C960,54 1200,19 1440,24 L1440,74 L0,74 Z" fill="#0f172a" />
        </svg>
      </div>
      
      {/* Karakter Analizi popupı gösterilir */}
      {showCharacterAnalysis && (
        <CharacterAnalysis 
          manualShow={showCharacterAnalysis} 
          onClose={() => setShowCharacterAnalysis(false)}
        />
      )}
      
      {/* Stil */}
      <style jsx global>{`
        .video-container {
          width: 100%;
          height: 100%;
          overflow: hidden;
        }
        
        @media (max-aspect-ratio: 16/9) {
          .video-container video {
            height: 100%;
            width: auto;
          }
        }
        
        @media (min-aspect-ratio: 16/9) {
          .video-container video {
            width: 100%;
            height: auto;
          }
        }
        
        /* Mobil cihaz optimizasyonu - video gizleme kaldırıldı */
        @media (max-width: 768px) {
          .video-container video {
            /* Artık mobilde de video gösteriliyor */
            filter: blur(4px); /* Mobilde daha fazla blur yaparak performans artırma */
          }
          
          .feature-popup {
            width: 90vw;
            max-height: 80vh;
            overflow-y: auto;
            transform: translate(-50%, -50%) !important;
            top: 50% !important;
            left: 50% !important;
            position: fixed;
            z-index: 50;
          }
          
          /* Mobil cihazlarda dokunma olayları için iyileştirme */
          .feature-card {
            cursor: pointer;
            -webkit-tap-highlight-color: transparent; /* iOS'ta dokunma vurgusunu kaldır */
            touch-action: manipulation; /* Tarayıcı varsayılan dokunma olaylarını iyileştir */
          }
          
          /* Popup içindeki kapatma düğmesi daha büyük olsun */
          .feature-popup button[aria-label="Kapat"],
          .feature-popup button[aria-label="Close"] {
            padding: 8px;
            margin: -8px;
          }
        }
        
        /* Animasyonlu gradyan arka plan */
        .animate-gradient {
          background-size: 400%;
          animation: gradient 15s ease infinite;
          animation-direction: alternate;
        }
        
        @keyframes gradient {
          0% {
            background-position: 0% 50%;
          }
          50% {
            background-position: 100% 50%;
          }
          100% {
            background-position: 0% 50%;
          }
        }
        
        .glow-small {
          animation: glow1 4s infinite alternate;
        }
        .glow-medium {
          animation: glow2 6s infinite alternate;
        }
        .glow-large {
          animation: glow3 8s infinite alternate;
        }
        
        .shadow-glow {
          box-shadow: 0 0 10px 2px rgba(255, 255, 255, 0.4);
        }
        
        @keyframes glow1 {
          0%, 100% { box-shadow: 0 0 5px 1px rgba(255, 255, 255, 0.3); }
          50% { box-shadow: 0 0 20px 5px rgba(255, 255, 255, 0.6); }
        }
        
        @keyframes glow2 {
          0%, 100% { box-shadow: 0 0 10px 2px rgba(255, 255, 255, 0.3); }
          50% { box-shadow: 0 0 30px 10px rgba(255, 255, 255, 0.5); }
        }
        
        @keyframes glow3 {
          0%, 100% { box-shadow: 0 0 15px 3px rgba(255, 255, 255, 0.3); }
          50% { box-shadow: 0 0 40px 15px rgba(255, 255, 255, 0.5); }
        }
        
        /* Video için performans önbelleği */
        video {
          will-change: transform;
          transform: translateZ(0);
          backface-visibility: hidden;
          filter: contrast(1.08) saturate(1.15) brightness(1.05);
        }
      `}</style>
    </section>
  );
} 