// scenes.jsx — sceny dla wideo 60s

// Wspólna paleta
const PALETTE = {
  orange: '#F36B1F',   // energetyczny akcent
  orangeDeep: '#D0531A',
  graphite: '#1E2329',
  graphiteMid: '#2A3038',
  cream: '#F6F2EB',
  white: '#FFFFFF',
  red: '#DC3545',
};

const FONT = "'Barlow Condensed', 'Arial Narrow', sans-serif";
const FONT_BODY = "'Inter', system-ui, sans-serif";
const FONT_MONO = "'JetBrains Mono', ui-monospace, monospace";

// ───────────────────────────── HELPERS ─────────────────────────────

function Subtitles({ text, bottom = 80 }) {
  if (typeof window !== 'undefined' && window.__SUBS_OFF) return null;
  return (
    <div data-subtitle="1" style={{
      position: 'absolute',
      left: '50%',
      bottom: bottom,
      transform: 'translateX(-50%)',
      background: 'rgba(10,12,16,0.82)',
      padding: '12px 24px',
      borderRadius: 6,
      maxWidth: 1400,
      fontFamily: FONT_BODY,
      fontSize: 28,
      fontWeight: 500,
      color: '#fff',
      letterSpacing: '0.01em',
      textAlign: 'center',
      lineHeight: 1.3,
      boxShadow: '0 8px 24px rgba(0,0,0,0.4)',
    }}>
      {text}
    </div>
  );
}

function BrandBar() {
  const t = useTime();
  const pulse = 0.5 + 0.5 * Math.sin(t * 2);
  return (
    <div style={{
      position: 'absolute', top: 32, left: 48,
      display: 'flex', alignItems: 'center', gap: 14,
      zIndex: 50,
    }}>
      <div style={{
        width: 48, height: 48,
        borderRadius: '50%',
        background: '#fff',
        display: 'flex', alignItems: 'center', justifyContent: 'center',
        overflow: 'hidden',
        boxShadow: '0 4px 12px rgba(0,0,0,0.3)',
      }}>
        <img src="assets/logo-sp.png" alt="SP Korczak" style={{ width: '100%', height: '100%', objectFit: 'cover' }} />
      </div>
      <div style={{ fontFamily: FONT_BODY, color: '#fff', lineHeight: 1.1 }}>
        <div style={{ fontSize: 14, fontWeight: 600, letterSpacing: '0.02em' }}>
          SP im. Janusza Korczaka
        </div>
        <div style={{ fontSize: 12, opacity: 0.7, letterSpacing: '0.08em', textTransform: 'uppercase' }}>
          Góra
        </div>
      </div>
    </div>
  );
}

function TimecodeTicker() {
  const t = useTime();
  const sec = Math.floor(t);
  return (
    <div style={{
      position: 'absolute', top: 32, right: 48,
      fontFamily: FONT_MONO, fontSize: 12,
      color: 'rgba(255,255,255,0.55)',
      letterSpacing: '0.1em',
      zIndex: 50,
    }}>
      {String(sec).padStart(2, '0')} / 60
    </div>
  );
}

// Pasek postępu u góry (wizualny rytm)
function ProgressTape() {
  const t = useTime();
  const progress = clamp(t / 60, 0, 1);
  return (
    <div style={{
      position: 'absolute', top: 0, left: 0, right: 0,
      height: 4,
      background: 'rgba(255,255,255,0.08)',
      zIndex: 60,
    }}>
      <div style={{
        height: '100%',
        width: `${progress * 100}%`,
        background: PALETTE.orange,
        transition: 'none',
      }} />
    </div>
  );
}

// ───────────────────────────── SCENA 1: HOOK (0-8s) ─────────────────────────────

function SceneHook() {
  return (
    <Sprite start={0} end={8.2}>
      {({ localTime }) => {
        // Ken Burns na zdjęciu szkoły
        const zoom = 1.05 + localTime * 0.015;
        const pan = localTime * 6;

        // Delikatna winieta — tylko dla czytelności tekstu
        const vign = 0.15 + Math.min(0.2, localTime * 0.02);

        // Slogan pojawia się po 1.2s
        const textOp = clamp((localTime - 1.2) / 0.6, 0, 1);

        // Pomarańczowy badge z rokiem 1973 (szkoła im. Korczaka istnieje od dekad — symbol tradycji)
        const tagOp = clamp((localTime - 3.5) / 0.4, 0, 1);
        const tagScale = 0.7 + 0.3 * Easing.easeOutBack(tagOp);

        return (
          <>
            <div style={{
              position: 'absolute', inset: 0,
              backgroundImage: 'url(assets/szkola-obecna.png)',
              backgroundSize: 'cover',
              backgroundPosition: `${50 + pan * 0.05}% 50%`,
              transform: `scale(${zoom})`,
              transformOrigin: 'center',
              filter: 'saturate(1.0) brightness(1.02)',
            }} />
            {/* Subtelny gradient dla czytelności */}
            <div style={{
              position: 'absolute', inset: 0,
              background: `linear-gradient(180deg, rgba(10,12,16,${vign}) 0%, rgba(10,12,16,${vign + 0.25}) 100%)`,
            }} />

            {/* Slogan */}
            <div style={{
              position: 'absolute',
              left: 120, top: 420,
              opacity: textOp,
              transform: `translateY(${(1 - textOp) * 20}px)`,
              fontFamily: FONT,
              fontSize: 120,
              fontWeight: 800,
              color: '#fff',
              lineHeight: 0.95,
              letterSpacing: '-0.01em',
              textTransform: 'uppercase',
              textShadow: '0 4px 20px rgba(0,0,0,0.6)',
            }}>
              NASZA SZKOŁA<br/>
              <span style={{ color: PALETTE.orange }}>ROŚNIE RAZEM Z NAMI.</span>
            </div>

            {/* Badge pozytywny */}
            <div style={{
              position: 'absolute',
              right: 140, top: 180,
              opacity: tagOp,
              transform: `rotate(-4deg) scale(${tagScale})`,
              transformOrigin: 'center',
              background: PALETTE.orange,
              color: '#fff',
              padding: '18px 30px',
              fontFamily: FONT,
              fontWeight: 800,
              fontSize: 52,
              lineHeight: 1,
              letterSpacing: '0.02em',
              boxShadow: '0 10px 30px rgba(243,107,31,0.5)',
              textAlign: 'center',
            }}>
              Czas na<br/>
              <span style={{ fontSize: 64 }}>KOLEJNY KROK</span>
            </div>

            <Subtitles text="Nasza szkoła rośnie razem z nami." />
          </>
        );
      }}
    </Sprite>
  );
}

// ───────────────────────────── SCENA 2: LICZBY PROBLEMU (8-18s) ─────────────────────────────

function ProblemStat({ number, label, icon, delay, localTime }) {
  const lt = localTime - delay;
  const op = clamp(lt / 0.6, 0, 1);
  const y = (1 - Easing.easeOutCubic(op)) * 30;
  const countProgress = clamp(lt / 1.2, 0, 1);
  const numInt = typeof number === 'number' ? Math.round(number * Easing.easeOutCubic(countProgress)) : number;

  return (
    <div style={{
      opacity: op,
      transform: `translateY(${y}px)`,
      textAlign: 'center',
      flex: 1,
    }}>
      <div style={{
        fontFamily: FONT,
        fontSize: 140,
        fontWeight: 800,
        color: PALETTE.orange,
        lineHeight: 1,
        letterSpacing: '-0.02em',
      }}>
        {numInt}
        {typeof number === 'number' && <span style={{ fontSize: 56, color: PALETTE.graphite }}>{icon}</span>}
      </div>
      <div style={{
        fontFamily: FONT_BODY,
        fontSize: 22,
        fontWeight: 600,
        color: PALETTE.graphite,
        marginTop: 12,
        textTransform: 'uppercase',
        letterSpacing: '0.08em',
      }}>
        {label}
      </div>
    </div>
  );
}

function SceneProblem() {
  return (
    <Sprite start={8} end={18.2}>
      {({ localTime }) => {
        return (
          <>
            <div style={{ position: 'absolute', inset: 0, background: PALETTE.cream }} />

            {/* Diagonal stripe accent */}
            <div style={{
              position: 'absolute',
              top: -50, right: -50,
              width: 400, height: 400,
              background: PALETTE.orange,
              transform: 'rotate(45deg)',
              opacity: 0.08,
            }} />

            {/* Nagłówek */}
            <div style={{
              position: 'absolute',
              left: 120, top: 140,
              opacity: clamp((localTime - 0.2) / 0.5, 0, 1),
              transform: `translateY(${(1 - clamp((localTime - 0.2) / 0.5, 0, 1)) * 20}px)`,
            }}>
              <div style={{
                fontFamily: FONT_MONO,
                fontSize: 16,
                color: PALETTE.orange,
                letterSpacing: '0.2em',
                textTransform: 'uppercase',
                marginBottom: 12,
              }}>
                — Nasza szkoła w liczbach
              </div>
              <div style={{
                fontFamily: FONT,
                fontSize: 92,
                fontWeight: 800,
                color: PALETTE.graphite,
                lineHeight: 0.95,
                letterSpacing: '-0.01em',
                textTransform: 'uppercase',
              }}>
                Tyle energii.<br/>
                Tyle pasji.<br/>
                <span style={{ color: PALETTE.orange }}>Czas na więcej miejsca.</span>
              </div>
            </div>

            {/* Stats row */}
            <div style={{
              position: 'absolute',
              left: 120, right: 120, bottom: 140,
              display: 'flex',
              gap: 40,
            }}>
              <ProblemStat number={58} icon="h" label="Godzin WF każdego tygodnia" delay={3.0} localTime={localTime} />
              <ProblemStat number={300} icon="+" label="Uczniów w ruchu" delay={4.5} localTime={localTime} />
              <ProblemStat number={1} icon="" label="Jedna sala gimnastyczna" delay={6.0} localTime={localTime} />
            </div>

            <Subtitles text="Codziennie dziesiątki dzieci ćwiczą, grają, rozwijają się — w jednej sali." />
          </>
        );
      }}
    </Sprite>
  );
}

// ───────────────────────────── SCENA 3: PORÓWNANIE (18-28s) ─────────────────────────────

function SceneComparison() {
  return (
    <Sprite start={18} end={28.2}>
      {({ localTime }) => {
        // Wipe z lewej na prawą — prawa strona się odsłania
        const wipe = clamp((localTime - 0.5) / 1.5, 0, 1);
        const wipeEased = Easing.easeInOutCubic(wipe);

        // Tekst "TERAZ" i "PO ROZBUDOWIE"
        const labelOp = clamp((localTime - 1.8) / 0.5, 0, 1);

        return (
          <>
            {/* Base: nowa hala (cel — to ma zostać na końcu) */}
            <div style={{
              position: 'absolute', inset: 0,
              backgroundImage: 'url(assets/hala-exterior-1.png)',
              backgroundSize: 'cover',
              backgroundPosition: 'center',
              transform: `scale(${1.02 + localTime * 0.005})`,
            }} />

            {/* Warstwa: obecna szkoła — schówa się od lewej do prawej, odkrywając nową halę */}
            <div style={{
              position: 'absolute', inset: 0,
              clipPath: `polygon(${wipeEased * 100}% 0, 100% 0, 100% 100%, ${wipeEased * 100}% 100%)`,
              backgroundImage: 'url(assets/szkola-obecna.png)',
              backgroundSize: 'cover',
              backgroundPosition: 'center',
              filter: 'saturate(0.7) brightness(0.85)',
              transform: `scale(${1.02 + localTime * 0.004})`,
            }} />

            {/* Diagonal divider */}
            <div style={{
              position: 'absolute',
              top: 0, bottom: 0,
              left: `calc(${wipeEased * 100}% - 3px)`,
              width: 6,
              background: PALETTE.orange,
              boxShadow: '0 0 30px rgba(243,107,31,0.8)',
            }} />

            {/* Gradient overlay bottom */}
            <div style={{
              position: 'absolute', inset: 0,
              background: 'linear-gradient(180deg, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0.75) 100%)',
            }} />

            {/* DZIŚ label — na lewej stronie, widoczne dopóki stara szkoła jeszcze jest */}
            <div style={{
              position: 'absolute',
              left: 80, top: 140,
              opacity: labelOp * (wipeEased < 0.85 ? 1 : Math.max(0, (1 - wipeEased) / 0.15)),
              fontFamily: FONT,
              fontWeight: 800,
              color: '#fff',
              textTransform: 'uppercase',
            }}>
              <div style={{ fontSize: 18, letterSpacing: '0.3em', opacity: 0.7, marginBottom: 6 }}>
                Dziś
              </div>
              <div style={{ fontSize: 72, lineHeight: 0.95, letterSpacing: '-0.01em' }}>
                NASZA SZKOŁA
              </div>
              <div style={{ fontSize: 22, fontWeight: 500, opacity: 0.85, marginTop: 8, letterSpacing: '0.02em' }}>
                Dobra baza · gotowa, by rosła dalej
              </div>
            </div>

            {/* PO label — na prawej stronie, pojawia się po odkryciu nowej hali */}
            <div style={{
              position: 'absolute',
              right: 80, top: 140,
              opacity: clamp((localTime - 2.8) / 0.5, 0, 1),
              fontFamily: FONT,
              fontWeight: 800,
              color: '#fff',
              textAlign: 'right',
              textTransform: 'uppercase',
            }}>
              <div style={{ fontSize: 18, letterSpacing: '0.3em', color: PALETTE.orange, marginBottom: 6 }}>
                Po rozbudowie
              </div>
              <div style={{ fontSize: 72, lineHeight: 0.95, letterSpacing: '-0.01em' }}>
                NOWA HALA
              </div>
              <div style={{ fontSize: 22, fontWeight: 500, opacity: 0.85, marginTop: 8, letterSpacing: '0.02em' }}>
                878 m² · Dwie sale · Trybuny
              </div>
            </div>

            <Subtitles text="Wyobraź sobie, jaką szkołę przekazujemy naszym dzieciom." />
          </>
        );
      }}
    </Sprite>
  );
}

// ───────────────────────────── SCENA 4: HALA ZEWNĄTRZ (28-36s) ─────────────────────────────

function SceneExterior() {
  return (
    <Sprite start={28} end={36.2}>
      {({ localTime }) => {
        // Ken Burns
        const zoom = 1.0 + localTime * 0.025;
        const panX = localTime * 5;

        return (
          <>
            <div style={{
              position: 'absolute', inset: 0,
              backgroundImage: 'url(assets/hala-exterior-1.png)',
              backgroundSize: 'cover',
              backgroundPosition: `${50 - panX * 0.08}% 45%`,
              transform: `scale(${zoom})`,
            }} />
            {/* subtle bottom gradient */}
            <div style={{
              position: 'absolute', inset: 0,
              background: 'linear-gradient(180deg, rgba(0,0,0,0) 50%, rgba(0,0,0,0.75) 100%)',
            }} />

            {/* Headline */}
            <div style={{
              position: 'absolute',
              left: 120, bottom: 200,
              opacity: clamp((localTime - 0.3) / 0.5, 0, 1),
              transform: `translateY(${(1 - clamp((localTime - 0.3) / 0.5, 0, 1)) * 20}px)`,
            }}>
              <div style={{
                fontFamily: FONT_MONO, fontSize: 16,
                color: PALETTE.orange, letterSpacing: '0.2em',
                textTransform: 'uppercase', marginBottom: 12,
              }}>
                — Etap I · Nowa hala sportowa
              </div>
              <div style={{
                fontFamily: FONT, fontSize: 96, fontWeight: 800,
                color: '#fff', lineHeight: 0.95,
                letterSpacing: '-0.01em', textTransform: 'uppercase',
              }}>
                Nowoczesna hala<br/>
                <span style={{ color: PALETTE.orange }}>na miarę naszych dzieci.</span>
              </div>
            </div>

            {/* Stats chip na prawo */}
            <div style={{
              position: 'absolute',
              right: 120, top: 180,
              opacity: clamp((localTime - 2.5) / 0.5, 0, 1),
              display: 'flex', flexDirection: 'column', gap: 16,
            }}>
              <StatChip value="878" unit="m²" label="Powierzchnia" />
              <StatChip value="608" unit="m²" label="Boisko wielofunkcyjne" />
              <StatChip value="2" unit="sektory" label="Dzielone kurtyną" />
            </div>

            <Subtitles text="Koszykówka, siatkówka, piłka ręczna — wszystko w jednym miejscu." />
          </>
        );
      }}
    </Sprite>
  );
}

function StatChip({ value, unit, label }) {
  return (
    <div style={{
      background: 'rgba(255,255,255,0.95)',
      padding: '14px 22px',
      borderLeft: `4px solid ${PALETTE.orange}`,
      borderRadius: '2px',
      backdropFilter: 'blur(8px)',
      minWidth: 280,
    }}>
      <div style={{ display: 'flex', alignItems: 'baseline', gap: 8 }}>
        <span style={{
          fontFamily: FONT, fontWeight: 800, fontSize: 56,
          color: PALETTE.graphite, lineHeight: 1, letterSpacing: '-0.02em',
        }}>
          {value}
        </span>
        <span style={{
          fontFamily: FONT_BODY, fontWeight: 600, fontSize: 22,
          color: PALETTE.orange,
        }}>
          {unit}
        </span>
      </div>
      <div style={{
        fontFamily: FONT_BODY, fontSize: 13, fontWeight: 600,
        color: PALETTE.graphite, opacity: 0.7,
        textTransform: 'uppercase', letterSpacing: '0.1em',
        marginTop: 4,
      }}>
        {label}
      </div>
    </div>
  );
}

// ───────────────────────────── SCENA 5: HALA WNĘTRZE (36-44s) ─────────────────────────────

function SceneInterior() {
  return (
    <Sprite start={36} end={44.2}>
      {({ localTime }) => {
        const zoom = 1.0 + localTime * 0.02;

        // Crossfade między dwoma wnętrzami w połowie
        const crossfade = clamp((localTime - 4) / 1.2, 0, 1);

        return (
          <>
            <div style={{
              position: 'absolute', inset: 0,
              backgroundImage: 'url(assets/hala-interior-1.png)',
              backgroundSize: 'cover',
              backgroundPosition: 'center',
              transform: `scale(${zoom})`,
            }} />
            <div style={{
              position: 'absolute', inset: 0,
              opacity: crossfade,
              backgroundImage: 'url(assets/hala-interior-2.png)',
              backgroundSize: 'cover',
              backgroundPosition: 'center',
              transform: `scale(${zoom})`,
            }} />

            {/* Gradient bottom */}
            <div style={{
              position: 'absolute', inset: 0,
              background: 'linear-gradient(180deg, rgba(0,0,0,0.4) 0%, rgba(0,0,0,0) 30%, rgba(0,0,0,0) 60%, rgba(0,0,0,0.8) 100%)',
            }} />

            {/* Headline top-left */}
            <div style={{
              position: 'absolute',
              left: 120, top: 140,
              opacity: clamp((localTime - 0.3) / 0.5, 0, 1),
            }}>
              <div style={{
                fontFamily: FONT_MONO, fontSize: 16,
                color: PALETTE.orange, letterSpacing: '0.2em',
                textTransform: 'uppercase', marginBottom: 12,
              }}>
                — Wewnątrz
              </div>
              <div style={{
                fontFamily: FONT, fontSize: 76, fontWeight: 800,
                color: '#fff', lineHeight: 0.95,
                letterSpacing: '-0.01em', textTransform: 'uppercase',
              }}>
                Koszykówka. Siatkówka.<br/>
                <span style={{ color: PALETTE.orange }}>Piłka ręczna.</span>
              </div>
            </div>

            {/* Feature strip bottom */}
            <div style={{
              position: 'absolute',
              left: 120, right: 120, bottom: 120,
              display: 'flex', gap: 24,
              opacity: clamp((localTime - 2.5) / 0.5, 0, 1),
            }}>
              <FeatureTag text="TRYBUNY" delay={0} localTime={localTime} baseDelay={2.5} />
              <FeatureTag text="DWIE GRUPY JEDNOCZEŚNIE" delay={0.2} localTime={localTime} baseDelay={2.5} />
              <FeatureTag text="SALKA DLA KLAS I–III" delay={0.4} localTime={localTime} baseDelay={2.5} />
              <FeatureTag text="SCHRON" delay={0.6} localTime={localTime} baseDelay={2.5} />
            </div>

            <Subtitles text="Dwie grupy mogą ćwiczyć równocześnie — więcej czasu na ruch." />
          </>
        );
      }}
    </Sprite>
  );
}

function FeatureTag({ text, delay, localTime, baseDelay }) {
  const lt = localTime - baseDelay - delay;
  const op = clamp(lt / 0.4, 0, 1);
  return (
    <div style={{
      opacity: op,
      transform: `translateY(${(1 - op) * 12}px)`,
      padding: '12px 20px',
      background: 'rgba(243,107,31,0.95)',
      color: '#fff',
      fontFamily: FONT_BODY,
      fontSize: 15,
      fontWeight: 700,
      letterSpacing: '0.1em',
      textTransform: 'uppercase',
      borderRadius: 2,
    }}>
      {text}
    </div>
  );
}

// ───────────────────────────── SCENA 6: KORZYŚCI (44-52s) ─────────────────────────────

function BenefitRow({ num, title, desc, delay, localTime }) {
  const lt = localTime - delay;
  const op = clamp(lt / 0.5, 0, 1);
  const slide = (1 - Easing.easeOutCubic(op)) * 40;

  return (
    <div style={{
      opacity: op,
      transform: `translateX(${slide}px)`,
      display: 'flex', alignItems: 'flex-start', gap: 24,
      padding: '20px 0',
      borderTop: `1px solid rgba(30,35,41,0.15)`,
    }}>
      <div style={{
        fontFamily: FONT_MONO, fontSize: 13,
        color: PALETTE.orange, letterSpacing: '0.1em',
        paddingTop: 8, minWidth: 40,
      }}>
        {num}
      </div>
      <div style={{ flex: 1 }}>
        <div style={{
          fontFamily: FONT, fontSize: 42, fontWeight: 700,
          color: PALETTE.graphite, lineHeight: 1.05,
          letterSpacing: '-0.01em', textTransform: 'uppercase',
          marginBottom: 4,
        }}>
          {title}
        </div>
        <div style={{
          fontFamily: FONT_BODY, fontSize: 20,
          color: PALETTE.graphite, opacity: 0.7,
          lineHeight: 1.35,
        }}>
          {desc}
        </div>
      </div>
    </div>
  );
}

function SceneBenefits() {
  return (
    <Sprite start={44} end={52.2}>
      {({ localTime }) => {
        return (
          <>
            <div style={{ position: 'absolute', inset: 0, background: PALETTE.cream }} />

            {/* accent stripe */}
            <div style={{
              position: 'absolute', left: 0, top: 0, bottom: 0,
              width: 12, background: PALETTE.orange,
            }} />

            {/* thumbnail na prawo */}
            <div style={{
              position: 'absolute',
              right: 120, top: 140, bottom: 140,
              width: 540,
              backgroundImage: 'url(assets/hala-exterior-2.png)',
              backgroundSize: 'cover',
              backgroundPosition: 'center',
              borderRadius: 4,
              opacity: clamp((localTime - 0.2) / 0.6, 0, 1),
              transform: `scale(${0.96 + 0.04 * Easing.easeOutCubic(clamp(localTime / 0.8, 0, 1))})`,
              boxShadow: '0 30px 80px rgba(0,0,0,0.25)',
            }} />

            {/* kontent */}
            <div style={{
              position: 'absolute',
              left: 120, top: 120, width: 880,
            }}>
              <div style={{
                fontFamily: FONT_MONO, fontSize: 16,
                color: PALETTE.orange, letterSpacing: '0.2em',
                textTransform: 'uppercase', marginBottom: 12,
                opacity: clamp(localTime / 0.5, 0, 1),
              }}>
                — Dlaczego teraz
              </div>

              <div style={{
                fontFamily: FONT, fontSize: 72, fontWeight: 800,
                color: PALETTE.graphite, lineHeight: 0.95,
                letterSpacing: '-0.01em', textTransform: 'uppercase',
                marginBottom: 32,
                opacity: clamp((localTime - 0.2) / 0.5, 0, 1),
              }}>
                To nie tylko<br/>
                <span style={{ color: PALETTE.orange }}>sala gimnastyczna.</span>
              </div>

              <BenefitRow
                num="01"
                title="Wydarzenia szkolne i wiejskie"
                desc="Akademie, występy, zawody — nareszcie we własnym miejscu."
                delay={1.0}
                localTime={localTime}
              />
              <BenefitRow
                num="02"
                title="Popołudniu — dla mieszkańców"
                desc="Niezależne wejście od ul. Pszczyńskiej."
                delay={1.6}
                localTime={localTime}
              />
              <BenefitRow
                num="03"
                title="Budowa NIE zakłóca nauki"
                desc="Szkoła pracuje normalnie przez cały czas prac."
                delay={2.2}
                localTime={localTime}
              />
            </div>

            <Subtitles text="Hala to miejsce dla dzieci rano i dla całej wsi po południu." />
          </>
        );
      }}
    </Sprite>
  );
}

// ───────────────────────────── SCENA 7: CTA (52-60s) ─────────────────────────────

function SceneCTA() {
  return (
    <Sprite start={52} end={60}>
      {({ localTime }) => {
        // Ken Burns na zewnętrzu
        const zoom = 1.05 + localTime * 0.02;

        const titleOp = clamp((localTime - 0.2) / 0.5, 0, 1);
        const ctaOp = clamp((localTime - 1.5) / 0.5, 0, 1);
        const ctaScale = 0.9 + 0.1 * Easing.easeOutBack(ctaOp);

        // Pulsing arrow
        const pulse = 0.85 + 0.15 * Math.sin(localTime * 6);

        return (
          <>
            <div style={{
              position: 'absolute', inset: 0,
              backgroundImage: 'url(assets/hala-exterior-3.png)',
              backgroundSize: 'cover',
              backgroundPosition: 'center',
              transform: `scale(${zoom})`,
              filter: 'saturate(1.1)',
            }} />
            <div style={{
              position: 'absolute', inset: 0,
              background: `linear-gradient(180deg, rgba(30,35,41,0.2) 0%, rgba(30,35,41,0.85) 100%)`,
            }} />

            <div style={{
              position: 'absolute',
              left: '50%', top: '42%',
              transform: 'translate(-50%, -50%)',
              textAlign: 'center',
              width: '100%',
              opacity: titleOp,
            }}>
              <div style={{
                fontFamily: FONT_MONO, fontSize: 16,
                color: PALETTE.orange, letterSpacing: '0.3em',
                textTransform: 'uppercase', marginBottom: 20,
              }}>
                — Dla naszych dzieci
              </div>
              <div style={{
                fontFamily: FONT, fontSize: 130, fontWeight: 800,
                color: '#fff', lineHeight: 0.95,
                letterSpacing: '-0.01em', textTransform: 'uppercase',
              }}>
                Poprzyj<br/>
                <span style={{ color: PALETTE.orange }}>rozbudowę szkoły.</span>
              </div>
            </div>

            {/* CTA box */}
            <div style={{
              position: 'absolute',
              left: '50%', bottom: 140,
              transform: `translateX(-50%) scale(${ctaScale})`,
              opacity: ctaOp,
              background: PALETTE.orange,
              color: '#fff',
              padding: '24px 48px',
              fontFamily: FONT,
              fontWeight: 800,
              fontSize: 44,
              letterSpacing: '-0.01em',
              textTransform: 'uppercase',
              boxShadow: '0 20px 60px rgba(243,107,31,0.5)',
              borderRadius: 4,
              display: 'flex', alignItems: 'center', gap: 20,
            }}>
              <span style={{ opacity: pulse, fontSize: 40 }}>✎</span>
              Podpisz petycję
              <span style={{
                fontFamily: FONT_BODY, fontSize: 18, fontWeight: 500,
                opacity: 0.9, letterSpacing: '0.05em',
                borderLeft: '2px solid rgba(255,255,255,0.4)',
                paddingLeft: 20,
                textTransform: 'none',
                maxWidth: 280,
                lineHeight: 1.3,
              }}>
                na zebraniu rodziców
              </span>
            </div>

            <Subtitles
              text="Podpisz petycję na zebraniu rodziców. Dla naszych dzieci."
              bottom={40}
            />
          </>
        );
      }}
    </Sprite>
  );
}

// ───────────────────────────── GŁÓWNA KOMPOZYCJA ─────────────────────────────

function Video() {
  const t = useTime();
  const sec = Math.floor(t);

  return (
    <div
      data-screen-label={`${String(sec).padStart(2,'0')}s`}
      style={{ position: 'absolute', inset: 0, overflow: 'hidden', background: '#000' }}
    >
      <SceneHook />
      <SceneProblem />
      <SceneComparison />
      <SceneExterior />
      <SceneInterior />
      <SceneBenefits />
      <SceneCTA />

      <ProgressTape />
      <BrandBar />
      <TimecodeTicker />
    </div>
  );
}

Object.assign(window, { Video, PALETTE });
