/* All sections of the site. Compose them in app.jsx. */

const { useState, useEffect, useRef, useCallback } = React;

/* Hook: fade-in on viewport */
function useReveal() {
  useEffect(() => {
    const els = document.querySelectorAll(".reveal");
    const io = new IntersectionObserver(
      (entries) => entries.forEach((e) => e.isIntersecting && e.target.classList.add("in")),
      { threshold: 0.12, rootMargin: "0px 0px -40px 0px" }
    );
    els.forEach((el) => io.observe(el));
    return () => io.disconnect();
  }, []);
}

/* ================= HEADER ================= */
const Header = ({ content, lang, setLang }) => {
  const [scrolled, setScrolled] = useState(false);
  const [open, setOpen] = useState(false);

  useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 20);
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  return (
    <header
      style={{
        position: "fixed", top: 0, left: 0, right: 0,
        zIndex: 50,
        padding: scrolled ? "12px 0" : "20px 0",
        background: scrolled ? "rgba(251,246,238,0.85)" : "transparent",
        backdropFilter: scrolled ? "blur(14px) saturate(120%)" : "none",
        WebkitBackdropFilter: scrolled ? "blur(14px) saturate(120%)" : "none",
        borderBottom: scrolled ? "1px solid var(--line-soft)" : "1px solid transparent",
        transition: "all .25s ease",
      }}
    >
      <div className="container" style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 24 }}>
        <a href="#top" dir="ltr" aria-label="Shlomo Kalichman home"
           style={{ fontFamily: "var(--font-en)", fontSize: 22, fontWeight: 800, letterSpacing: "-0.04em", color: "var(--ink)", display: "inline-flex", alignItems: "baseline" }}>
          Shlomo Kalichman<span style={{ color: "var(--coral)", marginInlineStart: 1 }}>.</span>
        </a>

        <nav className="header-nav" style={{ display: "flex", alignItems: "center", gap: 6 }}>
          {content.nav.map((n) => (
            <a key={n.href} href={n.href}
               style={{ padding: "8px 14px", borderRadius: 999, fontSize: 14, fontWeight: 500, color: "var(--ink-2)", transition: "background .15s" }}
               onMouseEnter={(e) => e.currentTarget.style.background = "var(--bg-warm)"}
               onMouseLeave={(e) => e.currentTarget.style.background = "transparent"}
            >
              {n.label}
            </a>
          ))}
        </nav>

        <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
          {/* Language switch */}
          <div style={{
            display: "flex", alignItems: "center",
            background: "var(--surface)", border: "1px solid var(--line)",
            borderRadius: 999, padding: 3, gap: 0, boxShadow: "var(--shadow-card)",
          }}>
            <button
              onClick={() => setLang("he")}
              style={{
                padding: "5px 11px", border: 0, borderRadius: 999, fontSize: 12, fontWeight: 700,
                background: lang === "he" ? "var(--coral)" : "transparent",
                color: lang === "he" ? "#fff" : "var(--ink-2)",
              }}
            >HE</button>
            <button
              onClick={() => setLang("en")}
              style={{
                padding: "5px 11px", border: 0, borderRadius: 999, fontSize: 12, fontWeight: 700,
                background: lang === "en" ? "var(--coral)" : "transparent",
                color: lang === "en" ? "#fff" : "var(--ink-2)",
              }}
            >EN</button>
          </div>

          <a href="https://www.linkedin.com/in/shlomo-kalichman/" target="_blank" rel="noreferrer" className="header-linkedin" aria-label="LinkedIn"
             style={{ width: 36, height: 36, display: "inline-flex", alignItems: "center", justifyContent: "center", borderRadius: 999, background: "var(--surface)", border: "1px solid var(--line)", color: "var(--ink-2)" }}>
            <Icon name="linkedin" size={16} />
          </a>
          <a href="#contact" className="btn btn-primary btn-small header-cta">
            {content.headerCta}
            <Icon name="arrow" size={14} className="flip-rtl" />
          </a>

          <button
            className="mobile-menu-btn"
            onClick={() => setOpen(o => !o)}
            aria-label="Menu"
            style={{
              display: "none", width: 40, height: 40, borderRadius: 12,
              background: "var(--surface)", border: "1px solid var(--line)", color: "var(--ink)",
            }}
          >
            <Icon name={open ? "x" : "menu"} size={20} />
          </button>
        </div>
      </div>

      {/* Mobile menu drawer */}
      {open && (
        <div className="mobile-drawer" style={{
          margin: "12px 20px 0", padding: 16, borderRadius: 18,
          background: "var(--surface)", border: "1px solid var(--line)",
          boxShadow: "var(--shadow-lift)",
        }}>
          <nav style={{ display: "flex", flexDirection: "column", gap: 4 }}>
            {content.nav.map((n) => (
              <a key={n.href} href={n.href} onClick={() => setOpen(false)}
                 style={{ padding: "12px 14px", borderRadius: 12, fontSize: 16, fontWeight: 500, color: "var(--ink)" }}>
                {n.label}
              </a>
            ))}
            <a href="#contact" className="btn btn-primary" onClick={() => setOpen(false)} style={{ marginTop: 8, justifyContent: "center" }}>
              {content.headerCta}
            </a>
          </nav>
        </div>
      )}

      <style>{`
        @media (max-width: 920px) {
          .header-nav, .header-linkedin, .header-cta { display: none !important; }
          .mobile-menu-btn { display: inline-flex !important; align-items: center; justify-content: center; }
        }
      `}</style>
    </header>
  );
};

/* ================= HERO ================= */
const Hero = ({ content, lang }) => {
  const isRTL = lang === "he";
  const titleLines = content.hero.title.split("\n");

  return (
    <section id="top" style={{ position: "relative", minHeight: "100vh", overflow: "hidden", paddingBottom: 80 }}>
      {/* Background glows */}
      <div style={{
        pointerEvents: "none", position: "absolute",
        [isRTL ? "left" : "right"]: -130, top: 80,
        width: 280, height: 280, borderRadius: "50%",
        background: "rgba(232,100,42,0.10)", filter: "blur(64px)",
      }} />
      <div style={{
        pointerEvents: "none", position: "absolute",
        [isRTL ? "right" : "left"]: -160, bottom: 40,
        width: 384, height: 384, borderRadius: "50%",
        background: "rgba(255,217,168,0.35)", filter: "blur(80px)",
      }} />

      <div className="container" style={{ paddingTop: 140 }}>
        <div className="hero-grid" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 48, alignItems: "center" }}>

          {/* Text column */}
          <div className="hero-text reveal in" style={{ textAlign: isRTL ? "right" : "left" }}>
            <div style={{
              display: "inline-flex", alignItems: "center", gap: 8,
              padding: "8px 16px 8px 12px", borderRadius: 999,
              background: "var(--coral-soft)", marginBottom: 24,
            }}>
              <span style={{ width: 8, height: 8, borderRadius: "50%", background: "var(--coral)", flexShrink: 0 }} />
              <span style={{ fontSize: 13, fontWeight: 700, color: "var(--coral)" }}>
                {content.hero.availability}
              </span>
            </div>

            <h1 style={{
              fontFamily: isRTL ? "'Heebo', sans-serif" : "var(--font-display)",
              fontWeight: isRTL ? 800 : 400,
              fontSize: "clamp(44px, 6.4vw, 84px)",
              lineHeight: 1.02,
              letterSpacing: isRTL ? "-0.055em" : "-0.02em",
              margin: 0, color: "var(--ink)",
            }}>
              {titleLines.map((line, i) => {
                const isHighlight = line.trim() === content.hero.titleHighlight?.trim();
                return (
                  <span key={i} style={{ display: "block" }}>
                    {isHighlight ? (
                      <span style={{
                        background: "linear-gradient(95deg, var(--coral) 0%, var(--coral-deep) 100%)",
                        WebkitBackgroundClip: "text", backgroundClip: "text",
                        color: "transparent", fontStyle: isRTL ? "normal" : "italic",
                      }}>{line}</span>
                    ) : line}
                  </span>
                );
              })}
            </h1>

            <div style={{ marginTop: 32, height: 4, width: 48, borderRadius: 999, background: "var(--coral)" }} />

            <h2 style={{
              marginTop: 32, maxWidth: 560,
              fontSize: "clamp(18px, 2.2vw, 28px)", fontWeight: 700,
              lineHeight: 1.55, letterSpacing: "-0.03em", color: "var(--ink-2)",
            }}>
              {content.hero.statement}
            </h2>

            <p style={{ marginTop: 24, maxWidth: 520, fontSize: 16, lineHeight: 1.7, color: "var(--ink-3)" }}>
              {content.hero.support}
            </p>

            <div style={{ marginTop: 36, display: "flex", flexWrap: "wrap", gap: 12 }}>
              <a href="#contact" className="btn btn-primary" style={{ borderRadius: 16, padding: "16px 28px" }}>
                {content.hero.primaryCta}
                <Icon name="arrow-up-left" size={20} />
              </a>
              <a href="#projects" style={{
                display: "inline-flex", alignItems: "center", justifyContent: "center",
                borderRadius: 16, border: "1px solid rgba(232,100,42,0.70)",
                background: "rgba(255,255,255,0.55)", padding: "16px 28px",
                fontSize: 15, fontWeight: 700, color: "var(--ink-2)",
                backdropFilter: "blur(4px)", WebkitBackdropFilter: "blur(4px)",
                transition: "background .15s, transform .15s",
              }}>
                {content.hero.secondaryCta}
              </a>
            </div>
          </div>

          {/* Visual column */}
          <div
            className="hero-visual"
            style={{ position: "relative", height: 580 }}
            aria-label="Professional portrait and expertise cards"
          >
            {/* Organic blob */}
            <div className="hero-blob" style={{
              position: "absolute", left: "50%", top: "50%",
              transform: "translate(-50%, -50%)",
              width: 420, height: 500,
              borderRadius: "44% 56% 61% 39% / 44% 39% 61% 56%",
              background: "linear-gradient(135deg, #ffd0a0, #ffaa60, #f47820)",
              boxShadow: "0 35px 90px rgba(244,111,59,0.22)",
              zIndex: 1,
            }} />

            {/* Dot grid — top */}
            <div style={{
              position: "absolute", [isRTL ? "left" : "right"]: "14%", top: "10%",
              width: 128, height: 80, opacity: 0.45, zIndex: 2,
              backgroundImage: "radial-gradient(#bca79b 1.6px, transparent 1.6px)",
              backgroundSize: "14px 14px",
            }} />
            {/* Dot grid — bottom */}
            <div style={{
              position: "absolute", bottom: "7%", [isRTL ? "left" : "right"]: "24%",
              width: 96, height: 80, opacity: 0.35, zIndex: 2,
              backgroundImage: "radial-gradient(#bca79b 1.6px, transparent 1.6px)",
              backgroundSize: "14px 14px",
            }} />

            {/* Accent dots */}
            <div style={{
              position: "absolute", [isRTL ? "right" : "left"]: "11%", bottom: "10%",
              width: 16, height: 16, borderRadius: "50%",
              background: "rgba(232,100,42,0.85)", zIndex: 2,
            }} />
            <div style={{
              position: "absolute", [isRTL ? "right" : "left"]: "4%", top: "32%",
              width: 12, height: 12, borderRadius: "50%",
              border: "1px solid rgba(232,100,42,0.55)", zIndex: 2,
            }} />

            {/* Portrait */}
            <div className="hero-portrait-wrap" style={{
              position: "absolute", left: "50%", top: "50%",
              transform: "translate(-50%, -50%)",
              width: 420, height: 500,
              zIndex: 3,
            }}>
              <img
                src="/images/profile-images/sk-buttons.png"
                alt="שלמה קליחמן"
                draggable="false"
                style={{
                  width: "100%", height: "100%",
                  objectFit: "cover", objectPosition: "center top",
                  display: "block", userSelect: "none",
                  borderRadius: "44% 56% 61% 39% / 44% 39% 61% 56%",
                  boxShadow: "0 22px 48px rgba(38,22,16,0.22)",
                }}
              />
            </div>

            {/* Floating cards — desktop */}
            <div className="hero-cards-desktop">
              {content.hero.floating.map((card, i) => (
                <FloatingCard key={i} data={card} index={i} lang={lang} />
              ))}
            </div>

            {/* Floating cards — mobile grid */}
            <div className="hero-cards-mobile">
              {content.hero.floating.slice(0, 4).map((card, i) => (
                <div key={i} style={{
                  display: "flex", alignItems: "center", gap: 8,
                  borderRadius: 18, border: "1px solid rgba(255,255,255,0.70)",
                  background: "rgba(255,255,255,0.90)", padding: "10px 12px",
                  boxShadow: "0 12px 28px rgba(54,38,25,0.10)",
                  backdropFilter: "blur(8px)", WebkitBackdropFilter: "blur(8px)",
                }}>
                  <Icon name={card.icon} size={18} stroke={1.8} style={{ color: "var(--coral)", flexShrink: 0 }} />
                  <span style={{ fontSize: 12, fontWeight: 700, lineHeight: 1.3, color: "var(--ink)" }}>{card.title}</span>
                </div>
              ))}
            </div>
          </div>
        </div>
      </div>

      <style>{`
        @keyframes hero-fade-up {
          from { opacity: 0; transform: translateY(12px); }
          to { opacity: 1; transform: translateY(0); }
        }
        @keyframes float-y {
          0%, 100% { transform: translateY(0); }
          50% { transform: translateY(-8px); }
        }
        .hero-cards-mobile { display: none; }
        @media (max-width: 920px) {
          .hero-grid { grid-template-columns: 1fr !important; gap: 40px !important; }
          .hero-visual { height: 460px !important; order: 1 !important; }
          .hero-text { order: 2 !important; }
          .hero-blob, .hero-portrait-wrap { width: 360px !important; height: 430px !important; }
        }
        @media (max-width: 600px) {
          .hero-visual { height: 440px !important; }
          .hero-blob, .hero-portrait-wrap { width: 280px !important; height: 320px !important; }
          .hero-cards-desktop { display: none; }
          .hero-cards-mobile {
            display: grid !important;
            position: absolute; bottom: 10px; left: 50%;
            transform: translateX(-50%);
            width: 100%; max-width: 380px;
            grid-template-columns: 1fr 1fr;
            gap: 10px; padding: 0 16px; z-index: 4;
          }
        }
      `}</style>
    </section>
  );
};

const FloatingCard = ({ data, index, lang }) => {
  const isRTL = lang === "he";
  const positions = [
    { [isRTL ? "right" : "left"]: 0,   top:    "16%" },
    { [isRTL ? "right" : "left"]: -8,  top:    "42%" },
    { [isRTL ? "right" : "left"]: 4,   bottom: "12%" },
    { [isRTL ? "left"  : "right"]: 8,  top:    "31%" },
    { [isRTL ? "left"  : "right"]: 4,  bottom: "9%"  },
  ];

  return (
    <div style={{
      position: "absolute", zIndex: 3,
      display: "flex", minHeight: 88, width: 116,
      flexDirection: "column", alignItems: "center", justifyContent: "center",
      gap: 8, borderRadius: 24, textAlign: "center", padding: 16,
      border: "1px solid rgba(255,255,255,0.70)",
      background: "rgba(255,255,255,0.88)",
      boxShadow: "0 18px 45px rgba(54,38,25,0.10)",
      backdropFilter: "blur(12px)", WebkitBackdropFilter: "blur(12px)",
      transition: "transform .2s ease, box-shadow .2s ease",
      animation: `hero-fade-up 0.55s ease-out ${index * 0.12}s both, float-y 6s ease-in-out ${index * 1.2}s infinite`,
      ...positions[index],
    }}>
      <span style={{ color: "var(--coral)" }}>
        <Icon name={data.icon} size={24} stroke={1.8} />
      </span>
      <span style={{ fontSize: 13, fontWeight: 700, lineHeight: 1.3, color: "var(--ink)", whiteSpace: "pre-line" }}>
        {data.title}
      </span>
    </div>
  );
};

/* ================= PROOF ================= */
const Proof = ({ content }) => (
  <section style={{ padding: "20px 0 80px", position: "relative" }}>
    <div className="container">
      <div className="proof-grid" style={{
        display: "grid",
        gridTemplateColumns: "repeat(3, 1fr)",
        gap: 20,
      }}>
        {content.proof.cards.map((c, i) => (
          <div key={i} className={`card reveal${i === 1 ? " proof-offset" : ""}`} style={{
            padding: "48px 26px 28px",
            display: "flex", flexDirection: "column", gap: 14,
            position: "relative", overflow: "visible",
          }}>
            <div style={{
              position: "absolute", top: -22, insetInlineStart: 26,
              width: 48, height: 48, borderRadius: 14,
              background: i === 1 ? "var(--teal-soft)" : "var(--coral-soft)",
              color: i === 1 ? "var(--teal)" : "var(--coral-deep)",
              display: "flex", alignItems: "center", justifyContent: "center",
              boxShadow: "0 4px 14px rgba(31,26,20,0.12)",
            }}>
              <Icon name={c.icon} size={24} stroke={2} />
            </div>
            <h3 style={{ fontSize: 22, margin: 0, color: "var(--ink)", letterSpacing: "-0.01em" }}>{c.title}</h3>
            <p style={{ fontSize: 15, lineHeight: 1.6, color: "var(--ink-3)", margin: 0 }}>{c.body}</p>
          </div>
        ))}
      </div>
    </div>
    <style>{`
      .proof-offset { transform: translateY(36px); }
      @media (max-width: 820px) {
        .proof-grid { grid-template-columns: 1fr !important; gap: 40px !important; padding-top: 28px; }
        .proof-offset { transform: none; }
      }
    `}</style>
  </section>
);

/* ================= ABOUT ================= */
const About = ({ content, lang }) => (
  <section id="about" className="section-pad" style={{ position: "relative" }}>
    <FlowLines style={{ position: "absolute", top: 80, [lang === "he" ? "right" : "left"]: -20, width: 320, height: 600, opacity: 0.5, zIndex: 0 }} color="#E8642A" opacity={0.18} />
    <div className="container">
      <div className="about-grid" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 80, alignItems: "center" }}>
        <div className="reveal">
          <div className="eyebrow" style={{ marginBottom: 16 }}>{content.about.eyebrow}</div>
          <h2 className="section-title" style={{
            fontFamily: lang === "he" ? "'Heebo', sans-serif" : "var(--font-display)",
            fontWeight: lang === "he" ? 700 : 400,
            fontSize: "clamp(34px, 4.4vw, 56px)",
            lineHeight: 1.05,
            letterSpacing: lang === "he" ? "-0.02em" : "-0.015em",
            marginBottom: 28,
          }}>
            {content.about.title.split("\n").map((l, i) => <span key={i} style={{ display: "block" }}>{l}</span>)}
          </h2>
          {content.about.paragraphs.map((p, i) => (
            <p key={i} style={{ fontSize: 16, lineHeight: 1.7, color: "var(--ink-2)", margin: "0 0 16px" }}>{p}</p>
          ))}
        </div>
        <div className="reveal">
          <AboutDiagram content={content} />
        </div>
      </div>
    </div>
    <style>{`
      @media (max-width: 820px) {
        .about-grid { grid-template-columns: 1fr !important; gap: 48px !important; }
      }
    `}</style>
  </section>
);

/* ================= EXPERTISE ================= */
const Expertise = ({ content, lang }) => (
  <section id="expertise" className="section-pad" style={{ background: "linear-gradient(180deg, transparent, rgba(245,236,220,0.55) 30%, rgba(245,236,220,0.55) 70%, transparent)", position: "relative" }}>
    <div className="container">
      <div style={{ textAlign: "center", marginBottom: 56 }} className="reveal">
        <div className="eyebrow" style={{ marginBottom: 14 }}>{content.expertise.eyebrow}</div>
        <h2 className="section-title display" style={{ marginBottom: 14 }}>
          {content.expertise.title.split("\n").map((l, i) => <span key={i} style={{ display: "block" }}>{l}</span>)}
        </h2>
        <p className="section-intro">{content.expertise.intro}</p>
      </div>
      <div className="exp-grid" style={{
        display: "grid",
        gridTemplateColumns: "repeat(3, 1fr)",
        gap: 20,
      }}>
        {content.expertise.cards.map((c, i) => (
          <ExpertiseCard key={i} card={c} index={i} />
        ))}
      </div>
    </div>
    <style>{`
      @media (max-width: 980px) {
        .exp-grid { grid-template-columns: repeat(2, 1fr) !important; }
      }
      @media (max-width: 620px) {
        .exp-grid { grid-template-columns: 1fr !important; }
      }
    `}</style>
  </section>
);

const ExpertiseCard = ({ card, index }) => {
  const colorMap = [
    { bg: "var(--coral-soft)", icon: "var(--coral-deep)" },
    { bg: "var(--teal-soft)",  icon: "var(--teal)" },
    { bg: "#F1E0BF",           icon: "#6E5325" },
    { bg: "var(--teal-soft)",  icon: "var(--teal)" },
    { bg: "var(--coral-soft)", icon: "var(--coral-deep)" },
    { bg: "#EFEAD8",           icon: "var(--olive)" },
  ];
  const c = colorMap[index % colorMap.length];
  return (
    <article className="card reveal" style={{ padding: "28px 26px", display: "flex", flexDirection: "column", gap: 14, position: "relative", overflow: "hidden" }}>
      <div style={{
        width: 52, height: 52, borderRadius: 14,
        background: c.bg, color: c.icon,
        display: "flex", alignItems: "center", justifyContent: "center",
      }}>
        <Icon name={card.icon} size={26} stroke={1.7} />
      </div>
      <h3 style={{ fontSize: 20, lineHeight: 1.25, margin: 0, color: "var(--ink)", letterSpacing: "-0.01em" }}>{card.title}</h3>
      <p style={{ fontSize: 14.5, lineHeight: 1.6, color: "var(--ink-3)", margin: 0 }}>{card.body}</p>
      <div style={{ display: "flex", flexWrap: "wrap", gap: 6, marginTop: 4 }}>
        {card.tags.map((t, i) => <span key={i} className="tag">{t}</span>)}
      </div>
    </article>
  );
};

/* ================= PROJECTS ================= */
const Projects = ({ content, openModal }) => (
  <section id="projects" className="section-pad" style={{ position: "relative" }}>
    <div className="container">
      <div style={{ textAlign: "center", marginBottom: 56 }} className="reveal">
        <div className="eyebrow" style={{ marginBottom: 14 }}>{content.projects.eyebrow}</div>
        <h2 className="section-title display" style={{ marginBottom: 14 }}>{content.projects.title}</h2>
        <p className="section-intro">{content.projects.intro}</p>
      </div>
      <div className="proj-grid" style={{
        display: "grid",
        gridTemplateColumns: "1fr 1fr 1fr",
        gap: 24,
      }}>
        {content.projects.items.map((p, i) => (
          <ProjectCard key={p.id} project={p} readMore={content.projects.readMore} onClick={() => openModal(p)} />
        ))}
      </div>
    </div>
    <style>{`
      @media (max-width: 980px) {
        .proj-grid { grid-template-columns: 1fr 1fr !important; }
      }
      @media (max-width: 620px) {
        .proj-grid { grid-template-columns: 1fr !important; }
      }
    `}</style>
  </section>
);

const ProjectCard = ({ project, readMore, onClick }) => (
  <article className="card reveal" style={{ display: "flex", flexDirection: "column", overflow: "hidden" }}>
    <div style={{ aspectRatio: "16/10.4", background: "#1F1A14", overflow: "hidden", position: "relative" }}>
      <ProjectMockup name={project.mockup} />
    </div>
    <div style={{ padding: "22px 22px 24px", display: "flex", flexDirection: "column", gap: 12, flex: 1 }}>
      <div style={{ display: "flex", flexWrap: "wrap", gap: 6 }}>
        {project.tags.slice(0, 2).map((t, i) => (
          <span key={i} className={`tag ${i === 0 ? "tag-coral" : "tag-teal"}`}>{t}</span>
        ))}
      </div>
      <h3 style={{ fontSize: 20, margin: 0, color: "var(--ink)", letterSpacing: "-0.01em" }}>{project.title}</h3>
      <p style={{ fontSize: 14.5, lineHeight: 1.6, color: "var(--ink-3)", margin: 0, flex: 1 }}>{project.summary}</p>
      <button onClick={onClick} className="btn btn-ghost btn-small" style={{ alignSelf: "flex-start", marginTop: 4 }}>
        {readMore}
        <Icon name="arrow" size={14} className="flip-rtl" />
      </button>
    </div>
  </article>
);

/* ================= CASE STUDY MODAL ================= */
const Modal = ({ project, content, onClose }) => {
  const closeBtnRef = useRef(null);

  useEffect(() => {
    if (!project) return;
    const onKey = (e) => e.key === "Escape" && onClose();
    document.body.style.overflow = "hidden";
    window.addEventListener("keydown", onKey);
    closeBtnRef.current?.focus();
    return () => {
      document.body.style.overflow = "";
      window.removeEventListener("keydown", onKey);
    };
  }, [project, onClose]);

  if (!project) return null;
  const L = content.projects.modalLabels;

  return (
    <div
      role="dialog"
      aria-modal="true"
      aria-labelledby="modal-title"
      onClick={onClose}
      style={{
        position: "fixed", inset: 0, zIndex: 100,
        background: "rgba(31,26,20,0.55)",
        backdropFilter: "blur(6px)",
        display: "flex", alignItems: "flex-start", justifyContent: "center",
        padding: "60px 20px",
        overflowY: "auto",
        animation: "modal-fade .2s ease",
      }}
    >
      <div onClick={(e) => e.stopPropagation()} style={{
        background: "var(--bg)",
        borderRadius: 22,
        width: "100%", maxWidth: 880,
        overflow: "hidden",
        boxShadow: "0 40px 80px -20px rgba(0,0,0,0.4)",
        position: "relative",
        animation: "modal-slide .25s ease",
      }}>
        <button
          ref={closeBtnRef}
          onClick={onClose}
          aria-label={content.projects.closeLabel}
          style={{
            position: "absolute", top: 16, insetInlineEnd: 16, zIndex: 5,
            width: 40, height: 40, borderRadius: 999,
            background: "rgba(255,255,255,0.92)", border: "1px solid var(--line)",
            display: "flex", alignItems: "center", justifyContent: "center",
            color: "var(--ink)",
          }}
        >
          <Icon name="x" size={18} />
        </button>

        <div style={{ aspectRatio: "16/7.6", background: "#1F1A14", overflow: "hidden" }}>
          <ProjectMockup name={project.mockup} />
        </div>

        <div style={{ padding: "32px 36px 36px" }}>
          <div style={{ display: "flex", flexWrap: "wrap", gap: 6, marginBottom: 14 }}>
            {project.tags.map((t, i) => (
              <span key={i} className={`tag ${i === 0 ? "tag-coral" : "tag-teal"}`}>{t}</span>
            ))}
          </div>
          <h2 id="modal-title" className="display" style={{ fontSize: "clamp(28px, 3.6vw, 40px)", margin: "0 0 12px", letterSpacing: "-0.02em" }}>
            {project.title}
          </h2>
          <p style={{ fontSize: 17, lineHeight: 1.6, color: "var(--ink-2)", margin: "0 0 28px" }}>{project.summary}</p>

          <div style={{ display: "grid", gridTemplateColumns: "repeat(2, 1fr)", gap: "22px 36px" }} className="modal-grid">
            <ModalBlock label={L.background} text={project.modal.background} />
            <ModalBlock label={L.challenge} text={project.modal.challenge} />
            <ModalBlock label={L.solution} text={project.modal.solution} />
            <ModalBlock label={L.role} text={project.modal.role} />
            <div style={{ gridColumn: "1 / -1" }}>
              <div className="eyebrow" style={{ marginBottom: 10 }}>{L.tech}</div>
              <div style={{ display: "flex", flexWrap: "wrap", gap: 8 }}>
                {project.modal.tech.map((t, i) => <span key={i} className="tag">{t}</span>)}
              </div>
            </div>
            <div style={{ gridColumn: "1 / -1", padding: "20px 22px", background: "var(--coral-soft)", borderRadius: 14, border: "1px solid rgba(232,100,42,0.15)" }}>
              <div className="eyebrow" style={{ marginBottom: 8 }}>{L.outcome}</div>
              <p style={{ fontSize: 16, lineHeight: 1.55, color: "var(--ink)", margin: 0, fontWeight: 500 }}>{project.modal.outcome}</p>
            </div>
          </div>
        </div>
      </div>
      <style>{`
        @keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
        @keyframes modal-slide { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
        @media (max-width: 640px) {
          .modal-grid { grid-template-columns: 1fr !important; gap: 18px !important; }
        }
      `}</style>
    </div>
  );
};

const ModalBlock = ({ label, text }) => (
  <div>
    <div className="eyebrow" style={{ marginBottom: 8 }}>{label}</div>
    <p style={{ fontSize: 14.5, lineHeight: 1.6, color: "var(--ink-2)", margin: 0 }}>{text}</p>
  </div>
);

/* ================= TESTIMONIALS ================= */
const Testimonials = ({ content }) => (
  <section id="testimonials" className="section-pad" style={{ background: "linear-gradient(180deg, transparent, rgba(245,236,220,0.4) 50%, transparent)" }}>
    <div className="container">
      <div style={{ textAlign: "center", marginBottom: 48 }} className="reveal">
        <div className="eyebrow" style={{ marginBottom: 14 }}>{content.testimonials.eyebrow}</div>
        <h2 className="section-title display">{content.testimonials.title}</h2>
      </div>
      <div className="testi-grid" style={{
        columns: 2,
        columnGap: 20,
      }}>
        {content.testimonials.items.map((t, i) => <TestimonialCard key={i} t={t} index={i} />)}
      </div>
    </div>
    <style>{`
      @media (max-width: 820px) {
        .testi-grid { columns: 1 !important; }
      }
    `}</style>
  </section>
);

const TestimonialCard = ({ t, index }) => {
  const colorMap = {
    coral: { bg: "var(--coral-soft)", fg: "var(--coral-deep)" },
    teal:  { bg: "var(--teal-soft)",  fg: "var(--teal)" },
    olive: { bg: "#EFEAD8",           fg: "var(--olive)" },
  };
  const c = colorMap[t.color] || colorMap.coral;

  return (
    <article className="card reveal" style={{
      padding: "28px 28px 26px",
      position: "relative",
      breakInside: "avoid",
      display: "inline-block",
      width: "100%",
      marginBottom: 20,
    }}>
      <div style={{
        position: "absolute", top: 20, insetInlineEnd: 22,
        color: c.fg, opacity: 0.35,
      }}>
        <Icon name="quote" size={36} />
      </div>
      <p style={{ fontSize: 16, lineHeight: 1.7, color: "var(--ink-2)", margin: "0 0 22px", maxWidth: "92%" }}>
        "{t.quote}"
      </p>
      <div style={{ display: "flex", alignItems: "center", gap: 14, paddingTop: 18, borderTop: "1px solid var(--line-soft)" }}>
        {t.photo ? (
          <img src={t.photo} alt={t.name} style={{ width: 44, height: 44, borderRadius: "50%", objectFit: "cover", objectPosition: "center top", flexShrink: 0 }} />
        ) : (
          <div style={{
            width: 44, height: 44, borderRadius: "50%",
            background: c.bg, color: c.fg,
            display: "flex", alignItems: "center", justifyContent: "center",
            fontWeight: 700, fontSize: 14, letterSpacing: "0.02em", flexShrink: 0,
          }}>
            {t.avatar}
          </div>
        )}
        <div style={{ lineHeight: 1.3 }}>
          <div style={{ fontWeight: 700, color: "var(--ink)", fontSize: 15 }}>{t.name}</div>
          <div style={{ fontSize: 13, color: "var(--ink-3)" }}>{t.role} · {t.company}</div>
        </div>
      </div>
    </article>
  );
};

/* ================= CONTACT ================= */
const Contact = ({ content, lang }) => {
  const [form, setForm] = useState({ name: "", email: "", interest: content.contact.interests[0], message: "" });
  const [sent, setSent] = useState(false);

  const onSubmit = (e) => {
    e.preventDefault();
    if (!form.name || !form.email || !form.message) return;
    setSent(true);
    setTimeout(() => setSent(false), 4000);
    setForm({ name: "", email: "", interest: content.contact.interests[0], message: "" });
  };

  return (
    <section id="contact" style={{ padding: "60px 0 100px", position: "relative" }}>
      <div className="container">
        <div className="contact-block" style={{
          position: "relative",
          background: "linear-gradient(135deg, #FBE0CB 0%, #F2C7A3 100%)",
          borderRadius: 28,
          padding: 56,
          overflow: "hidden",
          border: "1px solid rgba(232,100,42,0.15)",
        }}>
          {/* decorative shapes */}
          <svg viewBox="0 0 500 500" style={{ position: "absolute", top: -100, insetInlineEnd: -100, width: 400, opacity: 0.5 }} aria-hidden="true">
            <circle cx="250" cy="250" r="200" fill="#E8642A" opacity="0.25" />
            <circle cx="250" cy="250" r="120" fill="none" stroke="#E8642A" strokeOpacity="0.3" />
          </svg>
          <FlowLines style={{ position: "absolute", bottom: -100, insetInlineStart: -50, width: 300, height: 500, opacity: 0.5 }} color="#C84F18" opacity={0.25} />

          <div className="contact-grid" style={{
            position: "relative",
            display: "grid",
            gridTemplateColumns: "1fr 1fr",
            gap: 56,
            alignItems: "start",
          }}>
            {/* LEFT */}
            <div>
              <div className="eyebrow" style={{ marginBottom: 14 }}>{content.contact.eyebrow}</div>
              <h2 className="display" style={{
                fontFamily: lang === "he" ? "'Heebo', sans-serif" : "var(--font-display)",
                fontWeight: lang === "he" ? 700 : 400,
                fontSize: "clamp(36px, 4.8vw, 60px)",
                lineHeight: 1.05,
                margin: "0 0 20px",
                color: "var(--ink)",
                letterSpacing: "-0.02em",
              }}>
                {content.contact.headline.split("\n").map((l, i) => <span key={i} style={{ display: "block" }}>{l}</span>)}
              </h2>
              <p style={{ fontSize: 17, lineHeight: 1.6, color: "var(--ink-2)", margin: "0 0 32px", maxWidth: 420 }}>
                {content.contact.support}
              </p>

              <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "flex", flexDirection: "column", gap: 14 }}>
                <li style={{ display: "flex", alignItems: "center", gap: 12, fontSize: 15, color: "var(--ink)" }}>
                  <span style={{ width: 38, height: 38, borderRadius: 10, background: "rgba(255,255,255,0.65)", display: "flex", alignItems: "center", justifyContent: "center", color: "var(--coral-deep)" }}>
                    <Icon name="mail" size={18} />
                  </span>
                  <a href={`mailto:${content.contact.email}`} style={{ fontWeight: 500 }}>{content.contact.email}</a>
                </li>
                <li style={{ display: "flex", alignItems: "center", gap: 12, fontSize: 15, color: "var(--ink)" }}>
                  <span style={{ width: 38, height: 38, borderRadius: 10, background: "rgba(255,255,255,0.65)", display: "flex", alignItems: "center", justifyContent: "center", color: "var(--coral-deep)" }}>
                    <Icon name="linkedin" size={16} />
                  </span>
                  <a href="https://www.linkedin.com/in/shlomo-kalichman/" target="_blank" rel="noreferrer" style={{ fontWeight: 500 }}>{content.contact.linkedin}</a>
                </li>
                <li style={{ display: "flex", alignItems: "center", gap: 12, fontSize: 15, color: "var(--ink)" }}>
                  <span style={{ width: 38, height: 38, borderRadius: 10, background: "rgba(255,255,255,0.65)", display: "flex", alignItems: "center", justifyContent: "center", color: "var(--coral-deep)" }}>
                    <Icon name="pin" size={18} />
                  </span>
                  <span style={{ fontWeight: 500 }}>{content.contact.location}</span>
                </li>
              </ul>
            </div>

            {/* RIGHT — form */}
            <form onSubmit={onSubmit} style={{
              background: "rgba(255,255,255,0.85)",
              backdropFilter: "blur(6px)",
              borderRadius: 20,
              padding: 28,
              border: "1px solid rgba(255,255,255,0.6)",
              boxShadow: "0 20px 50px -20px rgba(31,26,20,0.2)",
            }}>
              <div className="form-row" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 14, marginBottom: 14 }}>
                <Field label={content.contact.fields.name} placeholder={content.contact.placeholders.name}
                       value={form.name} onChange={(v) => setForm({ ...form, name: v })} />
                <Field label={content.contact.fields.email} type="email" placeholder={content.contact.placeholders.email}
                       value={form.email} onChange={(v) => setForm({ ...form, email: v })} />
              </div>
              <div style={{ marginBottom: 14 }}>
                <Field
                  label={content.contact.fields.interest}
                  type="select"
                  value={form.interest}
                  onChange={(v) => setForm({ ...form, interest: v })}
                  options={content.contact.interests}
                />
              </div>
              <div style={{ marginBottom: 18 }}>
                <Field label={content.contact.fields.message} type="textarea" placeholder={content.contact.placeholders.message}
                       value={form.message} onChange={(v) => setForm({ ...form, message: v })} />
              </div>
              <button type="submit" className="btn btn-primary" style={{ width: "100%", justifyContent: "center", padding: "16px 22px", fontSize: 16 }}>
                {sent ? (<><Icon name="check" size={18} /> {content.contact.sent}</>) : (<>{content.contact.cta} <Icon name="arrow" size={16} className="flip-rtl" /></>)}
              </button>
            </form>
          </div>
        </div>
      </div>
      <style>{`
        @media (max-width: 900px) {
          .contact-block { padding: 36px 28px !important; border-radius: 22px !important; }
          .contact-grid { grid-template-columns: 1fr !important; gap: 32px !important; }
          .form-row { grid-template-columns: 1fr !important; }
        }
      `}</style>
    </section>
  );
};

const Field = ({ label, type = "text", value, onChange, placeholder, options }) => {
  const baseInput = {
    width: "100%",
    padding: "12px 14px",
    borderRadius: 12,
    border: "1px solid var(--line)",
    background: "#FFFFFF",
    fontSize: 14.5,
    color: "var(--ink)",
    fontFamily: "inherit",
    outline: "none",
    transition: "border-color .15s, box-shadow .15s",
  };
  const handleFocus = (e) => {
    e.target.style.borderColor = "var(--coral)";
    e.target.style.boxShadow = "0 0 0 3px rgba(232,100,42,0.15)";
  };
  const handleBlur = (e) => {
    e.target.style.borderColor = "var(--line)";
    e.target.style.boxShadow = "none";
  };
  return (
    <label style={{ display: "block" }}>
      <span style={{ display: "block", fontSize: 13, fontWeight: 600, color: "var(--ink-2)", marginBottom: 6 }}>{label}</span>
      {type === "textarea" ? (
        <textarea
          rows={4}
          value={value}
          onChange={(e) => onChange(e.target.value)}
          placeholder={placeholder}
          onFocus={handleFocus}
          onBlur={handleBlur}
          style={{ ...baseInput, resize: "vertical", minHeight: 100 }}
        />
      ) : type === "select" ? (
        <select
          value={value}
          onChange={(e) => onChange(e.target.value)}
          onFocus={handleFocus}
          onBlur={handleBlur}
          style={baseInput}
        >
          {options.map((o, i) => <option key={i} value={o}>{o}</option>)}
        </select>
      ) : (
        <input
          type={type}
          value={value}
          onChange={(e) => onChange(e.target.value)}
          placeholder={placeholder}
          onFocus={handleFocus}
          onBlur={handleBlur}
          style={baseInput}
        />
      )}
    </label>
  );
};

/* ================= FOOTER ================= */
const Footer = ({ content, lang, setLang }) => (
  <footer style={{ padding: "60px 0 40px", borderTop: "1px solid var(--line-soft)", background: "linear-gradient(180deg, transparent, rgba(238,223,200,0.35))" }}>
    <div className="container">
      <div className="footer-grid" style={{
        display: "grid",
        gridTemplateColumns: "1.4fr 1fr 1fr",
        gap: 40,
        marginBottom: 36,
      }}>
        <div>
          <div dir="ltr" style={{ fontFamily: "var(--font-en)", fontSize: 24, fontWeight: 800, letterSpacing: "-0.04em", color: "var(--ink)", marginBottom: 14, textAlign: lang === "he" ? "right" : "left" }}>
            Shlomo Kalichman<span style={{ color: "var(--coral)" }}>.</span>
          </div>
          <p style={{ fontSize: 15, color: "var(--ink-3)", lineHeight: 1.6, maxWidth: 340, margin: 0 }}>{content.footer.tagline}</p>
        </div>
        {content.footer.groups.map((g, i) => (
          <div key={i}>
            <h4 style={{ fontSize: 13, fontWeight: 700, letterSpacing: "0.12em", textTransform: "uppercase", color: "var(--ink-3)", margin: "0 0 14px" }}>{g.title}</h4>
            <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "flex", flexDirection: "column", gap: 8 }}>
              {g.items.map((it, j) => (
                <li key={j}>
                  <a href={g.anchors?.[j] || "#"} style={{ fontSize: 14.5, color: "var(--ink-2)" }}>{it}</a>
                </li>
              ))}
            </ul>
          </div>
        ))}
      </div>
      <div style={{
        display: "flex", flexWrap: "wrap", justifyContent: "space-between", alignItems: "center", gap: 16,
        paddingTop: 24, borderTop: "1px solid var(--line-soft)",
        fontSize: 13.5, color: "var(--ink-3)",
      }}>
        <span>{content.footer.copy} · {new Date().getFullYear()}</span>
        <div style={{ display: "flex", gap: 14, alignItems: "center" }}>
          <button onClick={() => setLang(lang === "he" ? "en" : "he")}
                  style={{ background: "transparent", border: 0, fontSize: 13.5, color: "var(--ink-2)", padding: 0, cursor: "pointer", textDecoration: "underline", textUnderlineOffset: 3 }}>
            {lang === "he" ? "View in English" : "צפו בעברית"}
          </button>
        </div>
      </div>
    </div>
    <style>{`
      @media (max-width: 820px) {
        .footer-grid { grid-template-columns: 1fr 1fr !important; gap: 28px !important; }
      }
      @media (max-width: 520px) {
        .footer-grid { grid-template-columns: 1fr !important; }
      }
    `}</style>
  </footer>
);

Object.assign(window, {
  useReveal, Header, Hero, Proof, About, Expertise, Projects, ProjectCard, Modal,
  Testimonials, Contact, Footer,
});
