// the-practice.jsx — ABC "The Practice" page
// HOW we build (not what): our method, our craft, our standard.
// The way we work · the work you never see · the crafts in our own
// hands · before it's permanent. Bilingual EN/AR. No overlap with
// Home (what we do) or the Client Guide (the build journey).
// Babel @7.29.0 — PINNED. Do not change CDN version.

const { useEffect, useRef, useState, useContext, createContext } = React;
const ABC = window.AC_DATA;
const P = window.AC_DATA.PRACTICE;
const t = (val, lang) => window.AC_T(val, lang);

const rich = (str) => {
  if (!str || !str.includes('*')) return str;
  const parts = str.split(/(\*[^*]+\*)/);
  return parts.map((p, i) =>
    p.startsWith('*') && p.endsWith('*') && p.length > 2
      ? <span key={i} className="it">{p.slice(1, -1)}</span>
      : p
  );
};

// ---- Lang context ----
const LangContext = createContext({ lang: "en", setLang: () => {} });
const useLang = () => useContext(LangContext);

const LangProvider = ({ children }) => {
  const [lang, setLang] = useState(() => {
    try {
      const q = new URLSearchParams(window.location.search).get("lang");
      if (q === "en" || q === "ar") return q;
      return localStorage.getItem("ac_lang") || localStorage.getItem("abc_lang") || "en";
    } catch { return "en"; }
  });
  useEffect(() => {
    const isAr = lang === "ar";
    document.documentElement.lang = lang;
    document.documentElement.dir = isAr ? "rtl" : "ltr";
    document.body.classList.toggle("is-ar", isAr);
    try { localStorage.setItem("ac_lang", lang); } catch {}
  }, [lang]);
  return (
    <LangContext.Provider value={{ lang, setLang }}>
      {children}
    </LangContext.Provider>
  );
};

// ---- Reveal ----
const revealObs = (() => {
  if (typeof window === "undefined") return null;
  const obs = new IntersectionObserver((entries) => {
    entries.forEach(e => {
      if (e.isIntersecting) { e.target.classList.add("in"); obs.unobserve(e.target); }
    });
  }, { threshold: 0.08, rootMargin: "0px" });
  return obs;
})();

const Reveal = ({ children, delay = 0, as: As = "div", className = "", style, ...rest }) => {
  const ref = useRef(null);
  useEffect(() => {
    const el = ref.current;
    if (!el || !revealObs) return;
    if (delay) el.style.transitionDelay = `${delay}ms`;
    revealObs.observe(el);
    return () => revealObs.unobserve(el);
  }, [delay]);
  return <As ref={ref} className={`reveal ${className}`} style={style} {...rest}>{children}</As>;
};

// ---- Scroll state ----
const useScrolled = (threshold = 24) => {
  const [scrolled, setScrolled] = useState(false);
  useEffect(() => {
    const cb = () => setScrolled(window.scrollY > threshold);
    window.addEventListener("scroll", cb, { passive: true });
    cb();
    return () => window.removeEventListener("scroll", cb);
  }, [threshold]);
  return scrolled;
};

const useScrollProgress = () => {
  const [p, setP] = useState(0);
  useEffect(() => {
    const cb = () => {
      const h = document.documentElement;
      const max = h.scrollHeight - h.clientHeight;
      setP(max > 0 ? Math.min(1, h.scrollTop / max) : 0);
    };
    window.addEventListener("scroll", cb, { passive: true }); cb();
    return () => window.removeEventListener("scroll", cb);
  }, []);
  return p;
};

const useSectionProgress = (ref) => {
  const [p, setP] = useState(0);
  useEffect(() => {
    const cb = () => {
      if (!ref.current) return;
      const rect = ref.current.getBoundingClientRect();
      const vh = window.innerHeight;
      const total = rect.height + vh;
      const scrolled = vh - rect.top;
      setP(Math.min(1, Math.max(0, scrolled / total)));
    };
    window.addEventListener("scroll", cb, { passive: true });
    cb();
    return () => window.removeEventListener("scroll", cb);
  }, [ref]);
  return p;
};

// ---- Lang toggle ----
const LangToggle = () => {
  const { lang, setLang } = useLang();
  return (
    <div className="lang-toggle" role="group" aria-label="Language">
      <button className={lang === "en" ? "active" : ""} onClick={() => setLang("en")} aria-pressed={lang === "en"} lang="en">EN</button>
      <span className="lang-toggle__sep" aria-hidden="true">·</span>
      <button className={lang === "ar" ? "active" : ""} onClick={() => setLang("ar")} aria-pressed={lang === "ar"} lang="ar">AR</button>
    </div>
  );
};

// ---- TopBar ----
const TopBar = () => {
  const { lang } = useLang();
  const scrolled = useScrolled();
  const [menuOpen, setMenuOpen] = useState(false);
  const closeMenu = () => setMenuOpen(false);
  return (
    <header className={`topbar${scrolled ? " topbar--scrolled" : ""}${menuOpen ? " topbar--menu" : ""}`}>
      <div className="topbar__inner">
        <a className="topbar__brand" href="/" aria-label="Albanna Conwood">
          <img className="brand-logo brand-logo--color"
            src={lang === "ar" ? "assets/logo-ar-color.png?v=23" : "assets/logo-en-color.png?v=23"}
            alt="Albanna Conwood Construction L.L.C — Since 1981" />
          <img className="brand-logo brand-logo--mark" src="assets/logo-mark.png?v=23" alt="" aria-hidden="true" />
        </a>
        <nav className={`topbar__nav${menuOpen ? " is-open" : ""}`} aria-label="Page navigation">
          <a href="/the-practice.html" className="active" onClick={closeMenu}>{lang === "ar" ? "منهجنا" : "The Practice"}</a>
          <a href="/client-guide.html" onClick={closeMenu}>{lang === "ar" ? "دليل المالك" : "Client Guide"}</a>
        </nav>
        <div className="topbar__actions">
          <LangToggle />
          <button
            type="button"
            className="topbar__burger"
            aria-label={lang === "ar" ? "القائمة" : "Menu"}
            aria-expanded={menuOpen}
            onClick={() => setMenuOpen((o) => !o)}
          >
            <span /><span /><span />
          </button>
        </div>
      </div>
      <div className="topbar__scrim" aria-hidden="true" onClick={closeMenu} />
    </header>
  );
};

// ---- Footer ----
const Footer = () => {
  const { lang } = useLang();
  return (
    <footer className="footer">
      <div className="footer__bar">
        <div className="footer__brand">
          <img className="brand-logo brand-logo--color"
            src={lang === "ar" ? "assets/logo-ar-color.png?v=23" : "assets/logo-en-color.png?v=23"}
            alt="Albanna Conwood Construction L.L.C" />
          <img className="brand-logo brand-logo--white"
            src={lang === "ar" ? "assets/logo-ar-white.png?v=23" : "assets/logo-en-white.png?v=23"}
            alt="Albanna Conwood Construction L.L.C" />
        </div>
        <span className="footer__copy">{t(ABC.UI.footer_copyright, lang)}</span>
      </div>
    </footer>
  );
};


// ================================================================
// THE ALBANNA STANDARD — three promises
// ================================================================
/* PILLAR_ICONS removed — replaced by ghost ordinal numerals in CSS */
const _UNUSED = [
  <svg className="bp-detail-svg" viewBox="0 0 160 120" fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
    {/* Column: left face, right face, cap */}
    <path className="drw" pathLength="1" strokeWidth="2" d="M52 6 V64 M108 6 V64 M52 6 H108" style={{animationDelay:'0s'}}/>
    {/* Concrete cross-hatch fill */}
    <path className="drw" pathLength="1" strokeWidth="0.9" d="M52 20 L66 6 M52 36 L80 8 M52 52 L94 10 M58 64 L108 14 M74 64 L108 30 M90 64 L108 46 M104 64 L108 60" style={{animationDelay:'0.28s'}}/>
    {/* Ground line */}
    <line className="drw" pathLength="1" strokeWidth="1.8" x1="8" y1="64" x2="152" y2="64" style={{animationDelay:'0.14s'}}/>
    {/* Earth hatching below footing */}
    <path className="drw" pathLength="1" strokeWidth="0.9" d="M8 100 L16 110 M22 100 L30 110 M36 100 L44 110 M50 100 L58 110 M64 100 L72 110 M78 100 L86 110 M92 100 L100 110 M106 100 L114 110 M120 100 L128 110 M134 100 L142 110 M148 100 L156 110" style={{animationDelay:'0.42s'}}/>
    {/* 4 rebar corner bars (emerald) — the invisible steel skeleton */}
    <circle className="drw bp-live" pathLength="1" strokeWidth="2" cx="64" cy="20" r="5" style={{animationDelay:'0.65s'}}/>
    <circle className="drw bp-live" pathLength="1" strokeWidth="2" cx="96" cy="20" r="5" style={{animationDelay:'0.73s'}}/>
    <circle className="drw bp-live" pathLength="1" strokeWidth="2" cx="64" cy="52" r="5" style={{animationDelay:'0.80s'}}/>
    <circle className="drw bp-live" pathLength="1" strokeWidth="2" cx="96" cy="52" r="5" style={{animationDelay:'0.87s'}}/>
    {/* Upper footing step (emerald) */}
    <path className="drw bp-live" pathLength="1" strokeWidth="2" d="M36 64 H124 V78 H36 Z" style={{animationDelay:'0.96s'}}/>
    {/* Lower footing step — wider spread (emerald) */}
    <path className="drw bp-live" pathLength="1" strokeWidth="2" d="M18 78 H142 V92 H18 Z" style={{animationDelay:'1.12s'}}/>
    {/* Footing horizontal rebar (emerald) */}
    <line className="drw bp-live" pathLength="1" strokeWidth="1.6" x1="22" y1="86" x2="138" y2="86" style={{animationDelay:'1.28s'}}/>
    <circle className="bp-detail-dot" cx="80" cy="86" r="2.5" fill="currentColor" stroke="none" style={{animationDelay:'1.9s'}}/>
  </svg>,

  /* 2. We test before we build
     A full-size sample wall panel propped on an easel, showing masonry bond pattern.
     Dimension annotations in emerald confirm it is being tested at actual scale. */
  <svg className="bp-detail-svg" viewBox="0 0 160 120" fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
    {/* Easel: left leg, right leg, crossbar */}
    <line className="drw" pathLength="1" strokeWidth="1.6" x1="52" y1="18" x2="28" y2="110" style={{animationDelay:'0s'}}/>
    <line className="drw" pathLength="1" strokeWidth="1.6" x1="108" y1="18" x2="132" y2="110" style={{animationDelay:'0.06s'}}/>
    <line className="drw" pathLength="1" strokeWidth="1.4" x1="34" y1="84" x2="126" y2="84" style={{animationDelay:'0.12s'}}/>
    {/* Sample wall panel */}
    <rect className="drw" pathLength="1" strokeWidth="2" x="36" y="10" width="88" height="76" rx="2" style={{animationDelay:'0.24s'}}/>
    {/* Masonry bond: bed joints (horizontal) */}
    <path className="drw" pathLength="1" strokeWidth="0.9" d="M36 26 H124 M36 42 H124 M36 58 H124 M36 74 H124" style={{animationDelay:'0.40s'}}/>
    {/* Masonry bond: perpend joints (alternating offset per course) */}
    <path className="drw" pathLength="1" strokeWidth="0.9" d="M80 10 V26 M58 26 V42 M102 26 V42 M80 42 V58 M58 58 V74 M102 58 V74 M80 74 V86" style={{animationDelay:'0.48s'}}/>
    {/* Height dimension annotation (emerald) */}
    <line className="drw bp-live" pathLength="1" strokeWidth="1.4" x1="20" y1="10" x2="20" y2="86" style={{animationDelay:'0.70s'}}/>
    <path className="drw bp-live" pathLength="1" strokeWidth="1.4" d="M14 10 H26 M14 86 H26" style={{animationDelay:'0.80s'}}/>
    {/* Width dimension annotation (emerald) */}
    <line className="drw bp-live" pathLength="1" strokeWidth="1.4" x1="36" y1="100" x2="124" y2="100" style={{animationDelay:'0.90s'}}/>
    <path className="drw bp-live" pathLength="1" strokeWidth="1.4" d="M36 94 V106 M124 94 V106" style={{animationDelay:'1.00s'}}/>
    {/* Scale label — two short lines (emerald) */}
    <path className="drw bp-live" pathLength="1" strokeWidth="1.8" d="M132 30 H150 M132 38 H150" style={{animationDelay:'1.10s'}}/>
    <circle className="bp-detail-dot" cx="80" cy="48" r="2.5" fill="currentColor" stroke="none" style={{animationDelay:'1.85s'}}/>
  </svg>,

  /* 3. Skilled hands that stay
     Two courses of brickwork in running bond. A trowel (blade + handle + grip rings) held at
     an angle spreading the fresh mortar bed — shown in emerald — onto the top course. */
  <svg className="bp-detail-svg" viewBox="0 0 160 120" fill="none" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
    {/* Bottom course: two bricks in running bond */}
    <rect className="drw" pathLength="1" strokeWidth="1.8" x="6" y="86" width="66" height="28" rx="2" style={{animationDelay:'0s'}}/>
    <rect className="drw" pathLength="1" strokeWidth="1.8" x="80" y="86" width="74" height="28" rx="2" style={{animationDelay:'0.06s'}}/>
    {/* Top course: three bricks, offset (running bond) */}
    <rect className="drw" pathLength="1" strokeWidth="1.8" x="6" y="58" width="36" height="28" rx="2" style={{animationDelay:'0.12s'}}/>
    <rect className="drw" pathLength="1" strokeWidth="1.8" x="50" y="58" width="74" height="28" rx="2" style={{animationDelay:'0.18s'}}/>
    <rect className="drw" pathLength="1" strokeWidth="1.8" x="132" y="58" width="22" height="28" rx="2" style={{animationDelay:'0.22s'}}/>
    {/* Fresh mortar bed on top of upper course (emerald) */}
    <line className="drw bp-live" pathLength="1" strokeWidth="4" x1="6" y1="55" x2="154" y2="55" style={{animationDelay:'0.38s'}}/>
    {/* Trowel blade — angled kite shape, tip at lower-left pressing the mortar */}
    <path className="drw" pathLength="1" strokeWidth="2" d="M12 58 L48 30 L108 16 L112 28 L58 50 Z" style={{animationDelay:'0.56s'}}/>
    {/* Handle */}
    <line className="drw" pathLength="1" strokeWidth="2.4" x1="110" y1="22" x2="148" y2="8" style={{animationDelay:'0.66s'}}/>
    {/* Ferrule collar */}
    <line className="drw" pathLength="1" strokeWidth="1.4" x1="104" y1="14" x2="116" y2="28" style={{animationDelay:'0.73s'}}/>
    {/* Handle grip rings */}
    <line className="drw" pathLength="1" strokeWidth="1.2" x1="120" y1="19" x2="126" y2="12" style={{animationDelay:'0.78s'}}/>
    <line className="drw" pathLength="1" strokeWidth="1.2" x1="131" y1="15" x2="137" y2="8" style={{animationDelay:'0.82s'}}/>
    {/* Mortar loaded on blade (emerald arc) */}
    <path className="drw bp-live" pathLength="1" strokeWidth="2" d="M16 54 Q56 38 104 20" style={{animationDelay:'0.96s'}}/>
    <circle className="bp-detail-dot" cx="60" cy="38" r="2.5" fill="currentColor" stroke="none" style={{animationDelay:'1.85s'}}/>
  </svg>,
];

const StandardDetailSVG = ({ revealed, style }) => (
  <svg
    className={`std-ghost-detail-svg${revealed ? " is-revealed" : ""}`}
    aria-hidden="true"
    style={style}
    viewBox="0 0 400 320"
    xmlns="http://www.w3.org/2000/svg"
  >
    <defs>
      <clipPath id="std-clip-grid">
        <rect className="std-clip-rect std-clip-rect--a" x="0" y="0" width="400" height="320" />
      </clipPath>
      <clipPath id="std-clip-ticks">
        <rect className="std-clip-rect std-clip-rect--b" x="0" y="0" width="400" height="320" />
      </clipPath>
      <clipPath id="std-clip-arrows">
        <rect className="std-clip-rect std-clip-rect--c" x="0" y="0" width="400" height="320" />
      </clipPath>
    </defs>
    <g clipPath="url(#std-clip-grid)">
      <line x1="40" y1="20" x2="360" y2="20" />
      <line x1="40" y1="60" x2="360" y2="60" />
      <line x1="40" y1="100" x2="360" y2="100" />
      <line x1="40" y1="140" x2="200" y2="140" />
      <line x1="40" y1="20" x2="40" y2="160" />
      <line x1="120" y1="20" x2="120" y2="160" />
      <line x1="200" y1="20" x2="200" y2="140" />
      <line x1="40" y1="60" x2="120" y2="60" strokeDasharray="3 5" />
      <line x1="120" y1="100" x2="200" y2="60" strokeDasharray="3 5" />
    </g>
    <g clipPath="url(#std-clip-ticks)">
      <line x1="40" y1="15" x2="40" y2="25" />
      <line x1="120" y1="15" x2="120" y2="25" />
      <line x1="200" y1="15" x2="200" y2="25" />
      <line x1="280" y1="15" x2="280" y2="25" />
      <line x1="360" y1="15" x2="360" y2="25" />
      <line x1="35" y1="20" x2="45" y2="20" />
      <line x1="35" y1="60" x2="45" y2="60" />
      <line x1="35" y1="100" x2="45" y2="100" />
      <line x1="35" y1="140" x2="45" y2="140" />
      <text x="78" y="13" className="std-svg-label">80cm</text>
      <text x="152" y="13" className="std-svg-label">160cm</text>
      <text x="232" y="13" className="std-svg-label">240cm</text>
      <text x="22" y="64" className="std-svg-label" textAnchor="end">A</text>
      <text x="22" y="104" className="std-svg-label" textAnchor="end">B</text>
      <text x="22" y="144" className="std-svg-label" textAnchor="end">C</text>
    </g>
    <g clipPath="url(#std-clip-arrows)">
      <line x1="220" y1="180" x2="340" y2="180" />
      <polygon points="340,176 350,180 340,184" />
      <polygon points="220,176 210,180 220,184" />
      <line x1="280" y1="170" x2="280" y2="190" strokeDasharray="2 4" />
      <text x="280" y="210" className="std-svg-label" textAnchor="middle">±0.5mm</text>
      <line x1="250" y1="240" x2="310" y2="240" />
      <line x1="250" y1="235" x2="250" y2="245" />
      <line x1="310" y1="235" x2="310" y2="245" />
      <text x="280" y="260" className="std-svg-label" textAnchor="middle">joint</text>
      <line x1="60" y1="200" x2="60" y2="290" strokeDasharray="4 4" />
      <line x1="55" y1="200" x2="65" y2="200" />
      <line x1="55" y1="290" x2="65" y2="290" />
      <text x="72" y="250" className="std-svg-label">h=90</text>
      <rect x="130" y="195" width="48" height="28" rx="1" fill="none" />
      <line x1="130" y1="202" x2="178" y2="202" />
      <line x1="154" y1="195" x2="154" y2="223" />
      <text x="154" y="238" className="std-svg-label" textAnchor="middle">struct.</text>
    </g>
  </svg>
);

const Standard = () => {
  const { lang } = useLang();
  const sectionRef = useRef(null);
  const p = useSectionProgress(sectionRef);
  const svgRevealClass = p > 0.4;
  const svgOpacity = Math.max(0, (p - 0.4) / 0.6);
  const ghostWord = lang === "ar" ? t(P.standard_title_em, "ar") : t(P.standard_title_em, "en");

  return (
    <section id="standard" className="practice-section practice-standard" ref={sectionRef}>
      <div className="std-ghost-wrap" aria-hidden="true">
        <StandardDetailSVG revealed={svgRevealClass} style={{ opacity: svgOpacity, transform: `translate(-50%, calc(-50% + ${p * -40}px))` }} />
        <span
          className="std-ghost-word"
          style={{
            transform: `scale(${p * 3.8 + 1.2})`,
            filter: `blur(${(1 - p) * 12}px)`,
            letterSpacing: `${-p * 0.04}em`,
            willChange: "transform, filter",
          }}
        >
          {ghostWord}
        </span>
      </div>
      <div className="bp-wrap">
        <div
          className="section-head practice-section__head bp-head"
          style={{ transform: `translateY(${-p * 28}px)` }}
        >
          <Reveal as="span" className="section-eyebrow">
            <span className="rule" aria-hidden="true" />
            {t(P.standard_eyebrow, lang)}
          </Reveal>
          <Reveal as="h2" className="section-title" delay={80}>
            {t(P.standard_title_a, lang)}<span className="it">{t(P.standard_title_em, lang)}</span>
          </Reveal>
        </div>
        <ul className="bp-notes">
          {P.standard_pillars.map((pillar, i) => (
            <Reveal as="li" key={i} className="bp-note" delay={i * 130}>
              <h3 className="bp-note__heading">{t(pillar.heading, lang)}</h3>
              <p className="bp-note__line">{rich(t(pillar.line, lang))}</p>
            </Reveal>
          ))}
        </ul>
      </div>
    </section>
  );
};

// ================================================================
// THE WORK YOU NEVER SEE — a drawn wall section on drafting paper
// ================================================================
const LAYER_SWATCH = [
  /* finish — visible face */
  <svg viewBox="0 0 46 30" className="bp-swatch-svg" fill="none" aria-hidden="true">
    <rect className="bp-sw-edge" x="0.75" y="0.75" width="44.5" height="28.5" />
    <line className="bp-sw-fine" x1="12" y1="0.75" x2="12" y2="29.25" />
    <line className="bp-sw-fine" x1="23" y1="0.75" x2="23" y2="29.25" />
    <line className="bp-sw-fine" x1="34" y1="0.75" x2="34" y2="29.25" />
    <line className="bp-sw-em" x1="0.75" y1="2.5" x2="45.25" y2="2.5" />
  </svg>,
  /* substrate — running bond */
  <svg viewBox="0 0 46 30" className="bp-swatch-svg" fill="none" aria-hidden="true">
    <rect className="bp-sw-edge" x="0.75" y="0.75" width="44.5" height="28.5" />
    <line className="bp-sw-fine" x1="0.75" y1="11" x2="45.25" y2="11" />
    <line className="bp-sw-fine" x1="0.75" y1="20" x2="45.25" y2="20" />
    <line className="bp-sw-fine" x1="16" y1="0.75" x2="16" y2="11" />
    <line className="bp-sw-fine" x1="31" y1="0.75" x2="31" y2="11" />
    <line className="bp-sw-fine" x1="9"  y1="11"   x2="9"  y2="20" />
    <line className="bp-sw-fine" x1="24" y1="11"   x2="24" y2="20" />
    <line className="bp-sw-fine" x1="38" y1="11"   x2="38" y2="20" />
    <line className="bp-sw-fine" x1="16" y1="20"   x2="16" y2="29.25" />
    <line className="bp-sw-fine" x1="31" y1="20"   x2="31" y2="29.25" />
  </svg>,
  /* services — conduit + box */
  <svg viewBox="0 0 46 30" className="bp-swatch-svg" fill="none" aria-hidden="true">
    <rect className="bp-sw-edge" x="0.75" y="0.75" width="44.5" height="28.5" />
    <line className="bp-sw-dash" x1="4" y1="15" x2="42" y2="15" />
    <rect className="bp-sw-fine" x="30" y="10" width="10" height="10" />
  </svg>,
  /* waterproofing — sealed membrane */
  <svg viewBox="0 0 46 30" className="bp-swatch-svg" fill="none" aria-hidden="true">
    <rect className="bp-sw-solid" x="0.75" y="0.75" width="44.5" height="28.5" />
  </svg>,
  /* structure — reinforced concrete */
  <svg viewBox="0 0 46 30" className="bp-swatch-svg" fill="none" aria-hidden="true">
    <rect className="bp-sw-edge" x="0.75" y="0.75" width="44.5" height="28.5" />
    <line className="bp-sw-fine" x1="4"  y1="29" x2="20" y2="3" />
    <line className="bp-sw-fine" x1="18" y1="29" x2="34" y2="3" />
    <line className="bp-sw-fine" x1="32" y1="29" x2="45" y2="7" />
    <circle className="bp-sw-dot" cx="13" cy="11" r="1.6" />
    <circle className="bp-sw-dot" cx="30" cy="18" r="1.6" />
  </svg>,
];

const WallSection = ({ lang }) => {
  const LAYER_Y   = [84, 176, 306, 396, 504];
  const BANDS     = [[44, 112], [112, 240], [240, 350], [350, 420], [420, 588]];
  const NUMS      = ["01", "02", "03", "04", "05"];
  const [active, setActive] = useState(-1);
  const layerNames = P.buildup_layers.map(ly => t(ly.name, lang));
  const layerNotes = P.buildup_layers.map(ly => t(ly.note, lang));
  const dim = (i) => "bp-dim" + (active === i ? " on" : "");
  return (
  <svg className={"bp-wall" + (active >= 0 ? " has-focus" : "")} viewBox="0 33 580 558" fill="none" role="img"
       aria-label={t(P.buildup_title_a, lang) + t(P.buildup_title_em, lang)}>

    <defs>
      <clipPath id="bpwFaceClip"><rect x="150" y="52" width="180" height="12" /></clipPath>
      <clipPath id="bpwMemClip"><rect x="150" y="372" width="180" height="48" /></clipPath>
      <linearGradient id="bpwGlint" x1="0" y1="0" x2="1" y2="0">
        <stop offset="0" stopColor="#bfe4db" stopOpacity="0" />
        <stop offset="0.5" stopColor="#d8f0e9" stopOpacity="0.9" />
        <stop offset="1" stopColor="#bfe4db" stopOpacity="0" />
      </linearGradient>
      <linearGradient id="bpwSheen" x1="0" y1="0" x2="1" y2="0">
        <stop offset="0" stopColor="#f2f3f4" stopOpacity="0" />
        <stop offset="0.5" stopColor="#f2f3f4" stopOpacity="0.30" />
        <stop offset="1" stopColor="#f2f3f4" stopOpacity="0" />
      </linearGradient>
    </defs>

    {/* ── Callout annotations — leader line from label to each wall zone ── */}
    <g className="bp-wall__callouts">
      {LAYER_Y.map((y, i) => (
        <g key={i} className={dim(i)}>
          <text className="bp-wall__callout-num" x="12" y={y - 34}>{NUMS[i]}</text>
          <text className="bp-wall__callout-name" x="12" y={y - 10}>{layerNames[i]}</text>
          <text className="bp-wall__callout-note" x="12" y={y + 14}>{layerNotes[i]}</text>
          <line className="drw bp-wall__callout-lead" pathLength="1"
                style={{ transitionDelay: (260 + i * 130) + "ms" }}
                x1="12" y1={y} x2="354" y2={y} />
          <circle className="bp-wall__callout-dot" cx="357" cy={y} r="2.6" fill="rgba(42,38,34,0.5)" />
          <circle className="bp-wall__callout-ping" style={{ animationDelay: (i * 1.1) + "s" }} cx="357" cy={y} r="3" />
        </g>
      ))}
    </g>

    {/* ── Wall cross-section — shifted right to make room for callouts ── */}
    <g transform="translate(210, 0)">

    {/* Zone background fills — one per layer, dimmable, with focus glow */}
    <g className={dim(0)}>
      <rect x="150" y="56"  width="180" height="56"  fill="rgba(78,131,124,0.12)" />
      <rect className="bp-zoneglow" x="150" y="56"  width="180" height="56" />
    </g>
    <g className={dim(1)}>
      <rect x="150" y="112" width="180" height="128" fill="rgba(190,175,150,0.10)" />
      <rect className="bp-zoneglow" x="150" y="112" width="180" height="128" />
    </g>
    <g className={dim(2)}>
      <rect x="150" y="240" width="180" height="132" fill="rgba(95,100,105,0.06)" />
      <rect className="bp-zoneglow" x="150" y="240" width="180" height="132" />
    </g>
    <g className={dim(3)}>
      <rect className="bp-zoneglow" x="150" y="372" width="180" height="48" />
    </g>
    <g className={dim(4)}>
      <rect x="150" y="420" width="180" height="168" fill="rgba(42,38,34,0.09)" />
      <rect className="bp-zoneglow" x="150" y="420" width="180" height="168" />
    </g>

    {/* Zone boundary dashes */}
    <line stroke="rgba(42,38,34,0.25)" strokeWidth="1" strokeDasharray="5 3" x1="150" y1="112" x2="330" y2="112"/>
    <line stroke="rgba(42,38,34,0.25)" strokeWidth="1" strokeDasharray="5 3" x1="150" y1="240" x2="330" y2="240"/>
    <line stroke="rgba(42,38,34,0.25)" strokeWidth="1" strokeDasharray="5 3" x1="150" y1="372" x2="330" y2="372"/>
    <line stroke="rgba(42,38,34,0.25)" strokeWidth="1" strokeDasharray="5 3" x1="150" y1="420" x2="330" y2="420"/>

    <g className="bp-wall__dim">
      <line className="drw" pathLength="1" x1="120" y1="56" x2="120" y2="588" />
      <line className="bp-wall__tick" x1="114" y1="56"  x2="126" y2="56" />
      <line className="bp-wall__tick" x1="114" y1="112" x2="126" y2="112" />
      <line className="bp-wall__tick" x1="114" y1="240" x2="126" y2="240" />
      <line className="bp-wall__tick" x1="114" y1="372" x2="126" y2="372" />
      <line className="bp-wall__tick" x1="114" y1="420" x2="126" y2="420" />
      <line className="bp-wall__tick" x1="114" y1="588" x2="126" y2="588" />
      <path className="bp-wall__arw" d="M120 56 l-4 8 M120 56 l4 8" />
      <path className="bp-wall__arw" d="M120 588 l-4 -8 M120 588 l4 -8" />
    </g>

    <rect className="drw bp-wall__frame" pathLength="1" x="150" y="56" width="180" height="532" />

    {/* STRUCTURE — reinforced concrete */}
    <g className={dim(4)}>
    <g className="wsb" style={{ transitionDelay: "60ms" }}>
      <line className="bp-hatch" x1="150" y1="588" x2="210" y2="528" />
      <line className="bp-hatch" x1="150" y1="528" x2="258" y2="420" />
      <line className="bp-hatch" x1="198" y1="588" x2="330" y2="456" />
      <line className="bp-hatch" x1="270" y1="588" x2="330" y2="528" />
      <line className="bp-hatch" x1="150" y1="470" x2="330" y2="470" opacity="0.5" />
      <line className="bp-steel" x1="196" y1="430" x2="196" y2="580" />
      <line className="bp-steel" x1="284" y1="430" x2="284" y2="580" />
      <line className="bp-fine" x1="196" y1="472" x2="284" y2="472" />
      <line className="bp-fine" x1="196" y1="540" x2="284" y2="540" />
      <circle className="bp-agg" cx="168" cy="556" r="2.2" />
      <circle className="bp-agg" style={{ animationDelay: "0.7s" }} cx="238" cy="502" r="2.2" />
      <circle className="bp-agg" style={{ animationDelay: "1.5s" }} cx="308" cy="560" r="2.2" />
      <circle className="bp-agg" style={{ animationDelay: "2.2s" }} cx="170" cy="488" r="1.6" />
      <circle className="bp-agg" style={{ animationDelay: "2.9s" }} cx="310" cy="492" r="1.6" />
    </g>
    </g>

    {/* WATERPROOFING — sealed membrane with a slow sheen passing over */}
    <g className={dim(3)}>
    <g className="wsb" style={{ transitionDelay: "180ms" }}>
      <rect className="bp-membrane" x="150" y="372" width="180" height="48" />
      <line className="bp-membrane-line" x1="150" y1="382" x2="330" y2="382" />
      <line className="bp-membrane-line" x1="150" y1="396" x2="330" y2="396" />
      <line className="bp-membrane-line" x1="150" y1="410" x2="330" y2="410" />
      <g clipPath="url(#bpwMemClip)">
        <rect className="bp-sheen" x="150" y="372" width="46" height="48" fill="url(#bpwSheen)" />
      </g>
    </g>
    </g>

    {/* SERVICES — routed conduit with current flowing to the junction box */}
    <g className={dim(2)}>
    <g className="wsb" style={{ transitionDelay: "300ms" }}>
      <line className="bp-conduit" x1="150" y1="290" x2="292" y2="290" />
      <line className="bp-conduit" x1="150" y1="340" x2="240" y2="340" />
      <rect className="bp-box" x="292" y="278" width="24" height="24" rx="2" />
      <line className="bp-fine" x1="200" y1="290" x2="200" y2="258" />
      <line className="bp-fine" x1="248" y1="290" x2="248" y2="330" />
      <line className="bp-fine" x1="192" y1="340" x2="192" y2="360" />
      <circle className="bp-node" cx="150" cy="290" r="3.4" />
      <circle className="bp-node" cx="150" cy="340" r="3.4" />
      <circle className="bp-flow" cx="150" cy="290" r="2.3" />
      <circle className="bp-flow bp-flow--b" style={{ animationDelay: "1.7s" }} cx="150" cy="340" r="2.3" />
      <circle className="bp-boxpulse" cx="304" cy="290" r="2.6" />
    </g>
    </g>

    {/* SUBSTRATE — running-bond blockwork */}
    <g className={dim(1)}>
    <g className="wsb" style={{ transitionDelay: "420ms" }}>
      <line className="bp-fine" x1="150" y1="143" x2="330" y2="143" />
      <line className="bp-fine" x1="150" y1="176" x2="330" y2="176" />
      <line className="bp-fine" x1="150" y1="209" x2="330" y2="209" />
      <line className="bp-fine" x1="195" y1="112" x2="195" y2="143" />
      <line className="bp-fine" x1="255" y1="112" x2="255" y2="143" />
      <line className="bp-fine" x1="315" y1="112" x2="315" y2="143" />
      <line className="bp-fine" x1="165" y1="143" x2="165" y2="176" />
      <line className="bp-fine" x1="225" y1="143" x2="225" y2="176" />
      <line className="bp-fine" x1="285" y1="143" x2="285" y2="176" />
      <line className="bp-fine" x1="195" y1="176" x2="195" y2="209" />
      <line className="bp-fine" x1="255" y1="176" x2="255" y2="209" />
      <line className="bp-fine" x1="315" y1="176" x2="315" y2="209" />
      <line className="bp-fine" x1="165" y1="209" x2="165" y2="240" />
      <line className="bp-fine" x1="225" y1="209" x2="225" y2="240" />
      <line className="bp-fine" x1="285" y1="209" x2="285" y2="240" />
    </g>
    </g>

    {/* FINISH — the visible face with a passing glint of light */}
    <g className={dim(0)}>
    <g className="wsb" style={{ transitionDelay: "540ms" }}>
      <line className="bp-face-em" x1="150" y1="58" x2="330" y2="58" />
      <line className="bp-fine" x1="195" y1="58" x2="195" y2="112" />
      <line className="bp-fine" x1="240" y1="58" x2="240" y2="112" />
      <line className="bp-fine" x1="285" y1="58" x2="285" y2="112" />
      <line className="bp-fine" x1="150" y1="85" x2="330" y2="85" />
      <g clipPath="url(#bpwFaceClip)">
        <rect className="bp-glint" x="150" y="55" width="64" height="6" fill="url(#bpwGlint)" />
      </g>
    </g>
    </g>

    </g>

    {/* ── Hover hit bands — focus a layer across callout + wall ── */}
    {BANDS.map((b, i) => (
      <rect key={i} className="bp-hit" x="0" y={b[0]} width="580" height={b[1] - b[0]}
            onMouseEnter={() => setActive(i)} onMouseLeave={() => setActive(-1)} />
    ))}
  </svg>
  );
};

const BuildUp = () => {
  const { lang } = useLang();
  const isAr = lang === "ar";
  return (
    <section id="buildup" className="practice-section practice-buildup">
      <div className="bp-wrap bp-buildup__layout">
        <div className="bp-buildup__head">
          <Reveal as="h2" className="section-title" delay={80}>
            {t(P.buildup_title_a, lang)}<span className="it">{t(P.buildup_title_em, lang)}</span>
          </Reveal>
          <Reveal as="p" className="practice-section__intro" delay={140}>{rich(t(P.buildup_intro, lang))}</Reveal>
          <Reveal as="p" className="bp-buildup__caption" delay={160}>{rich(t(P.buildup_caption, lang))}</Reveal>
        </div>
        <div className="bp-buildup__draw">
          <Reveal className="bp-wall-wrap">
            <WallSection lang={lang} />
          </Reveal>
        </div>
      </div>
    </section>
  );
};

// ================================================================
// IN OUR OWN HANDS — the crafts, as bespoke animated material studies
// Each card is a fine architectural line-drawing of the material,
// alive with one restrained, luxurious motion. viewBox 0 0 500 400.
// ================================================================
const CRAFT_SCENES = [
  /* 01 — Concrete & structure: rebar cage, breathing pour, swinging plumb */
  <svg className="cs cs--concrete" viewBox="0 0 500 400" fill="none" aria-hidden="true">
    <defs>
      <clipPath id="cs1col"><rect x="184" y="62" width="150" height="276" /></clipPath>
      <linearGradient id="cs1glint" x1="0" y1="1" x2="0" y2="0">
        <stop offset="0" stopColor="#5fa093" stopOpacity="0" />
        <stop offset="0.5" stopColor="#5fa093" stopOpacity="0.5" />
        <stop offset="1" stopColor="#5fa093" stopOpacity="0" />
      </linearGradient>
    </defs>
    <g clipPath="url(#cs1col)">
      <rect className="cs-pour" x="184" y="62" width="150" height="276" />
      <rect className="cs-riseglint" x="184" y="300" width="150" height="150" fill="url(#cs1glint)" />
    </g>
    <line className="cs-fine" x1="184" y1="44" x2="334" y2="44" />
    <line className="cs-fine" x1="184" y1="39" x2="184" y2="49" />
    <line className="cs-fine" x1="334" y1="39" x2="334" y2="49" />
    <rect className="cs-edge" x="184" y="62" width="150" height="276" />
    <line className="cs-steel" x1="212" y1="68" x2="212" y2="332" />
    <line className="cs-steel" x1="259" y1="68" x2="259" y2="332" />
    <line className="cs-steel" x1="306" y1="68" x2="306" y2="332" />
    <line className="cs-fine" x1="198" y1="96" x2="320" y2="96" />
    <line className="cs-fine" x1="198" y1="142" x2="320" y2="142" />
    <line className="cs-fine" x1="198" y1="188" x2="320" y2="188" />
    <line className="cs-fine" x1="198" y1="234" x2="320" y2="234" />
    <line className="cs-fine" x1="198" y1="280" x2="320" y2="280" />
    <g className="cs-plumb">
      <circle className="cs-emf" cx="120" cy="66" r="2.5" />
      <line className="cs-fine" x1="120" y1="68" x2="120" y2="298" />
      <path className="cs-emf" d="M120 298 L127 302 L123 316 L120 324 L117 316 L113 302 Z" />
    </g>
  </svg>,

  /* 02 — Services & MEP: orthogonal routing with pulses flowing to the board */
  <svg className="cs cs--mep" viewBox="0 0 500 400" fill="none" aria-hidden="true">
    <rect className="cs-edge" x="330" y="150" width="118" height="150" rx="4" />
    <rect className="cs-fine" x="344" y="162" width="90" height="10" />
    <line className="cs-fine" x1="344" y1="192" x2="434" y2="192" />
    <line className="cs-fine" x1="344" y1="212" x2="434" y2="212" />
    <line className="cs-fine" x1="344" y1="232" x2="434" y2="232" />
    <line className="cs-fine" x1="344" y1="252" x2="434" y2="252" />
    <line className="cs-fine" x1="344" y1="272" x2="434" y2="272" />
    <path className="cs-route" d="M62 118 H212 Q230 118 230 136 V172 H330" />
    <path className="cs-route" d="M62 205 H330" />
    <path className="cs-route" d="M62 300 H236 Q254 300 254 282 V240 H330" />
    <circle className="cs-emf" cx="62" cy="118" r="4" />
    <circle className="cs-emf" cx="62" cy="205" r="4" />
    <circle className="cs-emf" cx="62" cy="300" r="4" />
    <path className="cs-pulse" style={{ animationDelay: "0s" }} d="M62 118 H212 Q230 118 230 136 V172 H330" />
    <path className="cs-pulse" style={{ animationDelay: "1.05s" }} d="M62 205 H330" />
    <path className="cs-pulse" style={{ animationDelay: "2.1s" }} d="M62 300 H236 Q254 300 254 282 V240 H330" />
  </svg>,

  /* 03 — Stone & masonry: running-bond ashlar with a raking light drifting across */
  <svg className="cs cs--stone" viewBox="0 0 500 400" fill="none" aria-hidden="true">
    <defs>
      <clipPath id="cs3wall"><rect x="92" y="86" width="316" height="228" /></clipPath>
      <linearGradient id="cs3rake" x1="0" y1="0" x2="1" y2="0">
        <stop offset="0" stopColor="#5fa093" stopOpacity="0" />
        <stop offset="0.5" stopColor="#5fa093" stopOpacity="0.2" />
        <stop offset="1" stopColor="#5fa093" stopOpacity="0" />
      </linearGradient>
    </defs>
    <rect className="cs-edge" x="92" y="86" width="316" height="228" />
    <line className="cs-fine" x1="92" y1="143" x2="408" y2="143" />
    <line className="cs-fine" x1="92" y1="200" x2="408" y2="200" />
    <line className="cs-fine" x1="92" y1="257" x2="408" y2="257" />
    <line className="cs-fine" x1="176" y1="86" x2="176" y2="143" />
    <line className="cs-fine" x1="260" y1="86" x2="260" y2="143" />
    <line className="cs-fine" x1="344" y1="86" x2="344" y2="143" />
    <line className="cs-fine" x1="134" y1="143" x2="134" y2="200" />
    <line className="cs-fine" x1="218" y1="143" x2="218" y2="200" />
    <line className="cs-fine" x1="302" y1="143" x2="302" y2="200" />
    <line className="cs-fine" x1="366" y1="143" x2="366" y2="200" />
    <line className="cs-fine" x1="176" y1="200" x2="176" y2="257" />
    <line className="cs-fine" x1="260" y1="200" x2="260" y2="257" />
    <line className="cs-fine" x1="344" y1="200" x2="344" y2="257" />
    <line className="cs-fine" x1="134" y1="257" x2="134" y2="314" />
    <line className="cs-fine" x1="218" y1="257" x2="218" y2="314" />
    <line className="cs-fine" x1="302" y1="257" x2="302" y2="314" />
    <line className="cs-fine" x1="366" y1="257" x2="366" y2="314" />
    <line className="cs-em" style={{ opacity: 0.5 }} strokeWidth="1.3" strokeDasharray="2 5" x1="92" y1="116" x2="408" y2="116" />
    <g className="cs-rake" clipPath="url(#cs3wall)">
      <rect x="0" y="70" width="150" height="260" fill="url(#cs3rake)" />
    </g>
  </svg>,

  /* 04 — Joinery & finishes: an interlocking joint breathing into a perfect fit */
  <svg className="cs cs--joinery" viewBox="0 0 500 400" fill="none" aria-hidden="true">
    <g className="cs-fit-l">
      <path className="cs-edge" d="M60 122 H272 V162 H250 V202 H272 V242 H250 V282 H60 Z" />
      <line className="cs-fine" x1="80" y1="150" x2="236" y2="150" />
      <line className="cs-fine" x1="80" y1="182" x2="236" y2="182" />
      <line className="cs-fine" x1="80" y1="214" x2="236" y2="214" />
      <line className="cs-fine" x1="80" y1="246" x2="236" y2="246" />
    </g>
    <g className="cs-fit-r">
      <path className="cs-edge" d="M440 122 H272 V162 H250 V202 H272 V242 H250 V282 H440 Z" />
      <line className="cs-fine" x1="300" y1="150" x2="420" y2="150" />
      <line className="cs-fine" x1="300" y1="182" x2="420" y2="182" />
      <line className="cs-fine" x1="300" y1="214" x2="420" y2="214" />
      <line className="cs-fine" x1="300" y1="246" x2="420" y2="246" />
    </g>
    <line className="cs-seam" x1="261" y1="124" x2="261" y2="280" />
  </svg>,

  /* 05 — Aluminum & glass: curtain wall with glass pane tints, sweeping reflection, seal verification */
  <svg className="cs cs--glass" viewBox="0 0 500 400" fill="none" aria-hidden="true">
    <defs>
      <clipPath id="cs5f"><rect x="112" y="70" width="276" height="260" /></clipPath>
      <linearGradient id="cs5g" x1="0" y1="0" x2="1" y2="0">
        <stop offset="0" stopColor="#ffffff" stopOpacity="0" />
        <stop offset="0.38" stopColor="#ffffff" stopOpacity="0.62" />
        <stop offset="1" stopColor="#ffffff" stopOpacity="0" />
      </linearGradient>
      <linearGradient id="cs5em" x1="0" y1="0" x2="1" y2="0">
        <stop offset="0" stopColor="#5fa093" stopOpacity="0" />
        <stop offset="0.5" stopColor="#5fa093" stopOpacity="0.55" />
        <stop offset="1" stopColor="#5fa093" stopOpacity="0" />
      </linearGradient>
      <linearGradient id="cs5p" x1="0" y1="0" x2="0" y2="1">
        <stop offset="0" stopColor="#90bcc8" stopOpacity="0.26" />
        <stop offset="1" stopColor="#4a7a8a" stopOpacity="0.38" />
      </linearGradient>
    </defs>
    {/* Pane fills — each pane reads as glass */}
    <rect x="113" y="71"  width="90" height="85" fill="url(#cs5p)" />
    <rect x="205" y="71"  width="90" height="85" fill="url(#cs5p)" />
    <rect x="297" y="71"  width="90" height="85" fill="url(#cs5p)" />
    <rect x="113" y="158" width="90" height="84" fill="url(#cs5p)" />
    <rect x="205" y="158" width="90" height="84" fill="url(#cs5p)" />
    <rect x="297" y="158" width="90" height="84" fill="url(#cs5p)" />
    <rect x="113" y="244" width="90" height="85" fill="url(#cs5p)" />
    <rect x="205" y="244" width="90" height="85" fill="url(#cs5p)" />
    <rect x="297" y="244" width="90" height="85" fill="url(#cs5p)" />
    {/* Reflection sweep */}
    <g className="cs-reflect" clipPath="url(#cs5f)">
      <rect x="40" y="-40" width="72" height="480" fill="url(#cs5g)" />
      <rect x="86" y="-40" width="22" height="480" fill="url(#cs5em)" />
    </g>
    {/* Frame */}
    <rect className="cs-steel" x="112" y="70" width="276" height="260" />
    <line className="cs-steel" x1="204" y1="70" x2="204" y2="330" />
    <line className="cs-steel" x1="296" y1="70" x2="296" y2="330" />
    <line className="cs-steel" x1="112" y1="157" x2="388" y2="157" />
    <line className="cs-steel" x1="112" y1="243" x2="388" y2="243" />
    {/* Seal perimeter — animated emerald trace verifying every joint */}
    <rect className="cs-seal" x="112" y="70" width="276" height="260" />
    {/* Dimension above */}
    <line className="cs-fine" x1="112" y1="56" x2="388" y2="56" />
    <line className="cs-fine" x1="112" y1="51" x2="112" y2="61" />
    <line className="cs-fine" x1="388" y1="51" x2="388" y2="61" />
    {/* Mullion intersection callout dots — precision fitting marks */}
    <circle className="cs-emf cs-fit-dot" cx="204" cy="157" r="4.5" style={{animationDelay: "0s"}} />
    <circle className="cs-emf cs-fit-dot" cx="296" cy="157" r="4.5" style={{animationDelay: "0.7s"}} />
    <circle className="cs-emf cs-fit-dot" cx="204" cy="243" r="4.5" style={{animationDelay: "1.4s"}} />
    <circle className="cs-emf cs-fit-dot" cx="296" cy="243" r="4.5" style={{animationDelay: "2.1s"}} />
  </svg>,

  /* 06 — False ceiling: nested cove trays, a soft light breathing, downlights waking in turn */
  <svg className="cs cs--ceiling" viewBox="0 0 500 400" fill="none" aria-hidden="true">
    <defs>
      <radialGradient id="cs6c" cx="0.5" cy="0.5" r="0.5">
        <stop offset="0" stopColor="#5fa093" stopOpacity="0.5" />
        <stop offset="1" stopColor="#5fa093" stopOpacity="0" />
      </radialGradient>
    </defs>
    <rect className="cs-cove" x="150" y="118" width="200" height="168" fill="url(#cs6c)" />
    <rect className="cs-edge" x="100" y="86" width="300" height="228" />
    <rect className="cs-fine" x="140" y="118" width="220" height="164" />
    <rect className="cs-fine" x="170" y="146" width="160" height="108" />
    <circle className="cs-fine" cx="200" cy="200" r="8" />
    <circle className="cs-dl" cx="200" cy="200" r="5" style={{ animationDelay: "0s" }} />
    <circle className="cs-fine" cx="250" cy="200" r="8" />
    <circle className="cs-dl" cx="250" cy="200" r="5" style={{ animationDelay: "0.5s" }} />
    <circle className="cs-fine" cx="300" cy="200" r="8" />
    <circle className="cs-dl" cx="300" cy="200" r="5" style={{ animationDelay: "1s" }} />
    <line className="cs-fine" x1="100" y1="70" x2="400" y2="70" />
    <line className="cs-fine" x1="100" y1="65" x2="100" y2="75" />
    <line className="cs-fine" x1="400" y1="65" x2="400" y2="75" />
  </svg>,
];

const Crafts = () => {
  const { lang } = useLang();
  return (
    <section id="crafts" className="practice-section practice-crafts">
      <div className="bp-wrap">
        <div className="section-head practice-section__head bp-head">
          <Reveal as="h2" className="section-title" delay={80}>
            {t(P.disc_title_a, lang)}<span className="it">{t(P.disc_title_em, lang)}</span>
          </Reveal>
        </div>
        <div className="bp-plates">
          {P.disc_items.map((it, i) => (
            <Reveal key={i} className="bp-plate" delay={(i % 3) * 90}>
              <div className="bp-plate__scene" role="img" aria-label={t(it.name, lang)}>
                <span className="bp-corner bp-corner--tl" aria-hidden="true" />
                <span className="bp-corner bp-corner--br" aria-hidden="true" />
                {CRAFT_SCENES[i]}
              </div>
              <div className="bp-plate__body">
                <span className="bp-plate__rule" aria-hidden="true" />
                <h3 className="bp-plate__name">{t(it.name, lang)}</h3>
                <p className="bp-plate__line">{rich(t(it.line, lang))}</p>
              </div>
            </Reveal>
          ))}
        </div>
      </div>
    </section>
  );
};

// ================================================================
// BEFORE THE FIRST BRICK — checkpoint stamps
// ================================================================
const STAMP_ICONS = [
  /* sample first — approval seal with a check */
  <svg className="bp-stamp-svg" viewBox="0 0 96 96" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
    <circle className="drw" pathLength="1" cx="48" cy="48" r="41" />
    <circle className="drw" pathLength="1" cx="48" cy="48" r="31" />
    <path className="drw bp-live" pathLength="1" d="M34 49 l9 10 l20 -25" />
  </svg>,
  /* no swaps — the chosen material, locked */
  <svg className="bp-stamp-svg" viewBox="0 0 96 96" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
    <circle className="drw" pathLength="1" cx="48" cy="48" r="41" />
    <rect className="drw" pathLength="1" x="31" y="45" width="34" height="24" rx="2" />
    <path className="drw bp-live" pathLength="1" d="M38 45 v-7 a10 10 0 0 1 20 0 v7" />
  </svg>,
  /* checked — a lens over the work */
  <svg className="bp-stamp-svg" viewBox="0 0 96 96" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
    <circle className="drw" pathLength="1" cx="48" cy="48" r="41" />
    <circle className="drw" pathLength="1" cx="44" cy="44" r="15" />
    <line className="drw bp-live" pathLength="1" x1="55" y1="55" x2="67" y2="67" />
  </svg>,
];

const Methods = () => {
  const { lang } = useLang();
  return (
    <section id="method" className="practice-section practice-method">
      <div className="bp-wrap">
        <div className="section-head practice-section__head bp-head">
          <Reveal as="h2" className="section-title" delay={80}>
            {t(P.quality_title_a, lang)}<span className="it">{t(P.quality_title_em, lang)}</span>
          </Reveal>
        </div>
        <ol className="bp-gates">
          {P.quality_gates.map((g, i) => (
            <Reveal as="li" key={i} className="bp-gate" delay={i * 120}>
              <span className="bp-gate__stamp" aria-hidden="true">{STAMP_ICONS[i]}</span>
              <h3 className="bp-gate__name">{t(g.name, lang)}</h3>
              <p className="bp-gate__line">{rich(t(g.line, lang))}</p>
            </Reveal>
          ))}
        </ol>
      </div>
    </section>
  );
};



// ================================================================
// SYSTEMS — applying systems thinking (interconnected network)
// ================================================================
const Systems = () => {
  const { lang } = useLang();
  const N = P.systems_nodes.length;
  const [act, setAct] = React.useState(0);
  React.useEffect(() => {
    if (window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
    const id = setInterval(() => setAct((a) => (a + 1) % N), 3400);
    return () => clearInterval(id);
  }, [N]);
  const CX = 320, CY = 320, R = 165, LR = 217, ORBIT = 281;
  const pts = P.systems_nodes.map((n, i) => {
    const a = -Math.PI / 2 + (i * 2 * Math.PI) / N;
    return {
      x: CX + R * Math.cos(a), y: CY + R * Math.sin(a),
      lx: CX + LR * Math.cos(a), ly: CY + LR * Math.sin(a),
      node: n,
    };
  });
  const ticks = Array.from({ length: 72 }, (_, i) => {
    const a = (i * 5 * Math.PI) / 180;
    const major = i % 6 === 0;
    const r1 = major ? 258 : 264;
    const r2 = 271;
    return {
      x1: CX + r1 * Math.cos(a), y1: CY + r1 * Math.sin(a),
      x2: CX + r2 * Math.cos(a), y2: CY + r2 * Math.sin(a),
      major,
    };
  });
  const hubWords = t(P.systems_hub, lang).split(" ");
  return (
    <section id="systems" className="practice-section practice-systems">
      <div className="bp-wrap">
        <div className="section-head practice-section__head bp-head sys-head">
          <Reveal as="h2" className="section-title" delay={40}>
            {t(P.systems_title_a, lang)}<span className="it">{t(P.systems_title_em, lang)}</span>
          </Reveal>
          <Reveal as="p" className="sys-lead" delay={140}>{rich(t(P.systems_lead, lang))}</Reveal>
          <Reveal as="p" className="sys-body" delay={220}>{rich(t(P.systems_body, lang))}</Reveal>
        </div>
        <div className="sys-stage">
          {P.systems_points.map((pt, i) => (
            <Reveal key={i} className={`sys-outcome sys-outcome--${i === 0 ? "a" : "b"}`} delay={420 + i * 160}>
              <span className="sys-outcome__num" aria-hidden="true">{String(i + 1).padStart(2, "0")}</span>
              <div className="sys-outcome__text">
                <h3 className="sys-outcome__name">{t(pt.name, lang)}</h3>
                <p className="sys-outcome__line">{t(pt.line, lang)}</p>
              </div>
            </Reveal>
          ))}
          <Reveal className="sys-diagram" delay={180}>
            <svg viewBox="0 0 640 640" role="img" aria-label={t(P.systems_lead, lang).replace(/\*/g, "")}>
              <defs>
                <radialGradient id="sysHubGlow">
                  <stop offset="0%" stopColor="rgba(95, 160, 147, 0.30)" />
                  <stop offset="55%" stopColor="rgba(95, 160, 147, 0.10)" />
                  <stop offset="100%" stopColor="rgba(95, 160, 147, 0)" />
                </radialGradient>
                <radialGradient id="sysHubFill" cx="38%" cy="32%" r="85%">
                  <stop offset="0%" stopColor="#4d817a" />
                  <stop offset="100%" stopColor="#34605a" />
                </radialGradient>
              </defs>
              <circle className="sys-glow" cx={CX} cy={CY} r={155} fill="url(#sysHubGlow)" />
              <g aria-hidden="true">
                {ticks.map((tk, i) => (
                  <line
                    key={`t${i}`}
                    className={tk.major ? "sys-tick sys-tick--major" : "sys-tick"}
                    x1={tk.x1} y1={tk.y1} x2={tk.x2} y2={tk.y2}
                  />
                ))}
              </g>
              <circle className="sys-sat__orbit" cx={CX} cy={CY} r={ORBIT} fill="none" />
              <circle className="sys-orbit" cx={CX} cy={CY} r={121} fill="none" />
              <circle className="sys-ring" pathLength="1" cx={CX} cy={CY} r={R} fill="none" />
              {pts.map((p, i) => (
                <line
                  key={i} className="sys-spoke" pathLength="1"
                  x1={CX} y1={CY} x2={p.x} y2={p.y}
                  style={{ transitionDelay: `${0.55 + i * 0.14}s` }}
                />
              ))}
              {pts.map((p, i) => (
                <line
                  key={`f${i}`} className="sys-flow"
                  x1={CX} y1={CY} x2={p.x} y2={p.y}
                  style={{ animationDelay: `${i * 0.37}s` }}
                />
              ))}
              <circle className="sys-hub-pulse" cx={CX} cy={CY} r={62} fill="none" />
              <circle className="sys-hub-ring" cx={CX} cy={CY} r={62} fill="none" />
              <circle className="sys-hub" cx={CX} cy={CY} r={50} />
              {hubWords.length > 1 ? (
                <text className="sys-hub-label" x={CX} y={CY} textAnchor="middle">
                  <tspan x={CX} dy="-0.2em">{hubWords[0]}</tspan>
                  <tspan x={CX} dy="1.15em">{hubWords.slice(1).join(" ")}</tspan>
                </text>
              ) : (
                <text className="sys-hub-label" x={CX} y={CY} textAnchor="middle" dy="0.35em">
                  {hubWords[0]}
                </text>
              )}
              {pts.map((p, i) => (
                <g key={i} className="sys-node" style={{ transitionDelay: `${0.7 + i * 0.14}s` }}>
                  <circle className="sys-node__halo" cx={p.x} cy={p.y} r={11} fill="none" />
                  <circle className="sys-node__soft" cx={p.x} cy={p.y} r={7.5} />
                  <circle className="sys-dot" cx={p.x} cy={p.y} r={4.5} />
                  <text className="sys-label" x={p.lx} y={p.ly} textAnchor="middle" dy="0.35em">
                    {t(p.node, lang)}
                  </text>
                </g>
              ))}
              <g className="sys-ripple" key={act} aria-hidden="true">
                {pts.map((p, i) => {
                  if (i === act) return null;
                  const d = (i - act + N) % N;
                  const steps = Math.min(d, N - d);
                  const sweep = d <= N / 2 ? 1 : 0;
                  return (
                    <path
                      key={i} className="sys-hl" pathLength="1" fill="none"
                      d={`M ${pts[act].x} ${pts[act].y} A ${R} ${R} 0 0 ${sweep} ${p.x} ${p.y}`}
                      style={{ animationDelay: `${0.1 + steps * 0.09}s` }}
                    />
                  );
                })}
                <circle className="sys-hl-node" cx={pts[act].x} cy={pts[act].y} r={9} fill="none" />
              </g>
              <g className="sys-sat">
                <text className="sys-sat__label" x={CX} y={CY - ORBIT} textAnchor="middle" dy="0.35em">
                  {t(P.systems_sat[0], lang)}
                </text>
                <text className="sys-sat__label" x={CX} y={CY + ORBIT} textAnchor="middle" dy="0.35em">
                  {t(P.systems_sat[1], lang)}
                </text>
              </g>
            </svg>
            <p className="sys-caption">{t(P.systems_caption, lang)}</p>
          </Reveal>
        </div>
      </div>
    </section>
  );
};

// ================================================================
// KAIZEN — committed to continuous improvement
// ================================================================

// Compounding curve — small daily gains stacking into a year of growth.
const KaizenCompound = ({ lang }) => {
  const rootRef = React.useRef(null);

  const isRTL = lang === "ar";
  const X0 = 70, X1 = 1100, Y0 = 404, YT = 56, DAYS = 365, STEP = 5, DRAW = 3.2;
  const vmax = Math.pow(1.01, DAYS);

  // RTL: mirror x so Day 1 → right (X1), Day 365 → left (X0)
  const xOf = (d) => {
    const raw = X0 + ((X1 - X0) * d) / DAYS;
    return isRTL ? X0 + X1 - raw : raw;
  };
  const yOf = (d) => Y0 - ((Math.pow(1.01, d) - 1) / (vmax - 1)) * (Y0 - YT);

  const days = [];
  for (let d = 0; d <= DAYS; d += STEP) days.push(d);
  const pts = days.map((d) => [xOf(d), yOf(d)]);
  const cum = [0];
  for (let i = 1; i < pts.length; i++) {
    cum.push(cum[i - 1] + Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]));
  }
  const total = cum[cum.length - 1];
  const delayAt = (d) => (0.15 + (DRAW * cum[Math.round(d / STEP)]) / total).toFixed(2);
  const dAttr = "M " + pts.map((p) => `${p[0].toFixed(1)} ${p[1].toFixed(1)}`).join(" L ");
  const end = pts[pts.length - 1];
  // Area closes from curve-end → axis-corner below end → axis-corner below start → back
  const areaAttr = `${dAttr} L ${end[0]} ${Y0} L ${xOf(0)} ${Y0} Z`;

  const yGrid = [10, 20, 30];
  const yOfV = (v) => Y0 - ((v - 1) / (vmax - 1)) * (Y0 - YT);

  // RTL-aware anchors
  const endAnchor   = isRTL ? "start" : "end";
  const startAnchor = isRTL ? "end"   : "start";
  const xYLab = isRTL ? X1 + 16 : X0 - 14;

  const marks = [
    { d: 70, lab: "×2" },
    { d: 180, lab: "×6" },
    { d: 270, lab: "×15" },
  ];
  const dotDays = [70, 180, 270];
  const stepMonths = [];
  for (let d = 90; d <= 360; d += 90) stepMonths.push(d);
  const ticks = [];
  for (let d = 0; d <= 360; d += 30) ticks.push(d);
  ticks.push(DAYS);

  return (
    <div className="kaizen-compound" id="kaizen-chart" aria-hidden="true" ref={rootRef}>
      <svg viewBox="0 0 1180 470" role="presentation" focusable="false">
        <defs>
          <linearGradient id="kzFill" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0" stopColor="#b8dcd3" stopOpacity="0.42" />
            <stop offset="1" stopColor="#b8dcd3" stopOpacity="0" />
          </linearGradient>
        </defs>

        {/* Y-grid lines + labels — labels sit outside the chart on the correct side */}
        {yGrid.map((v) => (
          <g key={`g${v}`}>
            <line className="kz-grid" x1={X0} y1={yOfV(v)} x2={X1} y2={yOfV(v)} />
            <text className="kz-ylab" x={xYLab} y={yOfV(v) + 4} textAnchor={endAnchor}>{`×${v}`}</text>
          </g>
        ))}

        {/* Flat baseline */}
        <line className="kz-flat" x1={X0} y1={Y0} x2={X1} y2={Y0} />
        <text className="kz-flat-lab"
          x={isRTL ? X0 + 6 : X1} y={Y0 - 14}
          textAnchor={isRTL ? "start" : "end"}
        >{t(P.kaizen_axis_flat, lang)}</text>

        {/* X-axis ticks */}
        {ticks.map((d) => (
          <line key={`t${d}`} className="kz-tick" x1={xOf(d)} y1={Y0 + 6} x2={xOf(d)} y2={Y0 + 13} />
        ))}

        {/* Day labels — "Day 1" at xOf(0), "Day 365" at xOf(DAYS) */}
        <text className="kz-lab" x={xOf(0)}    y={Y0 + 40} textAnchor={startAnchor}>{t(P.kaizen_axis_start, lang)}</text>
        <text className="kz-lab" x={xOf(DAYS)} y={Y0 + 40} textAnchor={endAnchor}>{t(P.kaizen_axis_end, lang)}</text>

        <g className="kz-cycle">
          <path className="kz-area" d={areaAttr} fill="url(#kzFill)" />

          {/* Monthly step risers */}
          {stepMonths.map((d) => (
            <g key={`s${d}`}>
              <line
                className="kz-step-bar"
                x1={xOf(d)} y1={yOf(d - 30)} x2={xOf(d)} y2={yOf(d)}
                style={{ animationDelay: `${delayAt(d)}s` }}
              />
              <circle
                className="kz-step-dot" cx={xOf(d)} cy={yOf(d)} r="2.2"
                style={{ animationDelay: `${delayAt(d)}s` }}
              />
            </g>
          ))}

          <path className="kz-curve" pathLength="1" d={dAttr} />
          <path className="kz-comet-glow" pathLength="1" d={dAttr} fill="none" />
          <path className="kz-comet" pathLength="1" d={dAttr} fill="none" />

          {/* Milestone dots with leader ticks */}
          {dotDays.map((d) => (
            <g key={`d${d}`}>
              <line
                className="kz-dotlead"
                x1={xOf(d)} y1={yOf(d) - 8} x2={xOf(d)} y2={yOf(d) - 28}
                style={{ animationDelay: `${delayAt(d)}s` }}
              />
              <circle
                className="kz-dot" cx={xOf(d)} cy={yOf(d)} r="4.5"
                style={{ animationDelay: `${delayAt(d)}s` }}
              />
            </g>
          ))}

          {/* Milestone multiplier labels — offset away from leader tick */}
          {marks.map((m) => (
            <text
              key={`m${m.d}`} className="kz-dotlab"
              x={xOf(m.d) + (isRTL ? 13 : -13)} y={yOf(m.d) - 31}
              textAnchor={isRTL ? "start" : "end"}
              style={{ animationDelay: `${delayAt(m.d)}s` }}
            >{m.lab}</text>
          ))}

          {/* "+1% per day" callout note */}
          <text className="kz-note"
            x={xOf(300) + (isRTL ? 32 : -32)} y={yOf(300) - 28}
            textAnchor={isRTL ? "start" : "end"}
            style={{ animationDelay: `${delayAt(300)}s` }}
          >{t(P.kaizen_note, lang)}</text>

          {/* Endpoint bloom — two halo rings for emphasis */}
          <circle className="kz-bloom" cx={end[0]} cy={end[1]} r="6" />
          <circle className="kz-bloom-halo" cx={end[0]} cy={end[1]} r="13" fill="none" />
          <circle className="kz-bloom-halo kz-bloom-halo--far" cx={end[0]} cy={end[1]} r="22" fill="none" />

          {/* ×37 value label beside the endpoint */}
          <text className="kz-mult"
            x={end[0] + (isRTL ? 22 : -22)} y={end[1] + 10}
            textAnchor={isRTL ? "start" : "end"}
          >{t(P.kaizen_axis_mult, lang)}</text>
        </g>
      </svg>
    </div>
  );
};

// Signals intake — five sources feeding the kaizen loop, pulses gliding
// along the lines into the 改善 hub (sparks travel, never ripple).
const KZS_ICONS = (() => {
  const teeth = [0, 45, 90, 135, 180, 225, 270, 315]
    .map((a) => {
      const r = (a * Math.PI) / 180;
      const c = Math.cos(r), s = Math.sin(r);
      return `M ${(9 * c).toFixed(2)} ${(9 * s).toFixed(2)} L ${(13 * c).toFixed(2)} ${(13 * s).toFixed(2)}`;
    })
    .join(" ");
  return {
    site: (
      <>
        <path d="M0 16 V-10 M-8 16 H8 M-14 -10 H14 M0 -16 L-14 -10 M0 -16 L14 -10 M9 -10 V-1" />
        <circle cx="9" cy="1.5" r="1.6" />
      </>
    ),
    consultants: (
      <>
        <path d="M0 -12 L-9 12 M0 -12 L9 12 M-9 12 Q0 17 9 12 M0 -16 V-12" />
        <circle cx="0" cy="-12" r="2" />
      </>
    ),
    owners: <path d="M-14 0 L0 -13 L14 0 M-10 -2 V12 H10 V-2 M-2 12 V5 H3 V12" />,
    market: <path d="M-14 -12 V12 H14 M-10 8 L-3 1 L2 4 L12 -8 M12 -8 L6.5 -8.8 M12 -8 L11 -2.5" />,
    industry: (
      <>
        <circle cx="0" cy="0" r="8" />
        <path d={teeth} />
        <circle className="kzs-fill" cx="0" cy="0" r="2" />
      </>
    ),
  };
})();

const KaizenSignals = ({ lang }) => {
  const XS = [110, 340, 570, 800, 1030];
  const HUBX = 570, HUBY = 300, HUBR = 46;
  const srcs = lang === "ar" ? [...P.kaizen_signals].reverse() : P.kaizen_signals;
  return (
    <svg viewBox="0 0 1140 370" role="presentation" focusable="false" aria-hidden="true">
      <defs>
        <linearGradient id="kzsFlow" x1="0" y1="146" x2="0" y2="252" gradientUnits="userSpaceOnUse">
          <stop offset="0" stopColor="#f2f3f4" stopOpacity="0.10" />
          <stop offset="0.65" stopColor="#b8dcd3" stopOpacity="0.30" />
          <stop offset="1" stopColor="#b8dcd3" stopOpacity="0.55" />
        </linearGradient>
        <linearGradient id="kzsOutFlow" x1="0" y1="348" x2="0" y2="385" gradientUnits="userSpaceOnUse">
          <stop offset="0" stopColor="#b8dcd3" stopOpacity="0.3" />
          <stop offset="1" stopColor="#b8dcd3" stopOpacity="0.85" />
        </linearGradient>
        <radialGradient id="kzsHubFill">
          <stop offset="0" stopColor="#f2f3f4" stopOpacity="0.11" />
          <stop offset="1" stopColor="#f2f3f4" stopOpacity="0.02" />
        </radialGradient>
      </defs>
      {srcs.map((s, i) => {
        const x = XS[i];
        const d =
          x === HUBX
            ? `M ${x} 146 L ${HUBX} ${HUBY - HUBR - 2}`
            : `M ${x} 146 C ${x} 205, ${HUBX} 198, ${HUBX} ${HUBY - HUBR - 2}`;
        const dur = `${(2.4 + i * 0.25).toFixed(2)}s`;
        const begin = `${(i * 0.7).toFixed(2)}s`;
        return (
          <g key={s.id}>
            <path
              className="kzs-line" pathLength="1" d={d}
              style={{ animationDelay: `${(0.25 + i * 0.1).toFixed(2)}s` }}
            />
            <g className="kzs-node" style={{ animationDelay: `${(0.1 + i * 0.12).toFixed(2)}s` }}>
              <circle className="kzs-ring" cx={x} cy={64} r={34} />
              <g transform={`translate(${x} 64)`}>
                <g className="kzs-icon">{KZS_ICONS[s.id]}</g>
              </g>
              <text className="kzs-label" x={x} y={132} textAnchor="middle">{t(s.label, lang)}</text>
            </g>
            <circle className="kzs-pulse-glow" r="8.5" opacity="0">
              <animateMotion dur={dur} begin={begin} repeatCount="indefinite" path={d} />
              <animate
                attributeName="opacity" values="0;0.3;0.3;0" keyTimes="0;0.12;0.82;1"
                dur={dur} begin={begin} repeatCount="indefinite"
              />
            </circle>
            <circle className="kzs-pulse" r="3.6" opacity="0">
              <animateMotion dur={dur} begin={begin} repeatCount="indefinite" path={d} />
              <animate
                attributeName="opacity" values="0;1;1;0" keyTimes="0;0.12;0.82;1"
                dur={dur} begin={begin} repeatCount="indefinite"
              />
            </circle>
          </g>
        );
      })}
      <g className="kzs-hub" style={{ animationDelay: "0.7s" }}>
        <path
          className="kzs-in-head"
          d={`M ${HUBX - 8} ${HUBY - HUBR - 13} L ${HUBX} ${HUBY - HUBR - 3} L ${HUBX + 8} ${HUBY - HUBR - 13}`}
        />
        <circle className="kzs-hub-halo kzs-hub-halo--far" cx={HUBX} cy={HUBY} r={HUBR + 22} />
        <circle className="kzs-hub-halo" cx={HUBX} cy={HUBY} r={HUBR + 11} />
        <circle className="kzs-hub-ring" cx={HUBX} cy={HUBY} r={HUBR} />
        <g transform={`translate(${HUBX} ${HUBY})`}>
          <g className="kzs-cycle-fit">
            <g className="kzs-cycle">
              <path d="M -17.32 -10 A 20 20 0 0 1 17.32 -10" />
              <path d="M 17.32 -10 L 11.6 -14 M 17.32 -10 L 16.7 -17" />
              <path d="M 17.32 10 A 20 20 0 0 1 -17.32 10" />
              <path d="M -17.32 10 L -11.6 14 M -17.32 10 L -16.7 17" />
            </g>
          </g>
        </g>
        <line className="kzs-looplead" x1={HUBX + HUBR + 8} y1={HUBY} x2={HUBX + HUBR + 26} y2={HUBY} />
        <text className="kzs-looplab" x={HUBX + HUBR + 34} y={HUBY + 4} textAnchor="start">
          <tspan x={HUBX + HUBR + 34}>{t(P.kaizen_loop, lang)}</tspan>
        </text>
      </g>
    </svg>
  );
};

const Kaizen = () => {
  const { lang } = useLang();
  return (
    <section id="kaizen" className="practice-section practice-kaizen">
      <div className="kaizen-mark" aria-hidden="true" lang="ja">
        <span className="kaizen-mark__a">改</span>
      </div>
      <div className="bp-wrap kaizen-wrap">
        <div className="section-head practice-section__head bp-head kaizen-head">
          <Reveal as="span" className="section-eyebrow kaizen-eyebrow">
            <span className="rule" aria-hidden="true" />
            {t(P.kaizen_eyebrow, lang)}
            <span className="rule" aria-hidden="true" />
          </Reveal>
          <Reveal as="div" className="kaizen-ja" delay={60} aria-hidden="true" lang="ja">改善</Reveal>
          <Reveal as="h2" className="section-title" delay={120}>
            {t(P.kaizen_title_a, lang)}<span className="it">{t(P.kaizen_title_em, lang)}</span>
          </Reveal>
          <Reveal as="p" className="kaizen-lead" delay={200}>{t(P.kaizen_lead, lang)}</Reveal>
        </div>
        <Reveal className="kaizen-close" delay={140}>
          <div className="kaizen-close__cap">
            <p className="kaizen-close__line">
              {t(P.kaizen_close_a, lang)}<span className="it">{t(P.kaizen_close_em, lang)}</span>
            </p>
          </div>
          <KaizenCompound lang={lang} />
        </Reveal>
        <div className="kaizen-coda">
          <Reveal as="div" className="kaizen-coda__scanwrap" delay={60}>
            <svg className="kzs-scan" viewBox="0 0 44 44" aria-hidden="true" focusable="false">
              <circle className="kzs-scan__ring" cx="22" cy="22" r="20" />
              <circle className="kzs-scan__ring kzs-scan__ring--mid" cx="22" cy="22" r="13" />
              <circle className="kzs-scan__ring kzs-scan__ring--in" cx="22" cy="22" r="6.5" />
              <g className="kzs-scan__sweep">
                <path className="kzs-scan__wedge" d="M22 22 L22 2 A20 20 0 0 1 34.86 6.68 Z" />
                <line className="kzs-scan__beam" x1="22" y1="22" x2="22" y2="2" />
              </g>
              <circle className="kzs-scan__blip kzs-scan__blip--a" cx="31" cy="11.5" r="1.7" />
              <circle className="kzs-scan__blip kzs-scan__blip--b" cx="13" cy="28" r="1.5" />
              <circle className="kzs-scan__dot" cx="22" cy="22" r="1.8" />
            </svg>
          </Reveal>
          <Reveal as="p" className="kaizen-coda__line" delay={110}>
            {t(P.kaizen_coda, lang)}
          </Reveal>
          <Reveal className="kaizen-signals" delay={180}>
            <span className="kzs-sr">
              {P.kaizen_signals.map((s) => t(s.label, lang)).join(" · ")} · {t(P.kaizen_loop, lang)} · {t(P.kaizen_next, lang)}
            </span>
            <KaizenSignals lang={lang} />
          </Reveal>
        </div>
      </div>
    </section>
  );
};

// ================================================================
// APP
// ================================================================
const ProgressBar = () => {
  const p = useScrollProgress();
  return <div className="cg-progress" style={{ transform: `scaleX(${p})` }} aria-hidden="true" />;
};

function PracticeApp() {
  React.useEffect(() => {
    if (!window.location.hash) return;
    const id = window.location.hash.slice(1);
    const jump = () => {
      const el = document.getElementById(id);
      if (el) window.scrollTo({ top: Math.max(0, el.getBoundingClientRect().top + window.pageYOffset - 66), behavior: "instant" });
    };
    const t = setTimeout(jump, 200);
    window.addEventListener("load", jump);
    return () => { clearTimeout(t); window.removeEventListener("load", jump); };
  }, []);
  return (
    <>
      <ProgressBar />
      <TopBar />
      <main className="practice-main">
        <Standard />
        <BuildUp />
        <Crafts />
        <Methods />
        <Systems />
        <Kaizen />
      </main>
      <Footer />
    </>
  );
}

function App() {
  return (
    <LangProvider>
      <PracticeApp />
    </LangProvider>
  );
}

class ErrorBoundary extends React.Component {
  constructor(props) { super(props); this.state = { error: null }; }
  static getDerivedStateFromError(err) { return { error: err }; }
  render() {
    if (this.state.error) return (
      <div style={{ minHeight: "100vh", display: "flex", alignItems: "center", justifyContent: "center", background: "#f2f3f4", flexDirection: "column", gap: 16, padding: 32, textAlign: "center", fontFamily: "sans-serif" }}>
        <img src="assets/logo-mark-circle-emerald.png" alt="" width="64" height="64" />
        <p style={{ color: "#221f20", fontSize: 16, maxWidth: 400, margin: 0 }}>Something went wrong. Please refresh.</p>
        <button onClick={() => window.location.reload()} style={{ background: "#4e837c", color: "#fff", border: "none", borderRadius: 3, padding: "10px 24px", cursor: "pointer", fontSize: 14 }}>Refresh</button>
      </div>
    );
    return this.props.children;
  }
}

ReactDOM.createRoot(document.getElementById("root")).render(
  <ErrorBoundary><App /></ErrorBoundary>
);
