/* REVOLUTION TIMELINE - "מי שלא מצטרף ל-AI יישאר מאחורה"
   Scroll-driven video from frames_v3/ with bottom-anchored timeline (2020→2027),
   5 phase statements with distinct entry animations, and a climax CTA.
   Visually distinct from Hero (floating cards) and LoopSequence (HUD activation). */

function RevolutionTimeline() {
  const sectionRef = React.useRef(null);
  const canvasRef = React.useRef(null);
  const framesRef = React.useRef([]);
  const [framesReady, setFramesReady] = React.useState(false);
  const [loadPct, setLoadPct] = React.useState(0);
  const progress = useSectionProgress(sectionRef);
  const progressRef = React.useRef(0);
  React.useEffect(() => { progressRef.current = progress; }, [progress]);
  const isMobile = useIsMobile();
  const isMobileInitial = React.useRef(isMobile);

  // ── Frame loader (same pattern as LoopSequence, points to frames_v3/) ─
  React.useEffect(() => {
    let cancelled = false;
    const TOTAL_AVAILABLE = 301;
    const STEP = isMobileInitial.current ? 6 : 3;
    const MAX_W = isMobileInitial.current ? 600 : 960;
    const folder = isMobileInitial.current ? 'frames_v3_mobile' : 'frames_v3';
    const indices = [];
    for (let i = 1; i <= TOTAL_AVAILABLE; i += STEP) indices.push(i);

    (async () => {
      const frames = new Array(indices.length);
      let loaded = 0;
      const loadOne = (n, idx) => new Promise((resolve) => {
        const img = new Image();
        img.decoding = 'async';
        img.onload = () => {
          const scale = Math.min(1, MAX_W / img.naturalWidth);
          const W = Math.round(img.naturalWidth * scale);
          const H = Math.round(img.naturalHeight * scale);
          const c = document.createElement('canvas');
          c.width = W; c.height = H;
          c.getContext('2d').drawImage(img, 0, 0, W, H);
          frames[idx] = c;
          loaded++;
          if (!cancelled) setLoadPct(loaded / indices.length);
          resolve();
        };
        img.onerror = () => { loaded++; if (!cancelled) setLoadPct(loaded / indices.length); resolve(); };
        img.src = `${folder}/frame_${String(n).padStart(4, '0')}.jpg`;
      });
      const CONC = 8;
      let cur = 0;
      const workers = Array.from({ length: CONC }, async () => {
        while (cur < indices.length && !cancelled) {
          const i = cur++;
          await loadOne(indices[i], i);
        }
      });
      await Promise.all(workers);
      framesRef.current = frames.filter(Boolean);
      if (!cancelled) setFramesReady(true);
    })();
    return () => { cancelled = true; };
  }, []);

  // ── Smoothed paint loop ────────────────────────────────────────────
  const smoothedRef = React.useRef(0);
  React.useEffect(() => {
    if (!framesReady) return;
    const cv = canvasRef.current;
    if (!cv) return;
    const ctx = cv.getContext('2d');
    let raf = 0;
    let lastIdx = -1;
    const resize = () => {
      const dpr = Math.min(window.devicePixelRatio || 1, 2);
      cv.width = Math.round(window.innerWidth * dpr);
      cv.height = Math.round(window.innerHeight * dpr);
      cv.style.width = window.innerWidth + 'px';
      cv.style.height = window.innerHeight + 'px';
      lastIdx = -1;
    };
    const paint = () => {
      const total = framesRef.current.length;
      if (!total) return;
      const target = progressRef.current;
      const diff = target - smoothedRef.current;
      smoothedRef.current = Math.abs(diff) < 0.0002 ? target : smoothedRef.current + diff * 0.16;
      const p = smoothedRef.current;
      const idx = clamp(Math.round(p * (total - 1)), 0, total - 1);
      if (idx !== lastIdx) {
        const cw = cv.width, ch = cv.height;
        const fr = framesRef.current[idx];
        if (!fr) return;
        const scale = Math.max(cw / fr.width, ch / fr.height);
        const dw = fr.width * scale, dh = fr.height * scale;
        const dx = (cw - dw) / 2, dy = (ch - dh) / 2;
        ctx.globalCompositeOperation = 'copy';
        ctx.drawImage(fr, dx, dy, dw, dh);
        ctx.globalCompositeOperation = 'source-over';
        lastIdx = idx;
      }
    };
    const tick = () => { paint(); raf = requestAnimationFrame(tick); };
    resize();
    window.addEventListener('resize', resize);
    raf = requestAnimationFrame(tick);
    return () => { cancelAnimationFrame(raf); window.removeEventListener('resize', resize); };
  }, [framesReady]);

  // ── Phase windows + visibility ─────────────────────────────────────
  const W = {
    s2020: { in0: 0.08, in1: 0.13, out0: 0.22, out1: 0.26 },
    s2023: { in0: 0.26, in1: 0.31, out0: 0.40, out1: 0.44 },
    s2025: { in0: 0.44, in1: 0.49, out0: 0.58, out1: 0.62 },
    s2026: { in0: 0.62, in1: 0.69, out0: 0.78, out1: 0.82 },
    s2027: { in0: 0.82, in1: 0.89, out0: 1.10, out1: 1.20 },
  };
  const vis = (w) => Math.min(smoothstep(w.in0, w.in1, progress), 1 - smoothstep(w.out0, w.out1, progress));
  const v2020 = vis(W.s2020);
  const v2023 = vis(W.s2023);
  const v2025 = vis(W.s2025);
  const v2026 = vis(W.s2026);
  const v2027 = vis(W.s2027);
  const climaxP = smoothstep(0.86, 0.96, progress);
  const bootP = smoothstep(0.00, 0.06, progress);

  let phaseIdx = 0;
  if (progress >= 0.08) phaseIdx = 1;
  if (progress >= 0.26) phaseIdx = 2;
  if (progress >= 0.44) phaseIdx = 3;
  if (progress >= 0.62) phaseIdx = 4;
  if (progress >= 0.82) phaseIdx = 5;

  return (
    <section ref={sectionRef} style={{position:'relative', height: isMobile ? '720vh' : '960vh', background:'#0A0907'}}>
      <style>{`
        @keyframes rt-slide-right { from { transform:translateX(70vw); opacity:0 } 75% { transform:translateX(-14px); opacity:1 } 100% { transform:translateX(0); opacity:1 } }
        @keyframes rt-drop        { from { transform:translateY(-100px); opacity:0 } 65% { transform:translateY(12px); opacity:1 } 82% { transform:translateY(-6px) } 100% { transform:translateY(0); opacity:1 } }
        @keyframes rt-glitch      {
          0%   { transform:translate(0,0); text-shadow:0 0 transparent; }
          14%  { transform:translate(-3px,1px); text-shadow:3px 0 #ff3b6b,-3px 0 #2dd4f7; }
          28%  { transform:translate(3px,-1px); text-shadow:-2px 0 #ff3b6b,2px 0 #2dd4f7; }
          42%  { transform:translate(-2px,2px); text-shadow:4px 0 #ff3b6b,-4px 0 #2dd4f7; }
          58%  { transform:translate(1px,-2px); text-shadow:-1px 0 #ff3b6b,1px 0 #2dd4f7; }
          74%  { transform:translate(-1px,0); text-shadow:2px 0 #ff3b6b,-2px 0 #2dd4f7; }
          90%  { transform:translate(0,1px); text-shadow:1px 0 #ff3b6b,-1px 0 #2dd4f7; }
          100% { transform:translate(0,0); text-shadow:0 0 transparent; }
        }
        @keyframes rt-impact {
          0%   { transform:scale(1.55) translateX(0); opacity:0; color:#EEB332; }
          55%  { transform:scale(0.95) translateX(0); opacity:1; color:#EEB332; }
          65%  { transform:scale(1) translateX(-7px); color:#FFD777; }
          72%  { transform:scale(1) translateX(6px); color:#FFD777; }
          79%  { transform:scale(1) translateX(-4px); color:#FFE9B4; }
          86%  { transform:scale(1) translateX(2px); color:#FFF5D6; }
          100% { transform:scale(1) translateX(0); opacity:1; color:#F5F2ED; }
        }
        @keyframes rt-cursor      { 0%,49% { opacity:1 } 50%,100% { opacity:0 } }
        @keyframes rt-underline   { from { transform:scaleX(0) } to { transform:scaleX(1) } }
        @keyframes rt-orbit       { from { transform:rotate(0) } to { transform:rotate(360deg) } }
        @keyframes rt-halo        { 0%,100% { opacity:0.35; transform:scale(1) } 50% { opacity:0.85; transform:scale(1.06) } }
        @keyframes rt-now-breathe { 0%,100% { transform:translateX(-50%) scale(1); opacity:0.85 } 50% { transform:translateX(-50%) scale(1.08); opacity:1 } }
        @keyframes rt-spark       {
          0%   { transform:translateY(120vh) translateX(0); opacity:0; }
          12%  { opacity:0.85; }
          88%  { opacity:0.85; }
          100% { transform:translateY(-20vh) translateX(40px); opacity:0; }
        }
        @keyframes rt-ticker-pulse { 0%,100% { opacity:0.9 } 50% { opacity:0.45 } }
      `}</style>

      <div style={{position:'sticky', top:0, height:'100vh', overflow:'hidden'}}>
        {/* VIDEO */}
        <canvas
          ref={canvasRef}
          style={{position:'absolute', inset:0, width:'100%', height:'100%', display:'block',
                  filter:'saturate(1.08) contrast(1.05)'}}
        />

        {/* LOADER */}
        {!framesReady && (
          <div style={{position:'absolute', inset:0, display:'flex', alignItems:'center', justifyContent:'center', flexDirection:'column', gap:20, background:'#0A0907', zIndex:30}}>
            <div style={{fontSize:11, letterSpacing:'0.22em', textTransform:'uppercase', color:'#EEB332', fontFamily:'Open Sans, sans-serif', fontWeight:600}}>טוען קו זמן</div>
            <div style={{width:240, height:2, background:'rgba(245,242,237,0.08)', borderRadius:500, overflow:'hidden'}}>
              <div style={{height:'100%', width:`${loadPct*100}%`, background:'linear-gradient(90deg, #DD9933, #FFD777)', boxShadow:'0 0 12px #EEB332', transition:'width 120ms linear'}} />
            </div>
            <div style={{fontSize:12, color:'rgba(245,242,237,0.45)', fontFamily:'monospace'}}>{Math.round(loadPct*100)}%</div>
          </div>
        )}

        {/* CINEMATIC LETTERBOX - different from Hero (warm spotlight) and LoopSequence (tunnel sides) */}
        <div style={{position:'absolute', top:0, left:0, right:0, height:'10%', background:'linear-gradient(180deg, rgba(10,9,7,0.85), rgba(10,9,7,0))', pointerEvents:'none'}} />
        <div style={{position:'absolute', bottom:0, left:0, right:0, height:'26%', background:'linear-gradient(0deg, rgba(10,9,7,0.92) 0%, rgba(10,9,7,0.7) 40%, rgba(10,9,7,0) 100%)', pointerEvents:'none'}} />

        {/* AMBIENT SPARKS - slow drift on right edge */}
        <Sparks />

        {/* INTRO KICKER */}
        <div dir="rtl" style={{position:'absolute', top: isMobile ? 90 : 36, right: isMobile ? 14 : 36, fontFamily:'Open Sans, sans-serif', fontWeight:600, fontSize: isMobile ? 10 : 12, letterSpacing:'0.10em', color:'#EEB332', textShadow:'0 0 8px rgba(238,179,50,0.5)', opacity: bootP, pointerEvents:'none', zIndex:5}}>
          ▸ קו הזמן · 2020–2027
        </div>

        {/* PHASE COUNTER */}
        <div dir="ltr" style={{position:'absolute', top: isMobile ? 90 : 36, left: isMobile ? 14 : 36, fontFamily:'monospace', fontSize: isMobile ? 9 : 11, letterSpacing:'0.16em', color:'rgba(245,242,237,0.7)', opacity: bootP, pointerEvents:'none', zIndex:5}}>
          STAGE · {String(Math.max(phaseIdx, 1)).padStart(2,'0')} / 05
        </div>

        {/* STATEMENTS */}
        <TypewriterStatement visible={v2020} progress={progress} W={W.s2020} text="AI היה רעיון רחוק. משהו של מעבדות, קוד ומפתחים." />
        <SlideStatement      visible={v2023} text="ואז זה פרץ החוצה. פתאום כל אחד יכול ליצור, לבנות ולחשוב מהר יותר." />
        <DropStatement       visible={v2025} text="מי שלומד להשתמש בזה היום, מקבל יתרון שאי אפשר להשלים אחר כך." />
        <GlitchHaloStatement visible={v2026} text="החלון פתוח עכשיו. אבל הוא לא יישאר פתוח לנצח." />
        <StampImpactStatement visible={v2027} text="מי שיחכה שהעולם יירגע, יגלה שהוא כבר המשיך בלעדיו." />

        {/* CLIMAX CTA */}
        <ClimaxCTA climaxP={climaxP} />

        {/* BOTTOM TIMELINE */}
        <Timeline progress={progress} phaseIdx={phaseIdx} bootP={bootP} climaxP={climaxP} />
      </div>
    </section>
  );
}

/* ─────────────────────────────────────────────────────────────────────
   SUBCOMPONENTS
   ───────────────────────────────────────────────────────────────────── */

function Sparks() {
  const isMobile = useIsMobile();
  const count = isMobile ? 4 : 7;
  const sparks = React.useMemo(() => Array.from({ length: count }, () => ({
    left: 65 + Math.random() * 32,
    delay: Math.random() * 10,
    duration: 9 + Math.random() * 6,
    size: 2 + Math.random() * 2.5,
  })), [count]);
  return (
    <div style={{position:'absolute', inset:0, pointerEvents:'none', overflow:'hidden', zIndex:3}}>
      {sparks.map((s, i) => (
        <span key={i} style={{
          position:'absolute', top:0, left:`${s.left}%`,
          width:s.size, height:s.size, borderRadius:'50%',
          background:'#FFD777',
          boxShadow:'0 0 8px #EEB332, 0 0 16px rgba(238,179,50,0.4)',
          animation:`rt-spark ${s.duration}s linear ${s.delay}s infinite`,
          willChange:'transform, opacity',
        }} />
      ))}
    </div>
  );
}

/* Common centered stage for the upper area, leaving the bottom for timeline */
function StageWrap({ visible, children, top }) {
  return (
    <div style={{
      position:'absolute', top: top || '32%', left:0, right:0,
      display:'flex', justifyContent:'center', padding:'0 32px',
      pointerEvents:'none', zIndex:7,
      opacity: visible,
      transition:'opacity 240ms linear',
    }}>
      {children}
    </div>
  );
}

function TypewriterStatement({ visible, progress, W, text }) {
  if (visible <= 0.01) return null;
  const typeP = smoothstep(W.in0, W.in1, progress);
  const shown = Math.floor(typeP * text.length);
  const visibleText = text.slice(0, shown);
  const isTyping = typeP > 0 && typeP < 1;
  return (
    <StageWrap visible={visible}>
      <div dir="rtl" style={{
        fontFamily:'Open Sans, sans-serif', fontWeight:700,
        fontSize:'clamp(26px, 3.8vw, 56px)', lineHeight:1.3,
        letterSpacing:'-0.015em', textAlign:'center',
        color:'rgba(245,242,237,0.9)',
        textShadow:'0 4px 32px rgba(0,0,0,0.7)',
        maxWidth:'min(92vw, 1000px)',
      }}>
        <span style={{whiteSpace:'pre-wrap'}}>{visibleText}</span>
        {isTyping && (
          <span style={{
            display:'inline-block', width:'0.45em', height:'0.92em',
            background:'#EEB332', verticalAlign:'-2px', marginInlineStart:'0.12em',
            boxShadow:'0 0 12px #EEB332',
            animation:'rt-cursor 0.7s steps(1) infinite',
          }} />
        )}
      </div>
    </StageWrap>
  );
}

function SlideStatement({ visible, text }) {
  if (visible <= 0.01) return null;
  return (
    <StageWrap visible={visible}>
      <div dir="rtl" style={{
        fontFamily:'Open Sans, sans-serif', fontWeight:800,
        fontSize:'clamp(28px, 4.2vw, 64px)', lineHeight:1.25,
        letterSpacing:'-0.02em', textAlign:'center',
        color:'#F5F2ED',
        textShadow:'0 4px 40px rgba(0,0,0,0.75)',
        animation:'rt-slide-right 720ms cubic-bezier(0.22,1,0.36,1) both',
        willChange:'transform, opacity',
        maxWidth:'min(92vw, 1050px)',
      }}>{text}</div>
    </StageWrap>
  );
}

function DropStatement({ visible, text }) {
  if (visible <= 0.01) return null;
  return (
    <StageWrap visible={visible}>
      <div dir="rtl" style={{textAlign:'center', maxWidth:'min(92vw, 1050px)'}}>
        <div style={{
          fontFamily:'Open Sans, sans-serif', fontWeight:800,
          fontSize:'clamp(28px, 4.2vw, 64px)', lineHeight:1.25,
          letterSpacing:'-0.02em',
          color:'#F5F2ED',
          textShadow:'0 4px 40px rgba(0,0,0,0.75)',
          animation:'rt-drop 720ms cubic-bezier(0.36,0,0.22,1.1) both',
          willChange:'transform, opacity',
        }}>{text}</div>
        <div style={{
          margin:'24px auto 0',
          height:2, width:'min(60%, 480px)',
          background:'linear-gradient(90deg, transparent, #EEB332, transparent)',
          boxShadow:'0 0 12px #EEB332',
          transformOrigin:'center',
          animation:'rt-underline 700ms cubic-bezier(0.22,1,0.36,1) 340ms both',
        }} />
      </div>
    </StageWrap>
  );
}

function GlitchHaloStatement({ visible, text }) {
  if (visible <= 0.01) return null;
  return (
    <StageWrap visible={visible}>
      <div dir="rtl" style={{position:'relative', textAlign:'center'}}>
        {/* Soft persistent halo */}
        <div style={{
          position:'absolute', inset:'-10% -8%',
          background:'radial-gradient(ellipse at center, rgba(238,179,50,0.28), rgba(238,179,50,0) 65%)',
          pointerEvents:'none',
          animation:'rt-halo 2.2s ease-in-out infinite',
        }} />
        <div style={{
          position:'relative',
          fontFamily:'Open Sans, sans-serif', fontWeight:900,
          fontSize:'clamp(30px, 4.6vw, 72px)', lineHeight:1.2,
          letterSpacing:'-0.02em',
          maxWidth:'min(92vw, 1080px)',
          background:'linear-gradient(180deg, #FFD777 0%, #EEB332 50%, #B27418 100%)',
          WebkitBackgroundClip:'text', WebkitTextFillColor:'transparent', backgroundClip:'text',
          filter:'drop-shadow(0 0 30px rgba(238,179,50,0.55))',
          animation:'rt-glitch 600ms ease-out 1 both',
          willChange:'transform, text-shadow',
        }}>{text}</div>
      </div>
    </StageWrap>
  );
}

function StampImpactStatement({ visible, text }) {
  if (visible <= 0.01) return null;
  return (
    <div style={{
      position:'absolute', top:'24%', left:0, right:0,
      display:'flex', justifyContent:'center', padding:'0 32px',
      pointerEvents:'none', zIndex:7,
      opacity: visible,
      transition:'opacity 240ms linear',
    }}>
      <div dir="rtl" style={{
        fontFamily:'Open Sans, sans-serif', fontWeight:900,
        fontSize:'clamp(30px, 4.8vw, 76px)', lineHeight:1.2,
        letterSpacing:'-0.02em', textAlign:'center',
        maxWidth:'min(92vw, 1080px)',
        textShadow:'0 4px 40px rgba(0,0,0,0.85), 0 0 60px rgba(238,179,50,0.35)',
        animation:'rt-impact 1100ms cubic-bezier(0.34,1.56,0.64,1) both',
        willChange:'transform, opacity, color',
      }}>{text}</div>
    </div>
  );
}

function ClimaxCTA({ climaxP }) {
  const isMobile = useIsMobile();
  if (climaxP <= 0.01) return null;
  const arcW = isMobile ? 260 : 340;
  const arcH = isMobile ? 72 : 96;
  return (
    <div style={{
      position:'absolute', bottom: isMobile ? '34%' : '30%', left:0, right:0,
      display:'flex', alignItems:'center', justifyContent:'center', flexDirection:'column', gap: isMobile ? 14 : 18,
      pointerEvents: climaxP > 0.5 ? 'auto' : 'none',
      zIndex:8, padding:'0 16px',
      opacity: climaxP,
      transform: `scale(${lerp(0.78, 1, climaxP)})`,
      transition:'transform 280ms cubic-bezier(0.34,1.56,0.64,1)',
    }}>
      <div dir="ltr" style={{
        fontFamily:'monospace', fontSize: isMobile ? 10 : 'clamp(11px, 1.05vw, 14px)',
        letterSpacing:'0.24em', color:'#FFD777',
        textShadow:'0 0 10px rgba(238,179,50,0.55)',
      }}>{'> WINDOW.CLOSING'}</div>

      <div style={{position:'relative'}}>
        {/* Orbiting arc */}
        <div style={{
          position:'absolute', top:'50%', left:'50%',
          width:arcW, height:arcH,
          transform:'translate(-50%, -50%)',
          animation:'rt-orbit 5s linear infinite',
          pointerEvents:'none',
        }}>
          <svg width={arcW} height={arcH} viewBox={`0 0 ${arcW} ${arcH}`} style={{position:'absolute', inset:0}}>
            <ellipse cx={arcW/2} cy={arcH/2} rx={(arcW/2) - 12} ry={(arcH/2) - 8} fill="none" stroke="rgba(238,179,50,0.6)" strokeWidth="1" strokeDasharray="44 240" />
          </svg>
        </div>
        {/* Pulsing halo */}
        <div style={{
          position:'absolute', inset:-14,
          borderRadius:500,
          background:'radial-gradient(ellipse, rgba(238,179,50,0.4), transparent 60%)',
          animation:'rt-halo 2s ease-in-out infinite',
          pointerEvents:'none',
        }} />
        <button onClick={() => scrollToSection('pricing')} style={{
          position:'relative', zIndex:1,
          background:'rgba(10,9,7,0.65)',
          color:'#EEB332',
          border:'2px solid #DD9933',
          borderRadius:500,
          padding: isMobile ? '14px 28px' : '18px 56px',
          fontSize: isMobile ? 14 : 18, fontFamily:'Open Sans, sans-serif', fontWeight:700,
          cursor:'pointer', whiteSpace:'nowrap',
          boxShadow:'0 0 36px 6px rgba(238,179,50,0.5), inset 0 0 14px rgba(238,179,50,0.15)',
          backdropFilter:'blur(8px)', WebkitBackdropFilter:'blur(8px)',
        }}>הצטרף למהפכת ה-AI &larr;</button>
      </div>
    </div>
  );
}

function Timeline({ progress, phaseIdx, bootP, climaxP }) {
  const isMobile = useIsMobile();
  const years = [
    { year: 2020, pos: 4 },
    { year: 2023, pos: 28 },
    { year: 2025, pos: 52 },
    { year: 2026, pos: 76 },
    { year: 2027, pos: 96 },
  ];
  const markerPos = lerp(4, 96, clamp(progress, 0, 1));

  return (
    <div dir="ltr" style={{
      position:'absolute', bottom: isMobile ? 32 : 56, left: isMobile ? '4%' : '8%', right: isMobile ? '4%' : '8%',
      pointerEvents:'none', zIndex:6,
      opacity: bootP,
    }}>
      {/* line wrapper */}
      <div style={{position:'relative', height: 2}}>
        {/* full unfilled track */}
        <div style={{position:'absolute', top:0, left:0, right:0, height:2, background:'rgba(238,179,50,0.18)'}} />
        {/* filled portion behind marker */}
        <div style={{
          position:'absolute', top:0, left:0, height:2,
          width:`${markerPos}%`,
          background:'linear-gradient(90deg, rgba(238,179,50,0.5), #EEB332, #FFD777)',
          boxShadow:'0 0 10px rgba(238,179,50,0.45)',
          transition:'width 60ms linear',
        }} />

        {/* year ticks */}
        {years.map((y, i) => {
          const passed = i < phaseIdx;
          const active = i === phaseIdx - 1;
          return (
            <div key={y.year} style={{
              position:'absolute', top:-7, left:`${y.pos}%`,
              transform:'translateX(-50%)',
              width:2, height: isMobile ? 10 : 14,
              background: active ? '#FFD777' : passed ? '#EEB332' : 'rgba(238,179,50,0.35)',
              boxShadow: active ? '0 0 12px #FFD777' : passed ? '0 0 8px rgba(238,179,50,0.5)' : 'none',
              transition:'all 240ms',
            }} />
          );
        })}

        {/* marker - diamond + downward triangle */}
        <div style={{
          position:'absolute', top: isMobile ? -7 : -9, left:`${markerPos}%`,
          transform:'translateX(-50%) rotate(45deg)',
          width: isMobile ? 11 : 14, height: isMobile ? 11 : 14,
          background:'linear-gradient(135deg, #FFD777, #DD9933)',
          boxShadow:'0 0 16px #EEB332',
          transition:'left 60ms linear',
        }} />

        {/* NOW badge under marker */}
        <div style={{
          position:'absolute', top: isMobile ? 18 : 24, left:`${markerPos}%`,
          fontFamily:'monospace', fontSize: isMobile ? 8 : 9, letterSpacing:'0.28em',
          color:'#EEB332', textShadow:'0 0 8px rgba(238,179,50,0.6)',
          animation:'rt-now-breathe 2.2s ease-in-out infinite',
          willChange:'transform, opacity',
        }}>NOW</div>
      </div>

      {/* year labels */}
      <div style={{position:'relative', marginTop: isMobile ? 34 : 42, height:14}}>
        {years.map((y, i) => {
          const active = i === phaseIdx - 1;
          const passed = i < phaseIdx - 1;
          return (
            <div key={y.year} style={{
              position:'absolute', left:`${y.pos}%`,
              transform:'translateX(-50%)',
              fontFamily:'monospace', fontSize: isMobile ? 9 : 11, letterSpacing:'0.10em',
              color: active ? '#FFD777' : passed ? 'rgba(238,179,50,0.55)' : 'rgba(245,242,237,0.32)',
              textShadow: active ? '0 0 8px rgba(238,179,50,0.6)' : 'none',
              transition:'color 240ms',
              fontWeight: active ? 600 : 400,
            }}>{y.year}</div>
          );
        })}
      </div>

      {/* climax ticker - replaces no other UI; appears at bottom of timeline area */}
      <div dir="rtl" style={{
        marginTop: isMobile ? 12 : 18, textAlign:'center',
        fontFamily:'Open Sans, sans-serif', fontWeight:600, fontSize: isMobile ? 10 : 11, letterSpacing:'0.10em',
        color:'#FFD777', textShadow:'0 0 10px rgba(238,179,50,0.5)',
        opacity: climaxP,
        animation: climaxP > 0.3 ? 'rt-ticker-pulse 1.8s ease-in-out infinite' : 'none',
        transition:'opacity 280ms',
      }}>
        המהפכה כבר התחילה ▸ עכשיו · עכשיו · עכשיו
      </div>
    </div>
  );
}

window.RevolutionTimeline = RevolutionTimeline;
