// Sections: Hero, How, Why, Cars, Trust, FAQ, FinalCTA, Footer

const { useState: useStateS, useEffect: useEffectS } = React;

function Nav({ lang, setLang, t }) {
  const [scrolled, setScrolled] = useStateS(false);
  useEffectS(() => {
    const onScroll = () => setScrolled(window.scrollY > 8);
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);
  const navItems = [
    { id: "how", label: t.nav.how },
    { id: "cars", label: t.nav.cars },
    { id: "cost", label: t.nav.cost },
    { id: "trust", label: t.nav.trust },
    { id: "faq", label: t.nav.faq },
  ];
  const shippingLabel = t.misc?.shippingLink || "Shipping & Sourcing";
  const waLabel = t.misc?.wa || "WhatsApp";
  return (
    <header
      style={{
        position: "fixed", top: 0, left: 0, right: 0, zIndex: 50,
        backdropFilter: scrolled ? "blur(18px) saturate(140%)" : "none",
        WebkitBackdropFilter: scrolled ? "blur(18px) saturate(140%)" : "none",
        background: scrolled ? "rgba(10,10,11,0.72)" : "transparent",
        borderBottom: scrolled ? "1px solid var(--line)" : "1px solid transparent",
        transition: "background .3s ease, border-color .3s ease",
      }}
    >
      <div className="wrap" style={{ display: "flex", alignItems: "center", justifyContent: "space-between", height: 68 }}>
        <a href="#top" style={{ textDecoration: "none" }}><Wordmark /></a>
        <nav className="desktop-nav" style={{ display: "none", gap: 32, alignItems: "center" }}>
          {navItems.map((n) => (
            <a key={n.id} href={"#" + n.id} className="nav-link" style={{ color: "var(--mute)", textDecoration: "none", fontSize: 13, transition: "color .25s cubic-bezier(.16,1,.3,1)" }}
               onMouseEnter={(e) => (e.currentTarget.style.color = "var(--bone)")}
               onMouseLeave={(e) => (e.currentTarget.style.color = "var(--mute)")}>
              {n.label}
            </a>
          ))}
        </nav>
        <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
          <a href={SHIPPING_URL} target="_blank" rel="noopener" className="mono"
             style={{
               display: "none", color: "var(--mute)", textDecoration: "none",
               fontSize: 10, letterSpacing: "0.14em", textTransform: "uppercase",
               padding: "8px 12px", border: "1px solid var(--line-2)", borderRadius: 999,
               transition: "color .2s, border-color .2s",
             }}
             className="ship-link mono"
             onMouseEnter={(e) => { e.currentTarget.style.color = "var(--bone)"; e.currentTarget.style.borderColor = "var(--amber)"; }}
             onMouseLeave={(e) => { e.currentTarget.style.color = "var(--mute)"; e.currentTarget.style.borderColor = "var(--line-2)"; }}>
            {shippingLabel} <span className="flip">→</span>
          </a>
          <div className="lang-switch mono" role="group" aria-label="Language">
            {(window.LANG_ORDER || ["en","fr","es","ar"]).map((code) => (
              <button
                key={code}
                onClick={() => setLang(code)}
                aria-pressed={lang === code}
                className={"lang-btn" + (lang === code ? " is-active" : "")}
              >
                {(COPY[code] && COPY[code].code) || code.toUpperCase()}
              </button>
            ))}
          </div>
          <a href={WA.beirut} target="_blank" rel="noopener" className="btn btn-primary desktop-cta" style={{ display: "none", padding: "10px 18px", fontSize: 13 }}>
            {waLabel}
          </a>
        </div>
      </div>
      <style>{`
        @media (min-width: 900px) {
          .desktop-nav { display: flex !important; }
          .desktop-cta { display: inline-flex !important; }
        }
        @media (min-width: 1100px) {
          .ship-link { display: inline-flex !important; align-items: center; gap: 6px; }
        }
        .lang-switch {
          display: inline-flex; align-items: center;
          border: 1px solid var(--line-2);
          border-radius: 999px;
          padding: 3px;
          gap: 2px;
          background: rgba(10,10,11,0.4);
        }
        .lang-btn {
          background: transparent;
          border: 0;
          color: var(--mute);
          font: inherit;
          font-size: 10px;
          letter-spacing: 0.12em;
          text-transform: uppercase;
          padding: 5px 10px;
          border-radius: 999px;
          cursor: pointer;
          transition: color .2s ease, background .2s ease;
        }
        .lang-btn:hover { color: var(--bone); }
        .lang-btn.is-active {
          background: var(--bone);
          color: var(--ink-0);
        }
      `}</style>
    </header>
  );
}

function Hero({ t, lang }) {
  return (
    <section id="top" style={{ position: "relative", minHeight: "100vh", display: "flex", alignItems: "flex-end", overflow: "hidden", paddingBottom: 80, paddingTop: 120 }}>
      <HeroBackdrop />
      <div className="wrap" style={{ position: "relative", zIndex: 2 }}>
        <div className="hero-grid-2" style={{ display: "grid", gridTemplateColumns: "1fr", gap: 40, alignItems: "center" }}>
          <div style={{ maxWidth: 640 }}>
            <div className="eyebrow hero-anim d0" style={{ marginBottom: 28 }}>
              <span style={{ display: "inline-block", width: 24, height: 1, background: "var(--amber)", verticalAlign: "middle", marginInlineEnd: 12 }} />
              {t.hero.eyebrow}
            </div>
            <h1 className="serif" style={{ fontSize: "clamp(40px, 6.4vw, 84px)", lineHeight: 0.98, letterSpacing: "-0.02em", margin: 0, color: "var(--bone)" }}>
              <span className="hero-anim d2" style={{ display: "block" }}>{t.hero.headline_a}</span>
              <span className="hero-anim d4" style={{ display: "block", fontStyle: "italic", color: "var(--bone-2)" }}>{t.hero.headline_b}</span>
              <span className="hero-anim d6" style={{ display: "block", color: "var(--amber)", fontStyle: "italic" }}>{t.hero.headline_c}</span>
            </h1>
            <p className="hero-anim d10" style={{ fontSize: "clamp(15px, 1.5vw, 18px)", lineHeight: 1.55, color: "var(--mute)", maxWidth: 520, marginTop: 32, marginBottom: 0 }}>
              {t.hero.sub}
            </p>
            <div className="hero-anim d13" style={{ display: "flex", flexWrap: "wrap", gap: 12, marginTop: 36 }}>
              <a href={WA.beirut} target="_blank" rel="noopener" className="btn btn-wa">
                <WAIcon /> {t.hero.cta_primary}
              </a>
              <a href="#cost" className="btn btn-ghost">
                {t.hero.cta_secondary}
                <span className="flip" style={{ display: "inline-block" }}>→</span>
              </a>
            </div>
          </div>
          <div className="hero-car-anim hero-ev" style={{ width: "100%", maxWidth: 720, justifySelf: lang === "ar" ? "start" : "end", aspectRatio: "900/520" }}>
            <EVSilhouette />
          </div>
        </div>
        <div className="hero-anim d18" style={{ marginTop: 56, paddingTop: 24, borderTop: "1px solid var(--line)", display: "flex", alignItems: "center", gap: 12, flexWrap: "wrap" }}>
          <span className="mono" style={{ fontSize: 11, color: "var(--mute-2)", letterSpacing: "0.05em" }}>
            {t.hero.trust}
          </span>
        </div>
      </div>
      <div style={{ position: "absolute", bottom: 28, left: "50%", transform: "translateX(-50%)", display: "none", flexDirection: "column", alignItems: "center", gap: 10 }} className="scroll-ind">
        <span className="scroll-line" />
      </div>
      <style>{`
        @media (min-width: 900px) {
          .scroll-ind { display: flex !important; }
          .hero-grid-2 { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr) !important; gap: 48px !important; }
        }
        @media (max-width: 899px) {
          .hero-ev { max-width: 540px !important; margin-inline: auto; }
        }
      `}</style>
    </section>
  );
}

function WAIcon() {
  return (
    <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
      <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51l-.57-.01c-.198 0-.52.074-.792.372s-1.04 1.016-1.04 2.479 1.065 2.876 1.213 3.074c.149.198 2.095 3.2 5.077 4.487.71.306 1.263.489 1.694.626.712.226 1.36.194 1.872.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 0 1-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 0 1-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 0 1 2.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0 0 12.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 0 0 5.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893A11.821 11.821 0 0 0 20.464 3.488"/>
    </svg>
  );
}

function SectionLabel({ eyebrow, title, sub, align = "start", lang }) {
  return (
    <div data-reveal style={{ maxWidth: 720, marginInline: align === "center" ? "auto" : 0, textAlign: align === "center" ? "center" : (lang === "ar" ? "right" : "left"), marginBottom: 64 }}>
      <div className="eyebrow" style={{ marginBottom: 18 }}>{eyebrow}</div>
      <h2 className="serif" style={{ fontSize: "clamp(34px, 5vw, 56px)", lineHeight: 1.02, letterSpacing: "-0.02em", margin: 0, color: "var(--bone)" }}>
        {title}
      </h2>
      {sub && <p style={{ marginTop: 16, fontSize: 17, lineHeight: 1.55, color: "var(--mute)" }}>{sub}</p>}
    </div>
  );
}

// Animated step illustrations.
function StepIcon({ n, active }) {
  // n = 0 (pick), 1 (lock/sign), 2 (deliver/ship)
  const a = active ? 1 : 0;
  if (n === 0) {
    // Three car silhouettes, one highlighted with a moving caret
    return (
      <svg viewBox="0 0 240 140" className="step-svg" aria-hidden="true">
        <defs>
          <linearGradient id="picRim" x1="0" y1="0" x2="1" y2="0">
            <stop offset="0" stopColor="#e8732e" stopOpacity="0" />
            <stop offset=".5" stopColor="#e8732e" />
            <stop offset="1" stopColor="#e8732e" stopOpacity="0" />
          </linearGradient>
        </defs>
        {[0, 1, 2].map((i) => {
          const x = 24 + i * 70;
          const isPicked = i === 1;
          return (
            <g key={i} transform={`translate(${x}, 56)`} className={"pic-car " + (isPicked && active ? "pic-car-on" : "")} style={{ transitionDelay: (i * 80) + "ms" }}>
              {/* pad */}
              <rect x="-26" y="44" width="52" height="2" fill="rgba(255,255,255,.05)" />
              {/* body */}
              <path d="M -26 36 C -22 24, -14 18, -4 18 L 4 8 C 6 6, 10 4, 14 4 L 18 4 C 22 4, 24 6, 24 10 L 26 36 C 26 42, 22 44, 18 44 L -22 44 C -26 44, -28 40, -26 36 Z"
                    fill={isPicked && active ? "#1a1a1f" : "#13131a"}
                    stroke={isPicked && active ? "url(#picRim)" : "rgba(255,255,255,.06)"} strokeWidth="1" />
              {/* window */}
              <path d="M -10 22 C -6 12, 0 8, 6 8 L 14 8 C 18 8, 20 10, 20 14 L 20 22 Z" fill="rgba(255,255,255,.04)" />
              {/* wheels */}
              <circle cx="-14" cy="42" r="5" fill="#050506" />
              <circle cx="14" cy="42" r="5" fill="#050506" />
            </g>
          );
        })}
        {/* selection ring */}
        <g className="pic-ring" opacity={a}>
          <rect x="64" y="86" width="60" height="3" rx="1.5" fill="#e8732e" />
          <path d="M 88 80 L 94 86 L 100 80" fill="none" stroke="#e8732e" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
        </g>
        {/* tap marker */}
        <circle className="pic-tap" cx="94" cy="56" r="3" fill="#e8732e" opacity="0" />
      </svg>
    );
  }
  if (n === 1) {
    // Document with signature stroke being drawn
    return (
      <svg viewBox="0 0 240 140" className="step-svg" aria-hidden="true">
        {/* paper */}
        <g transform="translate(58,18)">
          <rect x="0" y="0" width="124" height="104" rx="2" fill="#13131a" stroke="rgba(255,255,255,.08)" />
          {/* top corner fold */}
          <path d="M 110 0 L 124 0 L 124 14 Z" fill="#0e0e10" stroke="rgba(255,255,255,.08)" />
          {/* header */}
          <rect x="14" y="14" width="50" height="4" rx="1" fill="rgba(239,233,221,.35)" />
          <rect x="14" y="22" width="32" height="3" rx="1" fill="rgba(239,233,221,.18)" />
          {/* lines */}
          {[36, 44, 52, 60, 68].map((y, i) => (
            <rect key={i} x="14" y={y} width={i % 2 ? 88 : 96} height="2" rx="1" fill="rgba(239,233,221,.10)" />
          ))}
          {/* signature box */}
          <line x1="14" y1="86" x2="68" y2="86" stroke="rgba(239,233,221,.25)" strokeDasharray="2 2" />
          {/* signature stroke (animated) */}
          <path className="sig-path" d="M 16 84 C 22 76, 28 90, 36 82 C 42 76, 50 88, 60 80" fill="none" stroke="#e8732e" strokeWidth="1.6" strokeLinecap="round" pathLength="100" strokeDasharray="100" strokeDashoffset={active ? 0 : 100} />
          {/* stamp */}
          <g className="stamp" opacity={a} transform="translate(82,72)">
            <circle r="14" fill="none" stroke="#e8732e" strokeWidth="1.4" opacity=".75" />
            <text y="3" textAnchor="middle" fontFamily="DM Mono, monospace" fontSize="6" fill="#e8732e" letterSpacing="0.5">DEPOSIT</text>
          </g>
        </g>
        {/* pen */}
        <g className="pen" style={{ transformOrigin: "74px 102px" }}>
          <line x1="68" y1="108" x2="80" y2="96" stroke="rgba(239,233,221,.85)" strokeWidth="1.4" strokeLinecap="round" />
          <line x1="80" y1="96" x2="84" y2="92" stroke="#e8732e" strokeWidth="1.6" strokeLinecap="round" />
          <circle cx="68" cy="108" r="1.4" fill="#e8732e" />
        </g>
      </svg>
    );
  }
  // n === 2 — ship sailing across with port marker, then car arriving
  return (
    <svg viewBox="0 0 240 140" className="step-svg" aria-hidden="true">
      {/* horizon */}
      <line x1="10" y1="92" x2="230" y2="92" stroke="rgba(255,255,255,.08)" />
      {/* waves */}
      <path d="M 10 100 Q 30 96, 50 100 T 90 100 T 130 100 T 170 100 T 210 100 T 230 100" fill="none" stroke="rgba(232,115,46,.18)" strokeWidth="1" />
      <path d="M 10 110 Q 34 106, 58 110 T 106 110 T 154 110 T 200 110 T 230 110" fill="none" stroke="rgba(232,115,46,.10)" strokeWidth="1" />
      {/* dotted route */}
      <line x1="20" y1="84" x2="220" y2="84" stroke="rgba(239,233,221,.15)" strokeDasharray="2 4" />
      {/* origin + destination markers */}
      <circle cx="20" cy="84" r="3" fill="rgba(239,233,221,.4)" />
      <circle cx="220" cy="84" r="4" fill="#e8732e" className="port-pulse" />
      <text x="20" y="74" textAnchor="middle" fontFamily="DM Mono" fontSize="6" fill="rgba(239,233,221,.45)" letterSpacing="0.5">GZ</text>
      <text x="220" y="74" textAnchor="middle" fontFamily="DM Mono" fontSize="6" fill="#e8732e" letterSpacing="0.5">BEY</text>

      {/* container ship */}
      <g className="ship" transform="translate(0,0)">
        <g transform="translate(0,72)">
          <path d="M -20 8 L 40 8 L 36 16 L -16 16 Z" fill="#16161a" stroke="rgba(255,255,255,.08)" />
          <rect x="-16" y="0" width="14" height="8" fill="#1d1d22" />
          <rect x="0" y="-2" width="10" height="10" fill="#26262d" />
          <rect x="12" y="2" width="10" height="6" fill="#1d1d22" />
          <rect x="24" y="0" width="10" height="8" fill="#e8732e" opacity=".55" />
          {/* bridge */}
          <rect x="32" y="-6" width="6" height="6" fill="#0e0e10" stroke="rgba(255,255,255,.08)" />
          {/* wake */}
          <path className="wake" d="M -22 16 L -38 16" stroke="rgba(255,255,255,.18)" strokeWidth="1" strokeLinecap="round" />
        </g>
      </g>
    </svg>
  );
}

function HowItWorks({ t, lang }) {
  const [activeIdx, setActiveIdx] = useStateS(-1);
  const [progress, setProgress] = useStateS(0); // 0 → 1
  const wrapRef = useRefA(null);

  useEffectS(() => {
    const el = wrapRef.current;
    if (!el) return;
    let frame = 0;
    const onScroll = () => {
      cancelAnimationFrame(frame);
      frame = requestAnimationFrame(() => {
        const rect = el.getBoundingClientRect();
        const vh = window.innerHeight || 800;
        // 0 when section bottom enters viewport bottom; 1 when section top reaches 30% of viewport
        const start = vh * 0.85;
        const end = vh * 0.25;
        const top = rect.top;
        let p = (start - top) / (start - end);
        p = Math.max(0, Math.min(1, p));
        setProgress(p);
        const which = p < 0.18 ? -1 : p < 0.5 ? 0 : p < 0.82 ? 1 : 2;
        setActiveIdx(which);
      });
    };
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    window.addEventListener("resize", onScroll);
    return () => { window.removeEventListener("scroll", onScroll); window.removeEventListener("resize", onScroll); cancelAnimationFrame(frame); };
  }, []);

  const meta = [
    t.misc?.free || "Free",
    t.misc?.deposit20 || "20% deposit",
    t.misc?.days45to60 || "45–60 days",
  ];

  return (
    <section id="how" style={{ padding: "120px 0", borderTop: "1px solid var(--line)", position: "relative", overflow: "hidden" }}>
      <div className="wrap">
        <SectionLabel eyebrow={t.how.eyebrow} title={t.how.title} lang={lang} />

        <div ref={wrapRef} className="how-grid" style={{ position: "relative" }}>
          {/* Connector line */}
          <div className="how-line-track" aria-hidden="true">
            <div className="how-line-fill" style={{ transform: `scaleX(${progress})` }} />
            {/* dots at 0%, 50%, 100% */}
            {[0, 1, 2].map((i) => (
              <span key={i} className={"how-dot " + (activeIdx >= i ? "on" : "")} style={{ insetInlineStart: `calc(${(i / 2) * 100}% - 7px)` }} />
            ))}
            {/* moving cargo dot */}
            <span className="how-cargo" style={{ insetInlineStart: `calc(${progress * 100}% - 5px)`, opacity: progress > 0.02 ? 1 : 0 }} />
          </div>

          <div className="how-cards">
            {t.how.steps.map((s, i) => {
              const isActive = activeIdx >= i;
              return (
                <div
                  key={i}
                  className={"how-card " + (isActive ? "is-active" : "")}
                  style={{ transitionDelay: (i * 60) + "ms" }}
                >
                  <div className="how-card-head">
                    <span className="serif how-num">{s.n}</span>
                    <span className="mono how-meta">{meta[i]}</span>
                  </div>
                  <div className="how-illus">
                    <StepIcon n={i} active={isActive} />
                  </div>
                  <div>
                    <h3 className="serif how-title">{s.k}</h3>
                    <p className="how-body">{s.v}</p>
                  </div>
                </div>
              );
            })}
          </div>
        </div>
      </div>

      <style>{`
        .how-grid { position: relative; }
        .how-cards {
          display: grid;
          grid-template-columns: 1fr;
          gap: 24px;
          position: relative;
          z-index: 1;
        }
        @media (min-width: 820px) {
          .how-cards { grid-template-columns: repeat(3, 1fr); gap: 0; }
        }

        .how-card {
          background: var(--ink-1);
          border: 1px solid var(--line);
          padding: 36px 28px 32px;
          min-height: 360px;
          display: flex; flex-direction: column; gap: 20px;
          opacity: 0; transform: translateY(18px);
          transition: opacity .7s cubic-bezier(.2,.7,.2,1), transform .7s cubic-bezier(.2,.7,.2,1), background .35s ease, border-color .35s ease;
          position: relative;
        }
        @media (min-width: 820px) {
          .how-card { margin-inline-start: -1px; }
          .how-card:first-child { margin-inline-start: 0; }
        }
        .how-card.is-active { opacity: 1; transform: none; }
        .how-card.is-active { background: var(--ink-2); border-color: var(--line-2); }

        .how-card-head { display: flex; align-items: baseline; justify-content: space-between; }
        .how-num {
          font-size: 56px; line-height: 1; font-style: italic;
          color: var(--amber);
          opacity: .35; transition: opacity .5s ease, transform .5s ease;
          transform: translateY(4px);
        }
        .how-card.is-active .how-num { opacity: 1; transform: none; }

        .how-meta {
          font-size: 10px; letter-spacing: .15em; text-transform: uppercase;
          color: var(--mute-2);
          padding: 5px 9px; border: 1px solid var(--line-2); border-radius: 999px;
          transition: color .35s, border-color .35s, background .35s;
        }
        .how-card.is-active .how-meta {
          color: var(--amber); border-color: rgba(232,115,46,.35); background: rgba(232,115,46,.05);
        }

        .how-illus {
          height: 130px; border: 1px dashed var(--line);
          background: linear-gradient(180deg, rgba(255,255,255,.015) 0%, transparent 100%);
          border-radius: 4px; overflow: hidden;
          display: flex; align-items: center; justify-content: center;
        }
        .step-svg { width: 100%; height: 100%; display: block; }

        .how-title { font-size: 24px; margin: 0; color: var(--bone); letter-spacing: -.01em; }
        .how-body { margin-top: 10px; margin-bottom: 0; font-size: 14.5px; line-height: 1.6; color: var(--mute); }

        /* Connector line */
        .how-line-track {
          position: absolute; top: -32px; left: 5%; right: 5%;
          height: 2px; background: var(--line);
          display: none;
        }
        @media (min-width: 820px) {
          .how-line-track { display: block; }
        }
        .how-line-fill {
          position: absolute; inset: 0;
          background: linear-gradient(90deg, var(--amber), #ffb27a);
          transform-origin: left center;
          transform: scaleX(0);
          transition: transform .3s linear;
        }
        [dir="rtl"] .how-line-fill { transform-origin: right center; }
        .how-dot {
          position: absolute; top: -6px; width: 14px; height: 14px; border-radius: 50%;
          background: var(--ink-0); border: 1.5px solid var(--line-2);
          transition: border-color .35s, background .35s, transform .35s;
        }
        .how-dot.on { border-color: var(--amber); background: var(--amber); transform: scale(1.05); }
        .how-cargo {
          position: absolute; top: -4px; width: 10px; height: 10px; border-radius: 2px;
          background: #ffb27a;
          box-shadow: 0 0 14px rgba(232,115,46,.7), 0 0 4px rgba(232,115,46,.9);
          transition: opacity .25s, inset-inline-start .12s linear;
        }

        /* Step 1 — picker */
        .pic-car { transition: transform .45s cubic-bezier(.2,.7,.2,1); transform-origin: center; }
        .pic-car-on { transform: translateY(-4px); }
        .pic-ring { transition: opacity .45s ease .2s; }
        @keyframes picTap {
          0% { opacity: 0; transform: scale(.4); }
          40% { opacity: .9; transform: scale(1); }
          100% { opacity: 0; transform: scale(2.4); }
        }
        .how-card.is-active .pic-tap {
          transform-box: fill-box; transform-origin: center;
          animation: picTap 1.4s ease-out .25s infinite;
        }

        /* Step 2 — signature draws */
        .sig-path { transition: stroke-dashoffset 1.1s cubic-bezier(.6,.05,.35,1) .15s; }
        .stamp { transition: opacity .4s ease 1.05s; transform-origin: center; }
        .how-card.is-active .stamp { animation: stampIn .5s cubic-bezier(.2,1.4,.3,1) 1.05s both; }
        @keyframes stampIn {
          0% { opacity: 0; transform: translate(82px, 72px) scale(1.6) rotate(-8deg); }
          60% { opacity: 1; transform: translate(82px, 72px) scale(.92) rotate(-6deg); }
          100% { opacity: .9; transform: translate(82px, 72px) scale(1) rotate(-6deg); }
        }
        .pen {
          opacity: 0; transform: translate(-12px, 8px);
          transition: opacity .35s ease, transform 1.1s cubic-bezier(.6,.05,.35,1) .15s;
        }
        .how-card.is-active .pen { opacity: 1; transform: translate(0, -10px); }

        /* Step 3 — ship sails across */
        .ship { transform: translateX(-40px); transition: transform 1.6s cubic-bezier(.5,.05,.3,1) .1s; }
        .how-card.is-active .ship { transform: translateX(170px); }
        .wake { stroke-dasharray: 12 4; animation: wakeMove 1.2s linear infinite; opacity: .8; }
        @keyframes wakeMove { to { stroke-dashoffset: -16; } }
        .port-pulse { transform-origin: 220px 84px; }
        .how-card.is-active .port-pulse { animation: portPulse 1.6s ease-out 1.5s infinite; }
        @keyframes portPulse {
          0% { r: 4; filter: drop-shadow(0 0 0 rgba(232,115,46,.0)); }
          50% { r: 6; filter: drop-shadow(0 0 8px rgba(232,115,46,.7)); }
          100% { r: 4; filter: drop-shadow(0 0 0 rgba(232,115,46,0)); }
        }

        @media (prefers-reduced-motion: reduce) {
          .how-card { opacity: 1; transform: none; transition: none; }
          .ship, .pen, .sig-path, .stamp, .pic-tap, .port-pulse, .wake, .how-line-fill, .how-cargo { animation: none !important; transition: none !important; }
          .how-line-fill { transform: scaleX(1); }
        }
      `}</style>
    </section>
  );
}

function WhyDirect({ t, lang }) {
  return (
    <section style={{ padding: "120px 0", borderTop: "1px solid var(--line)", background: "var(--ink-1)" }}>
      <div className="wrap">
        <SectionLabel eyebrow={t.why.eyebrow} title={t.why.title} lang={lang} />
        <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(280px, 1fr))", gap: 32 }}>
          {t.why.items.map((it, i) => (
            <div key={i} data-reveal data-delay={i * 100} style={{ paddingBlock: 32, borderTop: "1px solid var(--line-2)" }}>
              <div className="serif" style={{ fontSize: "clamp(48px, 6vw, 72px)", lineHeight: 1, color: "var(--bone)", letterSpacing: "-0.03em" }}>
                <AnimatedStat text={it.stat} />
              </div>
              <h3 style={{ marginTop: 20, marginBottom: 8, fontSize: 16, fontWeight: 500, color: "var(--bone)", letterSpacing: "0.005em" }}>{it.k}</h3>
              <p style={{ margin: 0, fontSize: 14, lineHeight: 1.6, color: "var(--mute)" }}>{it.v}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

function CarsGrid({ t, lang, onPickCar }) {
  return (
    <section id="cars" style={{ padding: "120px 0", borderTop: "1px solid var(--line)" }}>
      <div className="wrap">
        <SectionLabel eyebrow={t.cars.eyebrow} title={t.cars.title} sub={t.cars.sub} lang={lang} />
        <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(280px, 1fr))", gap: 16 }}>
          {CARS.map((c, i) => (
            <button key={c.id} data-reveal data-delay={i * 100} onClick={() => onPickCar(c.id)}
                    className="car-tile"
                    style={{
                      textAlign: lang === "ar" ? "right" : "left",
                      border: "1px solid var(--line)", borderRadius: 4, padding: 0, cursor: "pointer", color: "inherit",
                    }}>
              <div style={{ aspectRatio: "16/10", position: "relative", overflow: "hidden", borderBottom: "1px solid var(--line)" }}>
                <CarSilhouette palette={c.palette} variant={c.type.en} />
                <div className="brand-mark" style={{ position: "absolute", bottom: 14, insetInlineStart: 16 }}>
                  <BrandMark id={c.id} />
                </div>
                {c.badge && (
                  <span className="mono" style={{
                    position: "absolute", top: 12, insetInlineStart: 12,
                    fontSize: 9, letterSpacing: "0.15em", textTransform: "uppercase",
                    color: "var(--amber)", border: "1px solid rgba(245,165,36,0.35)", borderRadius: 999, padding: "4px 8px", background: "rgba(0,0,0,0.4)"
                  }}>
                    {c.badge}
                  </span>
                )}
              </div>
              <div style={{ padding: "20px 22px", display: "flex", flexDirection: "column", gap: 8 }}>
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", gap: 12 }}>
                  <h3 className="serif" style={{ margin: 0, fontSize: 24, color: "var(--bone)", letterSpacing: "-0.01em" }}>{c.name}</h3>
                  <span className="mono" style={{ fontSize: 11, color: "var(--mute-2)", letterSpacing: "0.06em", textTransform: "uppercase" }}>{c.type[lang]}</span>
                </div>
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
                  <span style={{ fontSize: 12, color: "var(--mute-2)" }}>{lang === "en" ? "from" : "ابتداءً من"}</span>
                  <span className="num car-price" style={{ fontSize: 18, color: "var(--bone)", fontWeight: 500 }}>
                    {lang === "en" ? fmt(c.landed) : fmtAr(c.landed)}
                  </span>
                </div>
              </div>
            </button>
          ))}
          {/* 6th tile: ask */}
          <a href={WA.beirut} target="_blank" rel="noopener" data-reveal data-delay={CARS.length * 100} className="ask-tile"
             style={{
               textDecoration: "none", color: "inherit",
               border: "1px dashed var(--line-2)", borderRadius: 4,
               display: "flex", flexDirection: "column", justifyContent: "center", alignItems: lang === "ar" ? "flex-end" : "flex-start",
               padding: "32px 24px", minHeight: 280, gap: 14,
               transition: "border-color .4s cubic-bezier(.16,1,.3,1), background .4s cubic-bezier(.16,1,.3,1)",
             }}
             onMouseEnter={(e) => { e.currentTarget.style.borderColor = "var(--amber)"; e.currentTarget.style.background = "rgba(232,115,46,0.05)"; }}
             onMouseLeave={(e) => { e.currentTarget.style.borderColor = "var(--line-2)"; e.currentTarget.style.background = "transparent"; }}>
            <span className="serif ask-plus" style={{ fontSize: 36, fontStyle: "italic", color: "var(--amber)", lineHeight: 1 }}>+</span>
            <div>
              <h3 className="serif" style={{ margin: 0, fontSize: 24, color: "var(--bone)", letterSpacing: "-0.01em" }}>{t.cars.ask}</h3>
              <div style={{ marginTop: 10, fontSize: 13, color: "var(--mute)", display: "inline-flex", alignItems: "center", gap: 8 }}>
                {t.cars.askCta} <span className="flip">→</span>
              </div>
            </div>
          </a>
        </div>
      </div>
    </section>
  );
}

function TrustBlock({ t, lang }) {
  return (
    <section id="trust" style={{ padding: "120px 0", borderTop: "1px solid var(--line)", background: "var(--ink-1)", position: "relative", overflow: "hidden" }}>
      <div className="wrap">
        <SectionLabel eyebrow={t.trust.eyebrow} title={t.trust.title} sub={t.trust.sub} lang={lang} />
        <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(180px, 1fr))", gap: 1, background: "var(--line)", border: "1px solid var(--line)" }}>
          {t.trust.stats.map((s, i) => (
            <div key={i} data-reveal data-delay={i * 150} style={{ background: "var(--ink-1)", padding: "36px 28px" }}>
              <div className="serif" style={{ fontSize: "clamp(40px, 5vw, 60px)", lineHeight: 1, color: "var(--amber)", letterSpacing: "-0.02em" }}>
                <AnimatedStat text={s.k} duration={1200} />
              </div>
              <div style={{ marginTop: 14, fontSize: 13, color: "var(--mute)", lineHeight: 1.5 }}>{s.v}</div>
              {s.note && (
                <div className="mono" style={{ marginTop: 8, fontSize: 10, letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--mute-2)" }}>
                  {s.note}
                </div>
              )}
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

function FAQ({ t, lang }) {
  return (
    <section id="faq" style={{ padding: "120px 0", borderTop: "1px solid var(--line)" }}>
      <div className="wrap">
        <SectionLabel eyebrow={t.faq.eyebrow} title={t.faq.title} lang={lang} />
        <div data-reveal style={{ borderTop: "1px solid var(--line-2)" }}>
          {t.faq.items.map((it, i) => (
            <details key={i} className="faq" style={{ borderBottom: "1px solid var(--line-2)" }}>
              <summary style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 16, padding: "26px 0", outline: "none" }}>
                <span className="serif" style={{ fontSize: "clamp(20px, 2.4vw, 26px)", color: "var(--bone)", letterSpacing: "-0.01em" }}>{it.q}</span>
                <span className="faq-icon" style={{ width: 28, height: 28, borderRadius: "50%", border: "1px solid var(--line-2)", display: "inline-flex", alignItems: "center", justifyContent: "center", color: "var(--mute)", fontSize: 18, lineHeight: 1, flexShrink: 0, transition: "transform .3s ease" }}>+</span>
              </summary>
              <div className="faq-body">
                <div>
                  <p style={{ margin: 0, paddingBottom: 28, paddingInlineEnd: "10%", fontSize: 16, lineHeight: 1.65, color: "var(--mute)" }}>{it.a}</p>
                </div>
              </div>
            </details>
          ))}
        </div>
      </div>
    </section>
  );
}

function FinalCTA({ t, lang }) {
  return (
    <section style={{ padding: "120px 0", borderTop: "1px solid var(--line)", background: "var(--ink-0)", position: "relative", overflow: "hidden" }}>
      {/* faint amber glow */}
      <div aria-hidden style={{ position: "absolute", inset: 0, background: "radial-gradient(ellipse at center, rgba(245,165,36,0.08), transparent 60%)" }} />
      <div className="wrap" style={{ position: "relative", textAlign: "center" }} data-reveal>
        <h2 className="serif" style={{ fontSize: "clamp(40px, 6vw, 72px)", lineHeight: 1, letterSpacing: "-0.02em", margin: 0, color: "var(--bone)" }}>
          {t.finalCta.title}
        </h2>
        <p style={{ marginTop: 20, marginBottom: 40, fontSize: 18, color: "var(--mute)" }}>{t.finalCta.sub}</p>
        <div style={{ display: "flex", flexWrap: "wrap", gap: 12, justifyContent: "center" }}>
          <a href={WA.beirut} target="_blank" rel="noopener" className="btn btn-wa" style={{ minWidth: 220 }}>
            <WAIcon /> {t.finalCta.beirut}
          </a>
          <a href={WA.china} target="_blank" rel="noopener" className="btn btn-ghost" style={{ minWidth: 220 }}>
            <WAIcon /> {t.finalCta.china}
          </a>
        </div>
      </div>
    </section>
  );
}

function CrossPromo({ t, lang }) {
  return (
    <section style={{ padding: "80px 0", borderTop: "1px solid var(--line)", background: "var(--ink-0)" }}>
      <div className="wrap" data-reveal style={{ display: "flex", flexWrap: "wrap", alignItems: "center", justifyContent: "space-between", gap: 32 }}>
        <div style={{ flex: "1 1 360px" }}>
          <div className="eyebrow" style={{ marginBottom: 14 }}>{t.crossPromo.eyebrow}</div>
          <h3 className="serif" style={{ fontSize: "clamp(26px, 3.4vw, 40px)", letterSpacing: "-0.015em", lineHeight: 1.05, margin: 0, color: "var(--bone)" }}>
            {t.crossPromo.title}
          </h3>
          <p style={{ marginTop: 12, marginBottom: 0, fontSize: 15, lineHeight: 1.6, color: "var(--mute)", maxWidth: 560 }}>
            {t.crossPromo.sub}
          </p>
        </div>
        <a href={SHIPPING_URL} target="_blank" rel="noopener" className="nudge-cta"
           style={{
             color: "var(--amber)", textDecoration: "none", fontSize: 16,
             borderBottom: "1px solid rgba(232,115,46,0.4)", paddingBottom: 4,
             display: "inline-flex", alignItems: "center", gap: 10, transition: "border-color .3s cubic-bezier(.16,1,.3,1)",
           }}
           onMouseEnter={(e) => (e.currentTarget.style.borderColor = "var(--amber)")}
           onMouseLeave={(e) => (e.currentTarget.style.borderColor = "rgba(232,115,46,0.4)")}>
          {t.crossPromo.cta} <span className="flip nudge-arrow">→</span>
        </a>
      </div>
    </section>
  );
}

function Footer({ t, lang }) {
  const ql = t.footer.quickLinks;
  return (
    <footer style={{ padding: "72px 0 36px", borderTop: "1px solid var(--line)", background: "var(--ink-0)" }}>
      <div className="wrap">
        <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))", gap: 40, marginBottom: 56 }}>
          {t.footer.offices.map((o, i) => (
            <div key={i}>
              <h4 className="serif" style={{ margin: 0, fontSize: 20, color: "var(--bone)", letterSpacing: "-0.005em" }}>{o.name}</h4>
              <div style={{ marginTop: 14, fontSize: 13, lineHeight: 1.7, color: "var(--mute)" }}>
                {o.lines.map((l, j) => <div key={j}>{l}</div>)}
              </div>
              <a href={"tel:" + o.tel} style={{ marginTop: 10, display: "inline-block", fontSize: 13, color: "var(--bone)", textDecoration: "none", borderBottom: "1px solid var(--line-2)", paddingBottom: 2, transition: "border-color .2s" }}
                 onMouseEnter={(e) => (e.currentTarget.style.borderColor = "var(--amber)")}
                 onMouseLeave={(e) => (e.currentTarget.style.borderColor = "var(--line-2)")}>
                {o.phone}
              </a>
            </div>
          ))}
          <div>
            <h4 className="serif" style={{ margin: 0, fontSize: 20, color: "var(--bone)", letterSpacing: "-0.005em" }}>{ql.label}</h4>
            <div style={{ marginTop: 14, display: "flex", flexDirection: "column", gap: 8 }}>
              {ql.items.map((it, j) => (
                <a key={j} href={it.href} target="_blank" rel="noopener"
                   style={{ fontSize: 13, color: "var(--mute)", textDecoration: "none", transition: "color .2s" }}
                   onMouseEnter={(e) => (e.currentTarget.style.color = "var(--amber)")}
                   onMouseLeave={(e) => (e.currentTarget.style.color = "var(--mute)")}>
                  {it.k}
                </a>
              ))}
            </div>
          </div>
        </div>
        <div style={{ paddingTop: 28, borderTop: "1px solid var(--line)", display: "flex", flexWrap: "wrap", alignItems: "center", justifyContent: "space-between", gap: 24 }}>
          <Wordmark small />
          <div style={{ fontSize: 12, color: "var(--mute-2)", maxWidth: 480, lineHeight: 1.6 }}>
            {t.footer.tag}
          </div>
          <div className="mono" style={{ fontSize: 11, color: "var(--mute-2)", letterSpacing: "0.05em" }}>
            {t.footer.legal}
          </div>
        </div>
      </div>
    </footer>
  );
}

function StickyMobileCTA({ t, lang }) {
  const [show, setShow] = useStateS(false);
  useEffectS(() => {
    const onScroll = () => setShow(window.scrollY > window.innerHeight * 0.6);
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);
  return (
    <div className={"sticky-wa " + (show ? "show" : "")} aria-hidden={!show}>
      <a href={WA.beirut} target="_blank" rel="noopener" className="btn btn-wa" style={{ flex: 1, padding: "14px 16px", fontSize: 14 }}>
        <WAIcon /> {t.finalCta.beirut}
      </a>
    </div>
  );
}

function Marquee({ lang }) {
  const items = lang === "en"
    ? ["Guangzhou", "Yiwu", "Beirut", "BYD", "Zeekr", "Hongqi", "Geely", "23 years", "China–Lebanon", "Door to door"]
    : ["غوانغجو", "ييوو", "بيروت", "بي واي دي", "زيكر", "هونغتشي", "جيلي", "٢٣ سنة", "الصين–لبنان", "من الباب إلى الباب"];
  const seq = [...items, ...items];
  return (
    <div className="marquee" aria-hidden>
      <div className="marquee-track serif" style={{ fontSize: 22, fontStyle: "italic", color: "var(--mute-2)" }}>
        {seq.map((w, i) => (
          <span key={i} style={{ display: "inline-flex", alignItems: "center", gap: 48 }}>
            {w}
            <span style={{ width: 6, height: 6, borderRadius: "50%", background: "var(--amber)", display: "inline-block" }} />
          </span>
        ))}
      </div>
    </div>
  );
}

window.Nav = Nav;
window.Hero = Hero;
window.HowItWorks = HowItWorks;
window.WhyDirect = WhyDirect;
window.CarsGrid = CarsGrid;
window.TrustBlock = TrustBlock;
window.FAQ = FAQ;
window.FinalCTA = FinalCTA;
window.Footer = Footer;
window.CrossPromo = CrossPromo;
window.StickyMobileCTA = StickyMobileCTA;
window.Marquee = Marquee;
window.WAIcon = WAIcon;
