// Full-bleed animated hero background — rich, layered substrate visualization.
// Five depth planes, dense wireframe grids, scanning beams, flowing data,
// atmospheric depth cues. Pure SVG/CSS.

const HeroBackground = () => (
  <div style={{
    position:'absolute', inset:0, overflow:'hidden',
    background:'radial-gradient(ellipse 130% 90% at 50% 25%, #0B1638 0%, #050B22 45%, #02050F 100%)',
    pointerEvents:'none',
  }}>
    {/* Deep space base — subtle nebula glow */}
    <div style={{
      position:'absolute', top:'-30%', left:'15%', width:1200, height:1000,
      background:'radial-gradient(ellipse, rgba(59,130,246,0.22) 0%, transparent 60%)',
      filter:'blur(100px)', animation:'heroAurora1 20s ease-in-out infinite',
    }}/>
    <div style={{
      position:'absolute', bottom:'-30%', right:'-15%', width:1100, height:1100,
      background:'radial-gradient(ellipse, rgba(30,64,175,0.45) 0%, transparent 65%)',
      filter:'blur(120px)', animation:'heroAurora2 24s ease-in-out infinite',
    }}/>
    <div style={{
      position:'absolute', top:'40%', left:'-10%', width:700, height:700,
      background:'radial-gradient(circle, rgba(147,197,253,0.15) 0%, transparent 60%)',
      filter:'blur(80px)', animation:'heroAurora1 16s ease-in-out infinite reverse',
    }}/>

    {/* Starfield — multi-layer with twinkle */}
    <div style={{
      position:'absolute', inset:0,
      backgroundImage:[
        'radial-gradient(circle at 12% 18%, rgba(255,255,255,0.55) 0.5px, transparent 1px)',
        'radial-gradient(circle at 78% 28%, rgba(255,255,255,0.4) 0.5px, transparent 1px)',
        'radial-gradient(circle at 34% 72%, rgba(147,197,253,0.6) 0.8px, transparent 1.4px)',
        'radial-gradient(circle at 88% 12%, rgba(255,255,255,0.45) 0.5px, transparent 1px)',
        'radial-gradient(circle at 8% 55%, rgba(147,197,253,0.5) 0.6px, transparent 1.2px)',
        'radial-gradient(circle at 58% 45%, rgba(255,255,255,0.3) 0.4px, transparent 0.8px)',
        'radial-gradient(circle at 22% 85%, rgba(147,197,253,0.4) 0.5px, transparent 1px)',
      ].join(', '),
      backgroundSize:'280px 280px, 340px 340px, 420px 420px, 360px 360px, 300px 300px, 240px 240px, 380px 380px',
      opacity:0.9,
    }}/>

    {/* Main wireframe substrate */}
    <svg viewBox="0 0 1600 900" preserveAspectRatio="xMidYMid slice"
         style={{position:'absolute', inset:0, width:'100%', height:'100%'}}>
      <defs>
        <linearGradient id="planeFadeDeep" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0" stopColor="#60A5FA" stopOpacity="0"/>
          <stop offset="0.5" stopColor="#60A5FA" stopOpacity="0.35"/>
          <stop offset="1" stopColor="#60A5FA" stopOpacity="0.1"/>
        </linearGradient>
        <linearGradient id="planeFadeMid" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0" stopColor="#93C5FD" stopOpacity="0"/>
          <stop offset="0.5" stopColor="#93C5FD" stopOpacity="0.45"/>
          <stop offset="1" stopColor="#93C5FD" stopOpacity="0.12"/>
        </linearGradient>
        <linearGradient id="planeFadeNear" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0" stopColor="#BFDBFE" stopOpacity="0.05"/>
          <stop offset="0.5" stopColor="#BFDBFE" stopOpacity="0.55"/>
          <stop offset="1" stopColor="#BFDBFE" stopOpacity="0.2"/>
        </linearGradient>
        <linearGradient id="horizonGlow" x1="0" y1="0" x2="1" y2="0">
          <stop offset="0" stopColor="#3B82F6" stopOpacity="0"/>
          <stop offset="0.5" stopColor="#93C5FD" stopOpacity="1"/>
          <stop offset="1" stopColor="#3B82F6" stopOpacity="0"/>
        </linearGradient>
        <linearGradient id="scanBeam" x1="0" y1="0" x2="1" y2="0">
          <stop offset="0" stopColor="#60A5FA" stopOpacity="0"/>
          <stop offset="0.5" stopColor="#93C5FD" stopOpacity="0.7"/>
          <stop offset="1" stopColor="#60A5FA" stopOpacity="0"/>
        </linearGradient>
        <radialGradient id="nodePulse">
          <stop offset="0" stopColor="#93C5FD" stopOpacity="1"/>
          <stop offset="1" stopColor="#93C5FD" stopOpacity="0"/>
        </radialGradient>
        <filter id="heroGlow"><feGaussianBlur stdDeviation="3"/></filter>
        <filter id="heroSoftGlow"><feGaussianBlur stdDeviation="6"/></filter>
      </defs>

      {/* Vertical atmospheric depth lines — subtle vertical beams */}
      <g opacity="0.3">
        {Array.from({length:20}).map((_,i)=>(
          <line key={i} x1={80*i} y1="0" x2={80*i} y2="900"
                stroke="#3B82F6" strokeWidth="0.3" strokeOpacity={0.15 + (i%3)*0.08}/>
        ))}
      </g>

      {/* DEEPEST PLANE — tiny, far on horizon */}
      <g transform="translate(800 260)" opacity="0.35">
        <g stroke="url(#planeFadeDeep)" strokeWidth="0.5" fill="none">
          {Array.from({length:7}).map((_,i)=>{
            const t = i/6;
            const y = -20 + t*40;
            const halfW = 140 + t*40;
            return <line key={i} x1={-halfW} y1={y} x2={halfW} y2={y}/>;
          })}
          {Array.from({length:9}).map((_,i)=>{
            const t = (i-4)/4;
            return <line key={i} x1={t*140} y1={-20} x2={t*180} y2={20}/>;
          })}
        </g>
      </g>

      {/* FAR PLANE — Agency Web */}
      <g transform="translate(800 340)" opacity="0.6">
        <g stroke="url(#planeFadeDeep)" strokeWidth="0.7" fill="none">
          {Array.from({length:11}).map((_,i)=>{
            const t = i/10;
            const y = -40 + t*80;
            const halfW = 240 + t*70;
            return <line key={i} x1={-halfW} y1={y} x2={halfW} y2={y}/>;
          })}
          {Array.from({length:13}).map((_,i)=>{
            const t = (i-6)/6;
            return <line key={i} x1={t*240} y1={-40} x2={t*310} y2={40}/>;
          })}
        </g>
        <text x="310" y="-50" fontFamily="var(--font-mono)" fontSize="9" fill="#60A5FA" letterSpacing="2" opacity="0.35">AGENCY_WEB · 219K PAGES</text>
        <line x1="250" y1="-45" x2="305" y2="-45" stroke="#60A5FA" strokeWidth="0.5" opacity="0.35"/>
      </g>

      {/* MID PLANE — SAM.gov */}
      <g transform="translate(800 490)" opacity="0.75">
        <g stroke="url(#planeFadeMid)" strokeWidth="0.85" fill="none">
          {Array.from({length:13}).map((_,i)=>{
            const t = i/12;
            const y = -70 + t*140;
            const halfW = 380 + t*120;
            return <line key={i} x1={-halfW} y1={y} x2={halfW} y2={y}/>;
          })}
          {Array.from({length:17}).map((_,i)=>{
            const t = (i-8)/8;
            return <line key={i} x1={t*380} y1={-70} x2={t*500} y2={70}/>;
          })}
        </g>
        <text x="510" y="-85" fontFamily="var(--font-mono)" fontSize="10" fill="#93C5FD" letterSpacing="2" opacity="0.4">SAM_GOV · 7.7M OPPORTUNITIES</text>
        <line x1="390" y1="-80" x2="505" y2="-80" stroke="#93C5FD" strokeWidth="0.6" opacity="0.4"/>
      </g>

      {/* NEAR PLANE — USASpending, most prominent */}
      <g transform="translate(800 740)" opacity="0.9">
        <g fill="none">
          {/* Horizontal lines with depth fade */}
          {Array.from({length:17}).map((_,i)=>{
            const t = i/16;
            const y = -110 + t*220;
            const halfW = 560 + t*220;
            return <line key={i} x1={-halfW} y1={y} x2={halfW} y2={y}
                         stroke="#BFDBFE" strokeWidth="0.9" strokeOpacity={0.2 + t*0.4}/>;
          })}
          {/* Converging diagonals */}
          {Array.from({length:21}).map((_,i)=>{
            const t = (i-10)/10;
            return <line key={i} x1={t*560} y1={-110} x2={t*780} y2={110}
                         stroke="url(#planeFadeNear)" strokeWidth="0.85"/>;
          })}
        </g>
        <text x="520" y="130" fontFamily="var(--font-mono)" fontSize="11" fill="#BFDBFE" letterSpacing="2" fontWeight="600" opacity="0.45">USASPENDING · 12.6M AWARDS · FY05–FY25</text>
        <line x1="380" y1="124" x2="515" y2="124" stroke="#BFDBFE" strokeWidth="0.8" opacity="0.45"/>
      </g>

      {/* Horizon glow band — bright seam at horizon */}
      <rect x="0" y="258" width="1600" height="1.5" fill="url(#horizonGlow)" opacity="0.9"/>
      <rect x="0" y="255" width="1600" height="8" fill="url(#horizonGlow)" opacity="0.35" filter="url(#heroGlow)"/>
      <rect x="0" y="252" width="1600" height="14" fill="url(#horizonGlow)" opacity="0.15" filter="url(#heroSoftGlow)"/>

      {/* Scanning beam — sweeps horizontally across */}
      <rect x="-400" y="200" width="400" height="540" fill="url(#scanBeam)" opacity="0.12">
        <animate attributeName="x" values="-400;1600" dur="9s" repeatCount="indefinite"/>
      </rect>

      {/* Vertical data flow — particles falling along convergence lines */}
      <g stroke="#60A5FA" strokeWidth="0.4" strokeOpacity="0.3" strokeDasharray="3 5">
        <line x1="500" y1="260" x2="500" y2="740"/>
        <line x1="650" y1="260" x2="650" y2="740"/>
        <line x1="800" y1="260" x2="800" y2="740"/>
        <line x1="950" y1="260" x2="950" y2="740"/>
        <line x1="1100" y1="260" x2="1100" y2="740"/>
      </g>

      {/* Flowing packets along convergence lines */}
      {[500, 650, 800, 950, 1100].map((x, i)=>(
        <circle key={i} cx={x} cy="260" r="1.8" fill="#93C5FD">
          <animate attributeName="cy" values="260;740" dur={`${4 + i*0.5}s`} begin={`${i*0.8}s`} repeatCount="indefinite"/>
          <animate attributeName="opacity" values="0;1;1;0" dur={`${4 + i*0.5}s`} begin={`${i*0.8}s`} repeatCount="indefinite"/>
        </circle>
      ))}

      {/* Pulsing data nodes across planes */}
      {[
        {cx:420, cy:340, r:2, delay:0},    {cx:1180, cy:340, r:1.8, delay:2},
        {cx:620, cy:340, r:1.6, delay:1.2}, {cx:980, cy:340, r:1.8, delay:2.6},
        {cx:500, cy:490, r:2.6, delay:1},  {cx:1100, cy:490, r:2.2, delay:3},
        {cx:700, cy:490, r:2.8, delay:0.5}, {cx:900, cy:490, r:3, delay:1.8},
        {cx:350, cy:740, r:3.5, delay:1.5}, {cx:1250, cy:740, r:3, delay:2.5},
        {cx:600, cy:740, r:4, delay:0.8}, {cx:1000, cy:740, r:3.5, delay:3.5},
        {cx:800, cy:740, r:4.5, delay:1.2},
      ].map((n,i)=>(
        <g key={i}>
          <circle cx={n.cx} cy={n.cy} r={n.r*5} fill="url(#nodePulse)" opacity="0.35">
            <animate attributeName="opacity" values="0.1;0.55;0.1" dur="4s" begin={`${n.delay}s`} repeatCount="indefinite"/>
            <animate attributeName="r" values={`${n.r*4};${n.r*7};${n.r*4}`} dur="4s" begin={`${n.delay}s`} repeatCount="indefinite"/>
          </circle>
          <circle cx={n.cx} cy={n.cy} r={n.r} fill="#BFDBFE">
            <animate attributeName="opacity" values="0.6;1;0.6" dur="2.5s" begin={`${n.delay}s`} repeatCount="indefinite"/>
          </circle>
        </g>
      ))}

      {/* Corner tick marks — technical readout feel */}
      <g stroke="#60A5FA" strokeWidth="0.8" fill="none" opacity="0.5">
        <path d="M 40 40 L 40 70 M 40 40 L 70 40"/>
        <path d="M 1560 40 L 1560 70 M 1560 40 L 1530 40"/>
        <path d="M 40 860 L 40 830 M 40 860 L 70 860"/>
        <path d="M 1560 860 L 1560 830 M 1560 860 L 1530 860"/>
      </g>
      <text x="50" y="85" fontFamily="var(--font-mono)" fontSize="8" fill="#60A5FA" letterSpacing="2" opacity="0.5">FPDS · SUBSTRATE</text>
      <text x="1510" y="85" fontFamily="var(--font-mono)" fontSize="8" fill="#60A5FA" letterSpacing="2" opacity="0.5" textAnchor="end">v2.2</text>
    </svg>

    {/* Depth haze — distant objects fade */}
    <div style={{
      position:'absolute', top:'20%', left:0, right:0, height:'30%',
      background:'linear-gradient(to bottom, rgba(2,5,15,0.4), transparent)',
      pointerEvents:'none',
    }}/>

    {/* Vignette */}
    <div style={{
      position:'absolute', inset:0,
      background:'radial-gradient(ellipse 90% 110% at 50% 50%, transparent 45%, rgba(2,4,13,0.65) 100%)',
      pointerEvents:'none',
    }}/>

    {/* Top fade for nav legibility */}
    <div style={{
      position:'absolute', top:0, left:0, right:0, height:140,
      background:'linear-gradient(to bottom, rgba(2,4,13,0.75), transparent)',
      pointerEvents:'none',
    }}/>

    {/* Bottom fade — for transition to next section */}
    <div style={{
      position:'absolute', bottom:0, left:0, right:0, height:200,
      background:'linear-gradient(to bottom, transparent, rgba(2,4,13,0.3) 40%, rgba(2,4,13,0.85))',
      pointerEvents:'none',
    }}/>
  </div>
);

// Transition strip between dark hero and light problem section.
// Horizon line glows, wireframe grid fades into white, vertical beams catch light.
const HeroToLightTransition = () => (
  <div style={{position:'relative', height:140, overflow:'hidden', background:'#fff', marginTop:-1}}>
    {/* Dark-to-light gradient backdrop */}
    <div style={{
      position:'absolute', inset:0,
      background:'linear-gradient(to bottom, #02040D 0%, #050B22 20%, #0B1638 40%, #1E3A8A 55%, #DBEAFE 80%, #fff 100%)',
    }}/>

    <svg viewBox="0 0 1600 140" preserveAspectRatio="none"
         style={{position:'absolute', inset:0, width:'100%', height:'100%'}}>
      <defs>
        <linearGradient id="transHorizon" x1="0" y1="0" x2="1" y2="0">
          <stop offset="0" stopColor="#3B82F6" stopOpacity="0"/>
          <stop offset="0.5" stopColor="#DBEAFE" stopOpacity="1"/>
          <stop offset="1" stopColor="#3B82F6" stopOpacity="0"/>
        </linearGradient>
        <linearGradient id="transGrid" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0" stopColor="#93C5FD" stopOpacity="0.6"/>
          <stop offset="1" stopColor="#93C5FD" stopOpacity="0"/>
        </linearGradient>
        <filter id="transGlow"><feGaussianBlur stdDeviation="4"/></filter>
      </defs>

      {/* Converging grid lines — top view of near plane extending into distance */}
      <g stroke="url(#transGrid)" strokeWidth="0.8" fill="none">
        {Array.from({length:6}).map((_,i)=>{
          const t = i/5;
          const y = t*70;
          const halfW = 800 + t*400;
          return <line key={i} x1={800-halfW} y1={y} x2={800+halfW} y2={y}/>;
        })}
        {Array.from({length:21}).map((_,i)=>{
          const t = (i-10)/10;
          return <line key={i} x1={800 + t*200} y1="0" x2={800 + t*1200} y2="70"/>;
        })}
      </g>

      {/* Horizon glow seam at top */}
      <rect x="0" y="0" width="1600" height="2" fill="url(#transHorizon)" opacity="0.9"/>
      <rect x="0" y="-4" width="1600" height="12" fill="url(#transHorizon)" opacity="0.5" filter="url(#transGlow)"/>

      {/* Bottom fade markers — subtle dots as grid meets white */}
      {Array.from({length:24}).map((_,i)=>{
        const x = i * 66.6 + 33;
        return <circle key={i} cx={x} cy="85" r="0.8" fill="#93C5FD" opacity="0.5"/>;
      })}
    </svg>
  </div>
);

window.HeroBackground = HeroBackground;
window.HeroToLightTransition = HeroToLightTransition;
