/* global React, useLang, useCart, PCButton, PCBadge, Eyebrow, Logo, Reveal */
const { useState: useSh, useEffect: useEh } = React;

// =========================================================
// HEM (landing page) sections
// =========================================================

// ----- HERO with 3 layout variants -----
function Hero({ layout = "split" }) {
  const { t } = useLang();
  const { add, setOpen } = useCart();
  const onShop = () => { setOpen(true); };

  if (layout === "fullbleed") return <HeroFullbleed t={t} onShop={onShop} />;
  if (layout === "editorial") return <HeroEditorial t={t} onShop={onShop} />;
  return <HeroSplit t={t} onShop={onShop} />;
}

function HeroSplit({ t, onShop }) {
  return (
    <section style={{ position: "relative", overflow: "hidden" }}>
      <div style={{
        maxWidth: 1280, margin: "0 auto", padding: "72px 32px 80px",
        display: "grid", gridTemplateColumns: "1.05fr 1fr", gap: 64, alignItems: "center",
      }}>
        <Reveal>
          <Eyebrow>{t.hero.eyebrow}</Eyebrow>
          <h1 style={{
            fontFamily: "var(--font-display)", fontSize: "clamp(64px, 8vw, 104px)",
            lineHeight: 0.96, color: "var(--skog)", letterSpacing: "-0.02em", maxWidth: 640,
          }}>
            {t.hero.titleA}{" "}
            <span style={{ fontStyle: "italic", color: "var(--sval-500)" }}>{t.hero.titleB}</span>
          </h1>
          <p style={{
            fontFamily: "var(--font-display)", fontStyle: "italic", fontSize: 22,
            color: "var(--sval-700)", marginTop: 18, letterSpacing: "-0.005em",
          }}>{t.hero.tagline}</p>
          <p style={{
            fontSize: 19, lineHeight: "30px", color: "var(--skog-mjuk)",
            marginTop: 24, maxWidth: 480,
          }}>{t.hero.body}</p>
          <div style={{ display: "flex", gap: 14, marginTop: 36, alignItems: "center", flexWrap: "wrap" }}>
            <PCButton onClick={onShop} size="lg" icon={<i className="ph ph-arrow-right" />}>{t.hero.cta1}</PCButton>
            <PCButton href="#how" variant="tertiary">{t.hero.cta2} →</PCButton>
          </div>
          <HeroStats t={t} />
        </Reveal>
        <Reveal delay={140}>
          <div style={{ position: "relative" }}>
            <div style={{
              background: "var(--linne-djup)", borderRadius: "var(--r-5)",
              aspectRatio: "4 / 5", overflow: "hidden", position: "relative",
              boxShadow: "var(--shadow-3)",
            }}>
              <img src="assets/photo-tesla-cupholder.jpeg" alt="Portacooler i Tesla-mittkonsolen"
                   style={{ width: "100%", height: "100%", objectFit: "cover" }} />
              <div style={{ position: "absolute", inset: 0, background: "linear-gradient(180deg, rgba(246,241,230,0) 60%, rgba(246,241,230,0.22))" }} />
            </div>
            <FloatingChip t={t} />
            <SpecChip />
          </div>
        </Reveal>
      </div>
    </section>
  );
}

function HeroEditorial({ t, onShop }) {
  return (
    <section style={{ position: "relative", overflow: "hidden", paddingTop: 64 }}>
      <div style={{ maxWidth: 1280, margin: "0 auto", padding: "0 32px", textAlign: "center" }}>
        <Reveal>
          <Eyebrow>{t.hero.eyebrow}</Eyebrow>
          <h1 style={{
            fontFamily: "var(--font-display)", fontSize: "clamp(72px, 11vw, 168px)",
            lineHeight: 0.92, color: "var(--skog)", letterSpacing: "-0.025em",
            maxWidth: 1100, margin: "0 auto",
          }}>
            {t.hero.titleA}{" "}
            <span style={{ fontStyle: "italic", color: "var(--sval-500)" }}>{t.hero.titleB}</span>
          </h1>
          <p style={{
            fontFamily: "var(--font-display)", fontStyle: "italic", fontSize: 24,
            color: "var(--sval-700)", marginTop: 22,
          }}>{t.hero.tagline}</p>
          <p style={{
            fontSize: 19, lineHeight: "30px", color: "var(--skog-mjuk)",
            marginTop: 24, maxWidth: 580, marginLeft: "auto", marginRight: "auto",
          }}>{t.hero.body}</p>
          <div style={{ display: "inline-flex", gap: 14, marginTop: 36, alignItems: "center", flexWrap: "wrap", justifyContent: "center" }}>
            <PCButton onClick={onShop} size="lg" icon={<i className="ph ph-arrow-right" />}>{t.hero.cta1}</PCButton>
            <PCButton href="#how" variant="tertiary">{t.hero.cta2} →</PCButton>
          </div>
        </Reveal>
        <Reveal delay={160}>
          <div style={{
            marginTop: 64, position: "relative",
            borderRadius: "var(--r-5)", overflow: "hidden",
            aspectRatio: "16 / 8", background: "var(--linne-djup)",
            boxShadow: "var(--shadow-3)",
          }}>
            <img src="assets/photo-tesla-cupholder.jpeg" alt=""
                 style={{ width: "100%", height: "100%", objectFit: "cover", objectPosition: "center 38%" }} />
            <div style={{ position: "absolute", inset: 0, background: "linear-gradient(180deg, rgba(246,241,230,0) 70%, rgba(246,241,230,0.35))" }} />
            <div style={{ position: "absolute", bottom: 24, left: 24, right: 24, display: "flex", justifyContent: "space-between", alignItems: "end" }}>
              <SpecRow t={t} dark />
            </div>
          </div>
        </Reveal>
      </div>
    </section>
  );
}

function HeroFullbleed({ t, onShop }) {
  return (
    <section style={{ position: "relative", overflow: "hidden", minHeight: "min(85vh, 760px)" }}>
      <img src="assets/photo-tesla-cupholder.jpeg" alt=""
           style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", objectPosition: "center 42%" }} />
      {/* Warm protection gradient — top + bottom for legibility */}
      <div style={{
        position: "absolute", inset: 0,
        background: "linear-gradient(180deg, rgba(27,42,34,0.35) 0%, rgba(27,42,34,0.0) 30%, rgba(27,42,34,0.0) 55%, rgba(27,42,34,0.7) 100%)",
      }} />
      <div style={{
        position: "relative", maxWidth: 1280, margin: "0 auto", padding: "120px 32px 80px",
        minHeight: "min(85vh, 760px)", display: "flex", flexDirection: "column", justifyContent: "end",
        color: "var(--linne)",
      }}>
        <Reveal>
          <Eyebrow color="rgba(246,241,230,0.85)">{t.hero.eyebrow}</Eyebrow>
          <h1 style={{
            fontFamily: "var(--font-display)", fontSize: "clamp(64px, 9vw, 128px)",
            lineHeight: 0.94, color: "var(--linne)", letterSpacing: "-0.025em", maxWidth: 820,
          }}>
            {t.hero.titleA}{" "}
            <span style={{ fontStyle: "italic", color: "var(--sval-300)" }}>{t.hero.titleB}</span>
          </h1>
          <p style={{
            fontSize: 19, lineHeight: "30px", color: "rgba(246,241,230,0.85)",
            marginTop: 24, maxWidth: 480,
          }}>{t.hero.body}</p>
          <div style={{ display: "flex", gap: 14, marginTop: 36, alignItems: "center", flexWrap: "wrap" }}>
            <PCButton onClick={onShop} size="lg" variant="onDark" icon={<i className="ph ph-arrow-right" />}>{t.hero.cta1}</PCButton>
            <PCButton href="#how" variant="secondaryDark">{t.hero.cta2}</PCButton>
          </div>
        </Reveal>
      </div>
    </section>
  );
}

function HeroStats({ t }) {
  const stats = [
    { v: "+4 °C", l: t.hero.stat1L },
    { v: "USB-C", l: t.hero.stat2L },
    { v: "720 g", l: t.hero.stat3L },
  ];
  return (
    <div style={{ display: "flex", gap: 28, marginTop: 56, alignItems: "center", flexWrap: "wrap" }}>
      {stats.map((s, i) => (
        <React.Fragment key={s.l}>
          {i > 0 && <div style={{ width: 1, height: 40, background: "var(--border-soft)" }} />}
          <div style={{ display: "flex", flexDirection: "column", gap: 4 }}>
            <span style={{ fontFamily: "var(--font-display)", fontSize: 36, color: "var(--skog)", lineHeight: 1 }}>{s.v}</span>
            <span style={{ fontSize: 12, color: "var(--skog-bleek)", letterSpacing: "0.04em" }}>{s.l}</span>
          </div>
        </React.Fragment>
      ))}
    </div>
  );
}

function SpecRow({ t, dark }) {
  const c = dark ? "var(--linne)" : "var(--skog)";
  const sub = dark ? "rgba(246,241,230,0.7)" : "var(--skog-bleek)";
  const stats = [
    { v: "+4 °C", l: t.hero.stat1L },
    { v: "USB-C", l: t.hero.stat2L },
    { v: "720 g", l: t.hero.stat3L },
  ];
  return (
    <div style={{ display: "flex", gap: 36, alignItems: "end" }}>
      {stats.map(s => (
        <div key={s.l} style={{ display: "flex", flexDirection: "column", gap: 2 }}>
          <span style={{ fontFamily: "var(--font-display)", fontSize: 32, color: c, lineHeight: 1 }}>{s.v}</span>
          <span style={{ fontSize: 11, color: sub, letterSpacing: "0.06em", textTransform: "uppercase" }}>{s.l}</span>
        </div>
      ))}
    </div>
  );
}

function FloatingChip({ t }) {
  return (
    <div style={{
      position: "absolute", bottom: 32, left: -28,
      background: "var(--linne)", borderRadius: "var(--r-4)", padding: "14px 18px",
      boxShadow: "var(--shadow-3)", border: "1px solid var(--border-soft)",
      display: "flex", alignItems: "center", gap: 12, maxWidth: 300,
    }}>
      <div style={{ width: 40, height: 40, borderRadius: 999, background: "var(--sval-100)", display: "flex", alignItems: "center", justifyContent: "center", color: "var(--sval-700)" }}>
        <i className="ph ph-car" style={{ fontSize: 20 }} />
      </div>
      <div>
        <div style={{ fontSize: 13, fontWeight: 600, color: "var(--skog)" }}>{t.hero.chipTitle}</div>
        <div style={{ fontSize: 12, color: "var(--skog-bleek)" }}>{t.hero.chipBody}</div>
      </div>
    </div>
  );
}

function SpecChip() {
  return (
    <div style={{
      position: "absolute", top: 28, right: -20,
      background: "var(--skog)", color: "var(--linne)", borderRadius: "var(--r-pill)",
      padding: "8px 16px", boxShadow: "var(--shadow-3)",
      display: "inline-flex", alignItems: "center", gap: 8,
      fontFamily: "var(--font-mono)", fontSize: 12, letterSpacing: "0.02em",
    }}>
      <span style={{ width: 6, height: 6, borderRadius: 999, background: "var(--sol-500)", boxShadow: "0 0 12px var(--sol-500)" }} />
      <span>18 W · USB-C PD</span>
    </div>
  );
}

// ----- Trust row -----
function TrustRow() {
  const { t } = useLang();
  const logos = ["Allt om Bil", "SLU", "KTH Materialteknik", "Naturkompaniet", "XXL Sport", "Bilprovningen"];
  return (
    <section style={{ borderTop: "1px solid var(--border-soft)", borderBottom: "1px solid var(--border-soft)", background: "var(--linne-djup)" }}>
      <div style={{
        maxWidth: 1280, margin: "0 auto", padding: "22px 32px",
        display: "flex", alignItems: "center", gap: 40, justifyContent: "space-between", flexWrap: "wrap",
      }}>
        <span style={{ fontSize: 12, fontWeight: 600, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--skog-bleek)", whiteSpace: "nowrap" }}>
          {t.trust.label}
        </span>
        {logos.map(l => (
          <span key={l} style={{
            fontFamily: "var(--font-display)", fontSize: 19, fontStyle: "italic",
            color: "var(--skog-mjuk)", opacity: 0.55, letterSpacing: "-0.01em",
            whiteSpace: "nowrap",
          }}>{l}</span>
        ))}
      </div>
    </section>
  );
}

// ----- How it works -----
function HowItWorks() {
  const { t } = useLang();
  const icons = ["ph-wrench", "ph-usb", "ph-thermometer-cold"];
  return (
    <section id="how" style={{ padding: "112px 32px", background: "var(--sval-100)", position: "relative", overflow: "hidden" }}>
      <div style={{
        position: "absolute", inset: 0, opacity: 0.4, pointerEvents: "none",
        backgroundImage: "url(assets/wave.svg)", backgroundSize: "420px", backgroundRepeat: "repeat",
        maskImage: "linear-gradient(180deg, transparent, black 30%, black 70%, transparent)",
      }} />
      <div style={{ maxWidth: 1280, margin: "0 auto", position: "relative" }}>
        <Reveal>
          <div style={{ textAlign: "center", maxWidth: 720, margin: "0 auto 64px" }}>
            <Eyebrow>{t.how.eyebrow}</Eyebrow>
            <h2 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(40px, 5vw, 60px)", color: "var(--skog)", letterSpacing: "-0.01em", lineHeight: 1.04 }}>
              <span style={{ fontStyle: "italic", color: "var(--sval-700)" }}>{t.how.title1}</span>
              {t.how.title2}
            </h2>
          </div>
        </Reveal>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 24 }}>
          {t.how.steps.map((s, i) => (
            <Reveal key={s.n} delay={i * 100}>
              <div style={{
                background: "var(--linne)", borderRadius: "var(--r-4)", padding: 32,
                border: "1px solid var(--border-soft)", height: "100%",
                transition: "transform 200ms var(--ease-out-warm), box-shadow 200ms var(--ease-out-warm)",
              }}
              onMouseEnter={e => { e.currentTarget.style.transform = "translateY(-4px)"; e.currentTarget.style.boxShadow = "var(--shadow-3)"; }}
              onMouseLeave={e => { e.currentTarget.style.transform = "translateY(0)"; e.currentTarget.style.boxShadow = "none"; }}
              >
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 28 }}>
                  <span style={{ fontFamily: "var(--font-mono)", fontSize: 13, color: "var(--skog-bleek)", letterSpacing: "0.08em" }}>{s.n}</span>
                  <div style={{ width: 48, height: 48, borderRadius: 999, background: "var(--sval-50)", display: "inline-flex", alignItems: "center", justifyContent: "center", color: "var(--sval-700)" }}>
                    <i className={`ph ${icons[i]}`} style={{ fontSize: 24 }} />
                  </div>
                </div>
                <h3 style={{ fontFamily: "var(--font-body)", fontSize: 22, fontWeight: 600, color: "var(--skog)", marginBottom: 10 }}>
                  {s.t}
                </h3>
                <p style={{ fontSize: 15, lineHeight: "24px", color: "var(--skog-mjuk)" }}>{s.b}</p>
              </div>
            </Reveal>
          ))}
        </div>
      </div>
    </section>
  );
}

// ----- Products -----
const PRODUCTS = [
  { id: "small",    key: "small",    name: "Small",    price: 990,  volume: "0,35", weight: 520,  watt: 15 },
  { id: "allround", key: "allround", name: "Allround", price: 1290, volume: "0,5",  weight: 720,  watt: 18, href: "allround.html" },
  { id: "pro",      key: "pro",      name: "Pro",      price: 2490, volume: "1,0",  weight: 1180, watt: 32 },
];

function ProductsSection() {
  const { t } = useLang();
  const { add } = useCart();
  return (
    <section id="products" style={{ padding: "112px 32px" }}>
      <div style={{ maxWidth: 1280, margin: "0 auto" }}>
        <Reveal>
          <div style={{ display: "flex", alignItems: "end", justifyContent: "space-between", marginBottom: 56, gap: 32, flexWrap: "wrap" }}>
            <div style={{ maxWidth: 720 }}>
              <Eyebrow>{t.products.eyebrow}</Eyebrow>
              <h2 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(40px, 4.5vw, 56px)", color: "var(--skog)", letterSpacing: "-0.01em", lineHeight: 1.02 }}>
                {t.products.title}
              </h2>
            </div>
            <a href="allround.html" style={{ fontSize: 15, fontWeight: 600, color: "var(--sval-500)", whiteSpace: "nowrap" }}>
              {t.products.all} →
            </a>
          </div>
        </Reveal>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 24 }}>
          {PRODUCTS.map((p, i) => {
            const c = t.products.cards[p.key];
            return (
              <Reveal key={p.id} delay={i * 90}>
                <ProductCard p={p} c={c} t={t} onAdd={() => add({
                  id: p.id, name: `Portacooler ${p.name}`, price: p.price, volume: p.volume,
                  image: "assets/illu-product.svg", color: "Blå",
                })} />
              </Reveal>
            );
          })}
        </div>
      </div>
    </section>
  );
}

function ProductCard({ p, c, t, onAdd }) {
  const [hover, setHover] = useSh(false);
  const stock = p.id === "pro" ? "low" : "in-stock";
  return (
    <article
      onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)}
      style={{
        background: "#fff", border: "1px solid var(--border-soft)", borderRadius: "var(--r-4)",
        overflow: "hidden", display: "flex", flexDirection: "column",
        transition: "transform 220ms var(--ease-out-warm), box-shadow 220ms var(--ease-out-warm)",
        transform: hover ? "translateY(-6px)" : "translateY(0)",
        boxShadow: hover ? "var(--shadow-3)" : "var(--shadow-1)",
      }}>
      <a href={p.href || "allround.html"} style={{ padding: 16, textDecoration: "none", display: "block" }}>
        <div style={{
          aspectRatio: "4 / 3", borderRadius: "var(--r-3)",
          background: p.id === "allround" ? "var(--sval-50)" : "var(--linne-djup)",
          display: "flex", alignItems: "center", justifyContent: "center", overflow: "hidden",
          position: "relative",
        }}>
          {c.tag && (
            <div style={{ position: "absolute", top: 14, left: 14 }}>
              <PCBadge tone={p.id === "allround" ? "best" : p.id === "pro" ? "b2b" : "new"}>{c.tag}</PCBadge>
            </div>
          )}
          <img src="assets/product-render.png" alt={`Portacooler ${p.name}`}
               style={{
                 height: p.id === "small" ? "62%" : p.id === "allround" ? "76%" : "84%",
                 objectFit: "contain", transition: "transform 320ms var(--ease-out-warm)",
                 transform: hover ? "scale(1.04) rotate(-2deg)" : "scale(1) rotate(0deg)",
               }} />
        </div>
      </a>
      <div style={{ padding: "0 24px 24px", display: "flex", flexDirection: "column", gap: 12, flex: 1 }}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
          <PCBadge tone={stock}>{stock === "in-stock" ? c.stock : c.stock}</PCBadge>
          <span style={{ fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--skog-bleek)" }}>
            {p.volume} L · {p.weight} g
          </span>
        </div>
        <div>
          <h3 style={{ fontFamily: "var(--font-body)", fontWeight: 600, fontSize: 22, color: "var(--skog)", letterSpacing: "-0.005em" }}>
            Portacooler {p.name}
          </h3>
          <p style={{ fontSize: 14, color: "var(--skog-mjuk)", marginTop: 4, lineHeight: "20px" }}>{c.t}</p>
        </div>
        <div style={{ display: "flex", gap: 12, fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--skog-mjuk)", padding: "10px 12px", background: "var(--linne)", borderRadius: "var(--r-2)" }}>
          <span>USB-C</span><span style={{ opacity: 0.4 }}>·</span>
          <span>{p.watt} W</span><span style={{ opacity: 0.4 }}>·</span>
          <span>+4 °C</span>
        </div>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginTop: 6 }}>
          <span style={{ fontFamily: "var(--font-display)", fontSize: 30, color: "var(--skog)" }}>
            {p.price.toLocaleString("sv-SE")}<span style={{ fontSize: 14, fontFamily: "var(--font-body)", color: "var(--skog-bleek)", marginLeft: 4 }}>kr</span>
          </span>
          <PCButton size="sm" onClick={onAdd} icon={<i className="ph ph-plus" />}>{t.products.lagg}</PCButton>
        </div>
      </div>
    </article>
  );
}

// ----- Use cases -----
function UseCases() {
  const { t } = useLang();
  const cases = [
    { icon: "ph-car",            illu: "assets/illu-car.svg",      key: 0 },
    { icon: "ph-picnic-basket",  illu: "assets/illu-picnic.svg",   key: 1 },
    { icon: "ph-flask",          illu: "assets/illu-lab.svg",      key: 2 },
    { icon: "ph-backpack",       illu: "assets/illu-backpack.svg", key: 3 },
  ];
  return (
    <section style={{ padding: "112px 32px" }}>
      <div style={{ maxWidth: 1280, margin: "0 auto" }}>
        <Reveal>
          <Eyebrow>{t.cases.eyebrow}</Eyebrow>
          <h2 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(40px, 4.5vw, 56px)", color: "var(--skog)", letterSpacing: "-0.01em", marginBottom: 56, maxWidth: 880, lineHeight: 1.04 }}>
            {t.cases.title}
          </h2>
        </Reveal>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 16 }}>
          {cases.map((c, i) => {
            const item = t.cases.items[c.key];
            return (
              <Reveal key={c.key} delay={i * 80}>
                <UseCaseCard c={c} item={item} />
              </Reveal>
            );
          })}
        </div>
      </div>
    </section>
  );
}

function UseCaseCard({ c, item }) {
  const [hover, setHover] = useSh(false);
  return (
    <a href="#" onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)}
       style={{
         background: hover ? "var(--linne)" : "var(--linne-djup)",
         borderRadius: "var(--r-4)", padding: 24,
         display: "flex", flexDirection: "column", gap: 14, textDecoration: "none",
         border: "1px solid transparent",
         transition: "all 200ms var(--ease-out-warm)",
         transform: hover ? "translateY(-4px)" : "translateY(0)",
         boxShadow: hover ? "var(--shadow-2)" : "none",
       }}>
      <div style={{ height: 132, display: "flex", alignItems: "center", justifyContent: "center" }}>
        <img src={c.illu} alt="" style={{ width: "100%", height: "100%", objectFit: "contain", transition: "transform 320ms var(--ease-out-warm)", transform: hover ? "scale(1.05)" : "scale(1)" }} />
      </div>
      <i className={`ph ${c.icon}`} style={{ fontSize: 22, color: "var(--sval-700)" }} />
      <div>
        <h3 style={{ fontFamily: "var(--font-body)", fontSize: 18, fontWeight: 600, color: "var(--skog)" }}>{item.t}</h3>
        <p style={{ fontSize: 14, color: "var(--skog-mjuk)", marginTop: 4, lineHeight: "20px" }}>{item.b}</p>
      </div>
    </a>
  );
}

// ----- Testimonials carousel -----
function Testimonials() {
  const { t } = useLang();
  const [idx, setIdx] = useSh(0);
  useEh(() => {
    const i = setInterval(() => setIdx(v => (v + 1) % t.testimonials.items.length), 7000);
    return () => clearInterval(i);
  }, [t.testimonials.items.length]);
  return (
    <section style={{ padding: "112px 32px", background: "var(--skog)", color: "var(--linne)", position: "relative", overflow: "hidden" }}>
      <div style={{
        position: "absolute", inset: 0, opacity: 0.12, pointerEvents: "none",
        backgroundImage: "url(assets/wave.svg)", backgroundRepeat: "repeat", backgroundSize: "320px",
      }} />
      <div style={{ maxWidth: 900, margin: "0 auto", position: "relative", textAlign: "center" }}>
        <Reveal>
          <Eyebrow color="rgba(246,241,230,0.7)">{t.testimonials.eyebrow}</Eyebrow>
          <div style={{ fontFamily: "var(--font-display)", fontSize: 96, color: "var(--sval-300)", lineHeight: 0.4, marginBottom: 24 }}>"</div>
          <div style={{ minHeight: 220, position: "relative" }}>
            {t.testimonials.items.map((item, i) => (
              <div key={i} style={{
                position: i === idx ? "relative" : "absolute", inset: 0,
                opacity: i === idx ? 1 : 0,
                transition: "opacity 600ms var(--ease-out-warm)", pointerEvents: i === idx ? "auto" : "none",
              }}>
                <blockquote style={{
                  fontFamily: "var(--font-display)", fontSize: "clamp(28px, 3.4vw, 44px)", lineHeight: 1.18,
                  color: "var(--linne)", letterSpacing: "-0.01em", margin: 0, fontStyle: "italic",
                }}>{item.q}</blockquote>
                <div style={{ marginTop: 36, display: "flex", flexDirection: "column", alignItems: "center", gap: 4 }}>
                  <div style={{ fontSize: 15, fontWeight: 600 }}>{item.n}</div>
                  <div style={{ fontSize: 13, color: "rgba(246,241,230,0.65)" }}>{item.m}</div>
                </div>
              </div>
            ))}
          </div>
        </Reveal>
        <div style={{ display: "flex", gap: 8, justifyContent: "center", marginTop: 40 }}>
          {t.testimonials.items.map((_, i) => (
            <button key={i} onClick={() => setIdx(i)} aria-label={`testimonial ${i + 1}`} style={{
              width: i === idx ? 28 : 10, height: 10, borderRadius: 999,
              background: i === idx ? "var(--sval-300)" : "rgba(246,241,230,0.25)",
              border: "none", cursor: "pointer",
              transition: "all 240ms var(--ease-out-warm)",
            }} />
          ))}
        </div>
      </div>
    </section>
  );
}

// ----- About -----
function About() {
  const { t } = useLang();
  return (
    <section style={{ padding: "112px 32px", background: "var(--linne-djup)" }}>
      <div style={{ maxWidth: 1280, margin: "0 auto", display: "grid", gridTemplateColumns: "1fr 1fr", gap: 80, alignItems: "center" }}>
        <Reveal>
          <div style={{
            aspectRatio: "4 / 5", background: "var(--linne)", borderRadius: "var(--r-5)",
            overflow: "hidden", position: "relative", boxShadow: "var(--shadow-3)",
          }}>
            <img src="assets/photo-car-door.jpeg" alt="" style={{ width: "100%", height: "100%", objectFit: "cover", objectPosition: "40% center" }} />
          </div>
        </Reveal>
        <Reveal delay={100}>
          <Eyebrow>{t.about.eyebrow}</Eyebrow>
          <h2 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(40px, 4.5vw, 56px)", color: "var(--skog)", letterSpacing: "-0.01em", lineHeight: 1.04 }}>
            {t.about.title1}<span style={{ fontStyle: "italic", color: "var(--sval-700)" }}>{t.about.title2}</span>
          </h2>
          <p style={{ fontSize: 17, color: "var(--skog-mjuk)", marginTop: 22, lineHeight: "28px" }}>{t.about.body1}</p>
          <p style={{ fontSize: 17, color: "var(--skog-mjuk)", marginTop: 16, lineHeight: "28px" }}>{t.about.body2}</p>
          <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 16, marginTop: 36 }}>
            {t.about.stats.map(s => (
              <div key={s.l}>
                <div style={{ fontFamily: "var(--font-display)", fontSize: 32, color: "var(--skog)", lineHeight: 1 }}>{s.n}</div>
                <div style={{ fontSize: 12, color: "var(--skog-bleek)", letterSpacing: "0.04em", marginTop: 6 }}>{s.l}</div>
              </div>
            ))}
          </div>
          <div style={{ marginTop: 28 }}>
            <PCButton variant="secondary" icon={<i className="ph ph-arrow-right" />}>{t.about.cta}</PCButton>
          </div>
        </Reveal>
      </div>
    </section>
  );
}

// ----- AI (B2B side service) -----
function AISection() {
  const { t } = useLang();
  return (
    <section id="ai" style={{ padding: "112px 32px", background: "var(--linne)" }}>
      <div style={{ maxWidth: 1280, margin: "0 auto" }}>
        <Reveal>
          <div style={{
            background: "var(--skog)", color: "var(--linne)", borderRadius: "var(--r-5)",
            padding: "72px 64px", display: "grid", gridTemplateColumns: "1.1fr 1fr",
            gap: 56, alignItems: "center", position: "relative", overflow: "hidden",
          }}>
            <div style={{
              position: "absolute", top: -120, right: -120, width: 460, height: 460,
              borderRadius: 999, background: "radial-gradient(circle, rgba(124,176,202,0.28), transparent 70%)",
            }} />
            <div style={{ position: "relative" }}>
              <Eyebrow color="rgba(246,241,230,0.7)">{t.ai.eyebrow}</Eyebrow>
              <h2 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(36px, 4vw, 52px)", color: "var(--linne)", letterSpacing: "-0.01em", lineHeight: 1.05 }}>
                {t.ai.title1}<span style={{ fontStyle: "italic", color: "var(--sval-300)" }}>{t.ai.title2}</span>
              </h2>
              <p style={{ fontSize: 17, color: "rgba(246,241,230,0.75)", marginTop: 18, lineHeight: "28px", maxWidth: 460 }}>{t.ai.body}</p>
              <div style={{ marginTop: 28 }}>
                <PCButton variant="onDark" icon={<i className="ph ph-arrow-right" />}>{t.ai.cta}</PCButton>
              </div>
            </div>
            <div style={{ position: "relative", display: "flex", flexDirection: "column", gap: 14 }}>
              {t.ai.bullets.map((b, i) => (
                <div key={i} style={{
                  display: "flex", alignItems: "center", gap: 16,
                  padding: "18px 22px", background: "rgba(246,241,230,0.06)",
                  borderRadius: "var(--r-3)", border: "1px solid rgba(246,241,230,0.08)",
                }}>
                  <div style={{ width: 40, height: 40, borderRadius: 999, background: "rgba(45,127,166,0.18)", display: "inline-flex", alignItems: "center", justifyContent: "center", color: "var(--sval-300)" }}>
                    <i className={`ph ${["ph-shield-check","ph-lightning","ph-brain"][i]}`} style={{ fontSize: 20 }} />
                  </div>
                  <span style={{ fontSize: 16, color: "var(--linne)", fontWeight: 500 }}>{b}</span>
                </div>
              ))}
              <div style={{ display: "flex", gap: 10, fontSize: 12, color: "rgba(246,241,230,0.55)", marginTop: 8, fontFamily: "var(--font-mono)", letterSpacing: "0.06em" }}>
                <span>LLAMA · MISTRAL · QWEN</span><span style={{ opacity: 0.5 }}>·</span><span>ON-PREM</span>
              </div>
            </div>
          </div>
        </Reveal>
      </div>
    </section>
  );
}

// ----- FAQ accordion -----
function FAQ() {
  const { t } = useLang();
  const [open, setOpen] = useSh(0);
  return (
    <section id="faq" style={{ padding: "112px 32px" }}>
      <div style={{ maxWidth: 1100, margin: "0 auto", display: "grid", gridTemplateColumns: "1fr 1.6fr", gap: 80 }}>
        <Reveal>
          <Eyebrow>{t.faq.eyebrow}</Eyebrow>
          <h2 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(36px, 4.2vw, 52px)", color: "var(--skog)", letterSpacing: "-0.01em", lineHeight: 1.04 }}>
            {t.faq.title}
          </h2>
          <p style={{ fontSize: 15, color: "var(--skog-mjuk)", marginTop: 18, lineHeight: "24px" }}>
            Hittar du inte svaret? Mejla oss på <a href="mailto:hej@portacooler.se" style={{ color: "var(--sval-700)", fontWeight: 600 }}>hej@portacooler.se</a>.
          </p>
        </Reveal>
        <Reveal delay={120}>
          <div style={{ display: "flex", flexDirection: "column" }}>
            {t.faq.items.map((it, i) => (
              <FAQItem key={i} item={it} open={open === i} onToggle={() => setOpen(open === i ? -1 : i)} first={i === 0} />
            ))}
          </div>
        </Reveal>
      </div>
    </section>
  );
}

function FAQItem({ item, open, onToggle, first }) {
  return (
    <div style={{
      borderTop: first ? "1px solid var(--border-soft)" : "none",
      borderBottom: "1px solid var(--border-soft)",
    }}>
      <button onClick={onToggle} style={{
        width: "100%", textAlign: "left", background: "transparent", border: "none",
        cursor: "pointer", padding: "24px 4px", display: "flex", justifyContent: "space-between",
        alignItems: "center", gap: 16, fontFamily: "var(--font-body)",
      }}>
        <span style={{ fontSize: 18, fontWeight: 600, color: "var(--skog)" }}>{item.q}</span>
        <i className="ph ph-plus" style={{
          fontSize: 18, color: "var(--sval-700)",
          transform: open ? "rotate(45deg)" : "rotate(0)",
          transition: "transform 220ms var(--ease-out-warm)",
        }} />
      </button>
      <div style={{
        maxHeight: open ? 320 : 0, overflow: "hidden",
        transition: "max-height 320ms var(--ease-out-warm)",
      }}>
        <p style={{
          padding: "0 4px 24px", fontSize: 16, color: "var(--skog-mjuk)",
          lineHeight: "26px", maxWidth: 640,
        }}>{item.a}</p>
      </div>
    </div>
  );
}

// ----- Closing CTA -----
function ClosingCTA() {
  const { t } = useLang();
  const { setOpen } = useCart();
  return (
    <section style={{ padding: "0 32px 96px" }}>
      <div style={{
        maxWidth: 1280, margin: "0 auto",
        background: "var(--sval-700)", color: "var(--linne)", borderRadius: "var(--r-5)",
        padding: "72px 64px", display: "grid", gridTemplateColumns: "1.5fr 1fr", gap: 48,
        alignItems: "center", position: "relative", overflow: "hidden",
      }}>
        <div style={{
          position: "absolute", inset: 0, opacity: 0.16, pointerEvents: "none",
          backgroundImage: "url(assets/wave.svg)", backgroundSize: "320px",
        }} />
        <div style={{ position: "relative" }}>
          <Eyebrow color="rgba(246,241,230,0.7)">Klart att börja</Eyebrow>
          <h2 style={{ fontFamily: "var(--font-display)", fontSize: "clamp(40px, 5vw, 64px)", color: "var(--linne)", letterSpacing: "-0.01em", lineHeight: 1 }}>
            <span style={{ fontStyle: "italic" }}>{t.hero.titleA}</span> {t.hero.titleB}
          </h2>
          <p style={{ fontSize: 17, color: "rgba(246,241,230,0.85)", marginTop: 20, maxWidth: 480, lineHeight: "28px" }}>
            Skickas inom 1–2 dagar från Kristinehamn. 60 dagars öppet köp.
          </p>
        </div>
        <div style={{ display: "flex", gap: 12, justifyContent: "end", position: "relative", flexWrap: "wrap" }}>
          <PCButton variant="onDark" size="lg" href="allround.html" icon={<i className="ph ph-arrow-right" />}>
            {t.hero.cta1}
          </PCButton>
          <PCButton variant="secondaryDark" size="lg" onClick={() => setOpen(true)}>
            <i className="ph ph-shopping-bag" style={{ fontSize: 18, marginRight: 6 }} />
            {t.nav.cart}
          </PCButton>
        </div>
      </div>
    </section>
  );
}

Object.assign(window, {
  Hero, TrustRow, HowItWorks, ProductsSection, UseCases,
  Testimonials, About, AISection, FAQ, ClosingCTA, PRODUCTS,
});
