"use client";
import { useRef, useState, useEffect } from "react";
import { motion, useScroll, useTransform, useSpring, useInView, AnimatePresence } from "framer-motion";

// ─── TOKENS ───────────────────────────────────────────────────
const G = "#C9A84C";
const GL = "#E8D5A3";
const GD = "#9A7A32";
const DARK = "#07070A";
const DARK2 = "#0D0D12";
const DARK3 = "#131318";

const goldText: React.CSSProperties = {
  background: `linear-gradient(135deg, ${G} 0%, ${GL} 45%, ${G} 100%)`,
  WebkitBackgroundClip: "text",
  WebkitTextFillColor: "transparent",
  backgroundClip: "text",
};
const GSHADOW = `0 0 0 1px ${G}22, 0 8px 48px rgba(201,168,76,0.18), 0 24px 80px rgba(0,0,0,0.55)`;
const GSHADOW_HOVER = `0 0 0 1px ${G}44, 0 8px 60px rgba(201,168,76,0.32), 0 32px 96px rgba(0,0,0,0.7)`;

// ─── DATA ─────────────────────────────────────────────────────
const pillars = [
  {
    id: "responsible-mining", title: "Responsible Mining", icon: "⛏️",
    accent: "#C9A84C",
    image: "/images/Image_fx (2).png",
    stat: { value: 100, suffix: "%", label: "Projects Assessed" },
    description: "Our approach to mining begins with responsibility. Every project is assessed through the lens of environmental impact, community wellbeing, and long-term sustainability before any operational activity commences.",
    points: [
      "Pre-development environmental and social impact assessments",
      "Progressive land rehabilitation and closure planning",
      "Responsible sourcing and supply chain management",
      "Compliance with international mining standards",
    ],
  },
  {
    id: "environment", title: "Environmental Stewardship", icon: "🌱",
    accent: "#C9A84C",
    image: "/images/Image_fx (1).png",
    stat: { value: 40, suffix: "%", label: "Emissions Reduced" },
    description: "We recognize our obligation to protect and preserve the natural environments in which we operate. Environmental awareness is not a compliance requirement — it is a fundamental operational commitment.",
    points: [
      "Water conservation and management systems",
      "Air quality monitoring and dust control",
      "Biodiversity protection and habitat preservation",
      "Waste management and recycling programs",
      "Energy efficiency and emissions reduction",
    ],
  },
  {
    id: "health-safety", title: "Health & Safety", icon: "🛡️",
    accent: "#C9A84C",
    image: "/images/blog_sustainability_report.png",
    stat: { value: 0, suffix: "", label: "Compromise on Safety" },
    description: "The safety of our workforce is non-negotiable. We operate under a zero-compromise safety culture with rigorous protocols, continuous training, and a commitment to industry-leading safety performance.",
    points: [
      "Comprehensive safety management systems",
      "Regular safety training and certification programs",
      "Incident investigation and prevention protocols",
      "Occupational health monitoring",
      "Emergency preparedness and response planning",
    ],
  },
  {
    id: "community", title: "Community Development", icon: "🤝",
    accent: "#C9A84C",
    image: "/Image_fx.png",
    stat: { value: 85, suffix: "%", label: "Local Employment" },
    description: "We believe mining operations should create shared value. Our community engagement approach focuses on meaningful partnerships, local employment, skills development, and social infrastructure investment.",
    points: [
      "Local hiring and skills development programs",
      "Community consultation and stakeholder engagement",
      "Social infrastructure investment",
      "Cultural heritage protection",
      "Local procurement and economic participation",
    ],
  },
  {
    id: "esg", title: "ESG Approach", icon: "📊",
    accent: "#C9A84C",
    image: "/images/20 (3).png",
    stat: { value: 3, suffix: "rd", label: "Party Verified" },
    description: "Our Environmental, Social, and Governance framework provides the structured accountability that guides our sustainability commitments and ensures transparent reporting to all stakeholders.",
    points: [
      "Structured ESG reporting and disclosure",
      "Board-level sustainability governance",
      "Stakeholder engagement and materiality assessment",
      "Third-party audits and verification",
      "Alignment with international sustainability frameworks",
    ],
  },
];

// ─── ANIMATED COUNTER ─────────────────────────────────────────
function Counter({ value, suffix }: { value: number; suffix: string }) {
  const ref = useRef(null);
  const inView = useInView(ref, { once: true });
  const [n, setN] = useState(0);
  useEffect(() => {
    if (!inView) return;
    if (value === 0) { setN(0); return; }
    let cur = 0;
    const step = (value / 1200) * 16;
    const t = setInterval(() => {
      cur = Math.min(cur + step, value);
      setN(Math.round(cur));
      if (cur >= value) clearInterval(t);
    }, 16);
    return () => clearInterval(t);
  }, [inView, value]);
  return <span ref={ref}>{n}{suffix}</span>;
}

// ─── SCROLL PROGRESS BAR ──────────────────────────────────────
function ScrollBar() {
  const { scrollYProgress } = useScroll();
  const scaleX = useSpring(scrollYProgress, { stiffness: 100, damping: 30 });
  return (
    <motion.div style={{
      position: "fixed", top: 0, left: 0, right: 0, height: 3,
      background: `linear-gradient(90deg, ${GD}, ${G}, ${GL})`,
      transformOrigin: "left", scaleX, zIndex: 999,
    }} />
  );
}
// ─── SIDE NAV ─────────────────────────────────────────────────
function SideNav({ active }: { active: number }) {
  return (
    <div className="side-nav" style={{
      position: "fixed", right: 28, top: "50%", transform: "translateY(-50%)",
      zIndex: 50, display: "flex", flexDirection: "column", gap: 14,
    }}>
      {pillars.map((p, i) => (
        <motion.button key={p.id}
          onClick={() => document.getElementById(p.id)?.scrollIntoView({ behavior: "smooth" })}
          whileHover="hov"
          style={{ display: "flex", alignItems: "center", gap: 10, background: "none", border: "none", cursor: "pointer", padding: 0 }}
        >
          <motion.span
            variants={{ hov: { opacity: 1, x: 0 }, default: { opacity: 0, x: 10 } }}
            initial="default"
            style={{
              fontSize: 11, whiteSpace: "nowrap", color: "rgba(255,255,255,0.55)",
              background: "rgba(13,13,18,0.88)", padding: "4px 10px",
              borderRadius: 4, border: "1px solid rgba(255,255,255,0.08)", backdropFilter: "blur(8px)",
              fontWeight: 500, letterSpacing: "0.06em",
            }}
          >{p.title}</motion.span>
          <motion.div
            animate={active === i
              ? { scale: 1.5, backgroundColor: p.accent, boxShadow: `0 0 8px ${p.accent}88` }
              : { scale: 1, backgroundColor: "transparent", boxShadow: "none" }
            }
            style={{
              width: 10, height: 10, borderRadius: "50%",
              border: `2px solid ${active === i ? p.accent : "rgba(201,168,76,0.35)"}`,
              flexShrink: 0, transition: "border-color 0.3s",
            }}
          />
        </motion.button>
      ))}
    </div>
  );
}

// ─── FLOATING ORBS ────────────────────────────────────────────
function FloatingOrbs() {
  return (
    <div style={{ position: "absolute", inset: 0, pointerEvents: "none", overflow: "hidden" }}>
      {[
        { x: "12%", y: "22%", w: 320, h: 320, color: `${G}09`, dur: 9 },
        { x: "72%", y: "14%", w: 200, h: 200, color: `${G}06`, dur: 12 },
        { x: "55%", y: "68%", w: 260, h: 260, color: `${G}07`, dur: 8 },
        { x: "8%", y: "75%", w: 140, h: 140, color: `${G}05`, dur: 14 },
      ].map((o, i) => (
        <motion.div key={i}
          animate={{ scale: [1, 1.2, 1], opacity: [0.6, 1, 0.6] }}
          transition={{ duration: o.dur, repeat: Infinity, ease: "easeInOut", delay: i * 1.5 }}
          style={{
            position: "absolute", left: o.x, top: o.y,
            width: o.w, height: o.h, borderRadius: "50%",
            background: `radial-gradient(circle, ${o.color} 0%, transparent 70%)`,
          }}
        />
      ))}
    </div>
  );
}

// ─── HERO ─────────────────────────────────────────────────────
function Hero() {
  const { scrollYProgress } = useScroll();
  const y = useTransform(scrollYProgress, [0, 0.4], [0, 180]);
  const op = useTransform(scrollYProgress, [0, 0.35], [1, 0]);
  const scale = useTransform(scrollYProgress, [0, 0.5], [1, 1.1]);

  return (
    <section className="resp-section" style={{ position: "relative", minHeight: "100vh", display: "flex", alignItems: "center", background: "#000", overflow: "hidden" }}>
      {/* Cinematic Background */}
      <motion.div style={{ position: "absolute", inset: 0, scale, opacity: 0.75 }}>
        <img 
          src="/images/sustainability_hero.png" 
          alt="Sustainability Landscape"
          style={{ width: "100%", height: "100%", objectFit: "cover" }}
        />
        <div style={{ position: "absolute", inset: 0, background: "linear-gradient(to bottom, transparent 40%, rgba(0,0,0,0.9))" }} />
        <div style={{ position: "absolute", inset: 0, background: "radial-gradient(circle at center, transparent, rgba(0,0,0,0.2))" }} />
      </motion.div>

      <FloatingOrbs />

      <motion.div className="resp-container" style={{ y, opacity: op, position: "relative", zIndex: 10, width: "100%", maxWidth: 1200, margin: "0 auto", padding: "0 64px" }}>
        {/* Breadcrumb */}
        <motion.div
          initial={{ opacity: 0, x: -20 }} animate={{ opacity: 1, x: 0 }}
          transition={{ duration: 0.7 }}
          style={{ display: "flex", alignItems: "center", gap: 12, marginBottom: 40 }}
        >
          <span style={{ width: 32, height: 1, background: G, display: "block" }} />
          <span style={{ fontSize: 10, textTransform: "uppercase", letterSpacing: "0.22em", fontWeight: 700, color: G }}>
            Crown Rock Minerals — Sustainability
          </span>
        </motion.div>

        {/* Editorial Headline */}
        <motion.h1
          initial={{ opacity: 0, y: 48 }} animate={{ opacity: 1, y: 0 }}
          transition={{ duration: 1.1, delay: 0.18 }}
          style={{
            fontFamily: "'Syncopate', sans-serif",
            fontSize: "clamp(36px, 6vw, 80px)",
            fontWeight: 700, lineHeight: 0.95, letterSpacing: "-0.03em",
            margin: "0 0 40px",
            textTransform: "uppercase",
            color: "#FFF"
          }}
        >
          RESPONSIBLE<br />
          <span style={goldText}>MINERAL</span><br />
          DEVELOPMENT
        </motion.h1>

        <div style={{ display: "flex", gap: 64, alignItems: "flex-start", flexWrap: "wrap" }}>
          <motion.p
            initial={{ opacity: 0, y: 28 }} animate={{ opacity: 1, y: 0 }}
            transition={{ duration: 0.9, delay: 0.4 }}
            style={{ fontSize: 18, lineHeight: 1.8, maxWidth: 520, color: "rgba(255,255,255,0.65)", fontWeight: 300, margin: 0 }}
          >
            At Crown Rock Minerals, sustainability is not an added layer. It is a core operational principle that informs how we assess, develop, and manage opportunity.
          </motion.p>

          {/* Scroll indicator */}
          <motion.div
            initial={{ opacity: 0 }} animate={{ opacity: 1 }}
            transition={{ delay: 1.2, duration: 0.8 }}
            style={{ display: "flex", alignItems: "center", gap: 14, paddingTop: 10 }}
          >
            <motion.div
              animate={{ y: [0, 8, 0] }}
              transition={{ duration: 1.6, repeat: Infinity, ease: "easeInOut" }}
              style={{ width: 24, height: 40, border: `1px solid ${G}40`, borderRadius: 12, display: "flex", justifyContent: "center", paddingTop: 6 }}
            >
              <div style={{ width: 4, height: 4, borderRadius: "50%", background: G }} />
            </motion.div>
            <span style={{ fontSize: 10, textTransform: "uppercase", letterSpacing: "0.2em", color: "rgba(255,255,255,0.4)" }}>Scroll to Explore</span>
          </motion.div>
        </div>
      </motion.div>

      {/* Grid lines */}
      <div style={{ position: "absolute", inset: 0, pointerEvents: "none" }}>
        {[...Array(5)].map((_, i) => (
          <motion.div key={i}
            initial={{ scaleX: 0 }} animate={{ scaleX: 1 }}
            transition={{ duration: 2.5, delay: 0.3 + i * 0.18, ease: "easeOut" }}
            style={{
              position: "absolute", top: `${20 + i * 15}%`, left: 0, right: 0,
              height: 1, transformOrigin: "left",
              background: `linear-gradient(90deg, ${G} 0%, transparent 100%)`,
              opacity: 0.05 + i * 0.01,
            }}
          />
        ))}
      </div>

      {/* Bottom edge fade */}
      <div style={{ position: "absolute", bottom: 0, left: 0, right: 0, height: 250, background: "linear-gradient(to top, #000, transparent)", zIndex: 5 }} />
    </section>
  );
}

// ─── STATS OVERVIEW ───────────────────────────────────────────
function Overview() {
  const ref = useRef(null);
  const isInView = useInView(ref, { once: true });

  const metrics = [
    { label: "Community Investment", val: 12.5, suf: "M+", icon: "🤝" },
    { label: "Water Recovery", val: 82, suf: "%", icon: "💧" },
    { label: "Rehabilitation Progress", val: 450, suf: "ha", icon: "🌱" },
    { label: "Safety Milestone", val: 2.1, suf: "M hrs", icon: "🛡️" },
  ];

  return (
    <section className="resp-section" ref={ref} style={{ background: "#000", position: "relative", padding: "160px 0", borderTop: "1px solid rgba(255,255,255,0.05)" }}>
      <div className="resp-container" style={{ maxWidth: 1200, margin: "0 auto", padding: "0 64px" }}>
        <div style={{ textAlign: "center", marginBottom: 100 }}>
          <motion.span 
            animate={isInView ? { opacity: 1, y: 0 } : { opacity: 0, y: 20 }}
            style={{ fontSize: 12, textTransform: "uppercase", letterSpacing: "0.4em", color: G, fontWeight: 700, display: "block", marginBottom: 24 }}
          >
            Institutional Performance
          </motion.span>
          <motion.h2 
            animate={isInView ? { opacity: 1, y: 0 } : { opacity: 0, y: 30 }}
            transition={{ delay: 0.1 }}
            style={{ fontFamily: "'Syncopate', sans-serif", fontSize: "clamp(32px, 5vw, 56px)", textTransform: "uppercase", lineHeight: 1, color: "#FFF", margin: 0 }}
          >
            MEASURING <span style={goldText}>IMPACT</span>
          </motion.h2>
        </div>

        <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(240px, 1fr))", gap: 32 }}>
          {metrics.map((m, i) => (
            <motion.div
              key={m.label}
              initial={{ opacity: 0, y: 40 }}
              animate={isInView ? { opacity: 1, y: 0 } : {}}
              transition={{ delay: i * 0.15 }}
              whileHover={{ y: -10, backgroundColor: "#000", borderColor: G, boxShadow: `0 20px 40px rgba(201,168,76,0.12)` }}
              style={{ 
                padding: "48px 40px", 
                background: "rgba(255,255,255,0.02)", 
                border: "1px solid rgba(255,255,255,0.08)", 
                borderRadius: 4,
                textAlign: "center",
                transition: "all 0.4s ease"
              }}
            >
              <div style={{ fontSize: 32, marginBottom: 24 }}>{m.icon}</div>
              <div style={{ fontFamily: "serif", fontSize: 44, fontWeight: 700, color: "#FFF", marginBottom: 8 }}>
                <Counter value={m.val} suffix={m.suf} />
              </div>
              <div style={{ fontSize: 11, textTransform: "uppercase", letterSpacing: "0.2em", color: "rgba(255,255,255,0.4)", fontWeight: 500 }}>
                {m.label}
              </div>
            </motion.div>
          ))}
        </div>
      </div>
    </section>
  );
}

// ─── PILLAR SECTION ───────────────────────────────────────────
function PillarSection({ pillar, index }: { pillar: any; index: number }) {
  const containerRef = useRef(null);
  const { scrollYProgress } = useScroll({ target: containerRef, offset: ["start end", "end start"] });
  const imgY = useTransform(scrollYProgress, [0, 1], [-80, 80]);
  const isEven = index % 2 === 0;

  return (
    <section
      ref={containerRef}
      id={pillar.id}
      className="resp-section"
      style={{
        background: isEven ? DARK : "#0A0A0A",
        position: "relative", overflow: "hidden",
      }}
    >
      <div className="split-flex" style={{ display: "flex", flexDirection: isEven ? "row" : "row-reverse", minHeight: "100vh", flexWrap: "wrap" }}>
        
        {/* Cinematic Image Side */}
        <div style={{ flex: "1 1 500px", height: "100vh", position: "relative", overflow: "hidden" }}>
          <motion.div style={{ position: "absolute", inset: "-15% 0", y: imgY }}>
            <img 
              src={pillar.image} 
              alt={pillar.title}
              style={{ width: "100%", height: "100%", objectFit: "cover" }}
            />
            <div style={{ position: "absolute", inset: 0, background: isEven 
              ? "linear-gradient(to right, transparent 60%, rgba(7,7,10,1) 100%)" 
              : "linear-gradient(to left, transparent 60%, rgba(10,10,10,1) 100%)" 
            }} />
          </motion.div>
          
          <div style={{ position: "absolute", bottom: 64, [isEven ? "left" : "right"]: 64, zIndex: 10 }}>
            <motion.div
              initial={{ scaleX: 0 }}
              whileInView={{ scaleX: 1 }}
              transition={{ duration: 1.2 }}
              style={{ height: 1, background: G, transformOrigin: isEven ? "left" : "right", marginBottom: 16 }}
            />
            <span style={{ fontSize: 12, textTransform: "uppercase", letterSpacing: "0.4em", color: "#FFF", fontWeight: 700 }}>
              {String(index + 1).padStart(2, "0")} / 05 Pillar
            </span>
          </div>
        </div>

        {/* Content Side */}
        <div className="resp-container resp-padding" style={{ flex: "1 1 500px", display: "flex", alignItems: "center", padding: "100px 80px" }}>
          <motion.div
            initial={{ opacity: 0, x: isEven ? 60 : -60 }}
            whileInView={{ opacity: 1, x: 0 }}
            transition={{ duration: 1, ease: "easeOut" }}
            viewport={{ once: true }}
            style={{ maxWidth: 540 }}
          >
            <div style={{ display: "flex", alignItems: "center", gap: 20, marginBottom: 32 }}>
              <span style={{ fontSize: 44 }}>{pillar.icon}</span>
              <div style={{ height: 1, flex: 1, background: `linear-gradient(90deg, ${G}50, transparent)` }} />
            </div>

            <h2 style={{
              fontFamily: "'Syncopate', sans-serif", fontWeight: 700,
              fontSize: "clamp(32px, 3.8vw, 52px)", lineHeight: 1.05,
              letterSpacing: "-0.04em", color: "#FFF",
              margin: "0 0 28px", textTransform: "uppercase"
            }}>
              {pillar.title}
            </h2>

            <p style={{ fontSize: 18, lineHeight: 1.85, color: "rgba(255,255,255,0.45)", marginBottom: 48, fontWeight: 300 }}>
              {pillar.description}
            </p>

            {/* Premium Black Hover Card */}
            <motion.div
              whileHover={{ 
                backgroundColor: "#000000",
                borderColor: G,
                y: -10,
                boxShadow: `0 30px 60px rgba(0,0,0,0.8), 0 0 0 1px ${G}33`
              }}
              style={{
                background: "rgba(255,255,255,0.02)",
                border: "1px solid rgba(255,255,255,0.08)",
                borderRadius: 4, padding: "48px 40px",
                transition: "all 0.5s cubic-bezier(0.23, 1, 0.32, 1)",
                position: "relative",
              }}
            >
              <div style={{ display: "flex", alignItems: "center", gap: 20, marginBottom: 32 }}>
                <div style={{
                  fontSize: 36, fontWeight: 700, color: G, fontFamily: "serif"
                }}>
                  <Counter value={pillar.stat.value} suffix={pillar.stat.suffix} />
                </div>
                <div style={{ fontSize: 11, textTransform: "uppercase", letterSpacing: "0.2em", color: "rgba(255,255,255,0.3)", fontWeight: 700 }}>
                  {pillar.stat.label}
                </div>
              </div>

              <div style={{ width: "100%", height: 1, background: "rgba(255,255,255,0.06)", marginBottom: 32 }} />

              <div style={{ display: "grid", gap: 20 }}>
                {pillar.points.map((p: string, i: number) => (
                  <div key={i} style={{ display: "flex", alignItems: "flex-start", gap: 16 }}>
                    <div style={{ width: 6, height: 6, borderRadius: "50%", background: G, marginTop: 8, flexShrink: 0 }} />
                    <span style={{ fontSize: 15, lineHeight: 1.6, color: "rgba(255,255,255,0.65)" }}>{p}</span>
                  </div>
                ))}
              </div>

              {/* Decorative corner */}
              <div style={{ position: "absolute", bottom: 0, right: 0, width: 40, height: 40, background: `linear-gradient(135deg, transparent 50%, ${G}10 50%)`, borderRadius: "0 0 4px 0" }} />
            </motion.div>
          </motion.div>
        </div>
      </div>
    </section>
  );
}

// ─── CTA ──────────────────────────────────────────────────────
function CTA() {
  return (
    <section className="resp-section" style={{ background: "#000", position: "relative", padding: "160px 0", overflow: "hidden" }}>
      {/* Decorative Elements */}
      <div style={{ position: "absolute", top: 0, left: "50%", transform: "translateX(-50%)", width: "100%", height: 1, background: `linear-gradient(90deg, transparent, ${G}40, transparent)` }} />
      
      <div className="resp-container" style={{ maxWidth: 800, margin: "0 auto", padding: "0 64px", textAlign: "center", position: "relative", zIndex: 1 }}>
        <motion.div
          initial={{ opacity: 0, y: 20 }}
          whileInView={{ opacity: 1, y: 0 }}
          viewport={{ once: true }}
          style={{ display: "flex", alignItems: "center", justifyContent: "center", gap: 20, marginBottom: 32 }}
        >
          <span style={{ width: 40, height: 1, background: G }} />
          <span style={{ fontSize: 11, textTransform: "uppercase", letterSpacing: "0.3em", fontWeight: 700, color: G }}>Strategic Engagement</span>
          <span style={{ width: 40, height: 1, background: G }} />
        </motion.div>

        <motion.h2
          initial={{ opacity: 0, y: 30 }}
          whileInView={{ opacity: 1, y: 0 }}
          viewport={{ once: true }}
          transition={{ duration: 0.8, delay: 0.1 }}
          style={{
            fontFamily: "'Syncopate', sans-serif", fontWeight: 700,
            fontSize: "clamp(32px, 5vw, 64px)", lineHeight: 1.1,
            letterSpacing: "-0.04em", color: "#FFF",
            margin: "0 0 32px", textTransform: "uppercase"
          }}
        >
          SHAPING A <span style={goldText}>RESPONSIBLE</span> FUTURE
        </motion.h2>

        <motion.p
          initial={{ opacity: 0, y: 20 }}
          whileInView={{ opacity: 1, y: 0 }}
          viewport={{ once: true }}
          transition={{ duration: 0.7, delay: 0.2 }}
          style={{ fontSize: 18, lineHeight: 1.8, color: "rgba(255,255,255,0.4)", margin: "0 0 56px", fontWeight: 300 }}
        >
          Engage with our strategic teams to explore how Crown Rock Minerals is redefining the standards of African mining through innovation and accountability.
        </motion.p>

        <motion.div
          initial={{ opacity: 0, y: 20 }}
          whileInView={{ opacity: 1, y: 0 }}
          viewport={{ once: true }}
          transition={{ duration: 0.6, delay: 0.3 }}
          style={{ display: "flex", gap: 24, justifyContent: "center", flexWrap: "wrap" }}
        >
          {[
            { label: "Partner With Us", dark: true },
            { label: "ESG Data Room", dark: false },
          ].map((b: { label: string, dark: boolean }) => (
            <motion.button key={b.label}
              whileHover={{ scale: 1.05, backgroundColor: b.dark ? "#FFF" : "rgba(255,255,255,0.05)" }}
              whileTap={{ scale: 0.98 }}
              style={{
                display: "inline-flex", alignItems: "center", gap: 12,
                padding: "18px 44px",
                background: b.dark ? G : "transparent",
                border: `1px solid ${b.dark ? "transparent" : G}`,
                color: b.dark ? "#000" : G,
                fontWeight: 800, fontSize: 12, textTransform: "uppercase",
                letterSpacing: "0.2em", cursor: "pointer",
                transition: "all 0.3s ease",
              }}
            >
              {b.label}
              <svg width="16" height="16" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={3}>
                <path strokeLinecap="round" strokeLinejoin="round" d="M17 8l4 4m0 0l-4 4m4-4H3" />
              </svg>
            </motion.button>
          ))}
        </motion.div>
      </div>

      {/* Background Glow */}
      <div style={{ position: "absolute", bottom: "-20%", left: "50%", transform: "translateX(-50%)", width: "60%", height: "40%", background: `radial-gradient(ellipse at center, ${G}15 0%, transparent 70%)`, pointerEvents: "none" }} />
    </section>
  );
}

// ─── ROOT ─────────────────────────────────────────────────────
export default function SustainabilityPage() {
  const [active, setActive] = useState(0);

  useEffect(() => {
    const obs = pillars.map((p: any, i: number) => {
      const el = document.getElementById(p.id);
      if (!el) return null;
      const o = new IntersectionObserver(
        ([e]) => { if (e.isIntersecting) setActive(i); },
        { threshold: 0.38 }
      );
      o.observe(el);
      return o;
    });
    return () => obs.forEach((o: any) => o?.disconnect());
  }, []);

  return (
    <div style={{ fontFamily: "'Helvetica Neue', Helvetica, Arial, sans-serif", background: DARK, margin: 0, padding: 0 }}>
      <style>{`
        @media(max-width: 1024px) {
          .resp-section { padding: 80px 0 !important; }
          .resp-container { padding: 0 24px !important; }
          .resp-padding { padding: 60px 24px !important; }
          .split-flex { flex-direction: column !important; }
          .side-nav { display: none !important; }
        }
      `}</style>
      <ScrollBar />
      <SideNav active={active} />
      <Hero />
      <Overview />
      {pillars.map((p, i) => <PillarSection key={p.id} pillar={p} index={i} />)}
      <CTA />
    </div>
  );
}
