/* ===========================================================
   Sections
   =========================================================== */

/* ---------- HOME ---------- */
function HomeSection({ onNav }) {
  return (
    <main
      style={{
        maxWidth: 1320, margin: "0 auto",
        padding: "0 32px",
        minHeight: "calc(100vh - 73px)",
        display: "grid", gridTemplateColumns: "minmax(0,1.05fr) minmax(0,1fr)",
        gap: 56, alignItems: "center",
      }}
    >
      {/* left: title */}
      <div style={{ padding: "80px 0" }}>
        <div
          style={{
            fontFamily: "var(--mono)",
            fontSize: 11, letterSpacing: "0.22em",
            textTransform: "uppercase",
            color: "var(--accent)",
            marginBottom: 28,
            display: "flex", alignItems: "center", gap: 12,
          }}
        >
          <span style={{ width: 6, height: 6, borderRadius: "50%", background: "var(--accent)", boxShadow: "0 0 12px var(--accent)" }} />
          {DATA.role}
        </div>

        <h1
          style={{
            fontFamily: "var(--serif)",
            fontWeight: 500,
            fontSize: "clamp(72px, 9.5vw, 168px)",
            lineHeight: 0.88,
            letterSpacing: "-0.025em",
            margin: 0,
          }}
        >
          Thiru<span style={{ color: "var(--ink-mute)", fontStyle: "italic" }}>.</span>
        </h1>
        <h2
          style={{
            fontFamily: "var(--serif)",
            fontStyle: "italic",
            fontWeight: 400,
            fontSize: "clamp(22px, 2.2vw, 30px)",
            color: "var(--ink-dim)",
            margin: "8px 0 32px",
            letterSpacing: "0.005em",
          }}
        >
          Thirumurugan Sivalingam
        </h2>

        <p
          style={{
            fontSize: 17, lineHeight: 1.6,
            color: "var(--ink-dim)",
            maxWidth: 480, margin: "0 0 40px",
          }}
        >
          {DATA.tagline}
        </p>

        <div style={{ display: "flex", gap: 16, flexWrap: "wrap" }}>
          <Btn variant="primary" onClick={() => onNav("contact")}>
            Get in touch
            <span style={{ fontFamily: "var(--mono)" }}>→</span>
          </Btn>
          <Btn variant="ghost" onClick={() => onNav("watch")}>
            Watch talks
          </Btn>
        </div>
      </div>

      {/* right: terminal card */}
      <div style={{ padding: "80px 0" }}>
        <div style={{ position: "relative" }}>
          {/* corner ticks */}
          {["tl","tr","bl","br"].map(p => (
            <span key={p} style={{
              position: "absolute", zIndex: 2,
              width: 10, height: 10,
              borderColor: "var(--accent)", borderStyle: "solid", borderWidth: 0,
              top:    p[0] === "t" ? -1 : "auto",
              bottom: p[0] === "b" ? -1 : "auto",
              left:   p[1] === "l" ? -1 : "auto",
              right:  p[1] === "r" ? -1 : "auto",
              borderTopWidth:    p[0] === "t" ? 1 : 0,
              borderBottomWidth: p[0] === "b" ? 1 : 0,
              borderLeftWidth:   p[1] === "l" ? 1 : 0,
              borderRightWidth:  p[1] === "r" ? 1 : 0,
            }} />
          ))}

          <div style={{
            border: "1px solid var(--line)",
            background: "#0a0c10",
            overflow: "hidden",
          }}>
            {/* title bar */}
            <div style={{
              display: "flex", alignItems: "center", gap: 8,
              padding: "12px 16px",
              borderBottom: "1px solid var(--line)",
              background: "var(--panel)",
            }}>
              <span style={{ width: 11, height: 11, borderRadius: "50%", background: "oklch(0.62 0.13 25)" }} />
              <span style={{ width: 11, height: 11, borderRadius: "50%", background: "oklch(0.74 0.11 80)" }} />
              <span style={{ width: 11, height: 11, borderRadius: "50%", background: "oklch(0.66 0.12 150)" }} />
              <span style={{
                marginLeft: 10, fontFamily: "var(--mono)", fontSize: 11,
                color: "var(--ink-mute)", letterSpacing: "0.04em",
              }}>
                ~/thiru · zsh · 64×20
              </span>
            </div>

            {/* body */}
            <div style={{
              padding: "22px 24px 26px",
              fontFamily: "var(--mono)", fontSize: 13.5, lineHeight: 1.85,
              color: "var(--ink-dim)",
            }}>
              {(() => {
                const accent = "var(--accent)";
                const key = "oklch(0.78 0.09 230)";
                const str = "var(--warm)";
                const num = "var(--ink)";
                const mute = "var(--ink-mute)";
                const punc = "var(--ink-dim)";
                const Prompt = () => <span style={{ color: accent, userSelect: "none" }}>$ </span>;
                const K = ({ children }) => <span style={{ color: key }}>"{children}"</span>;
                const S = ({ children }) => <span style={{ color: str }}>"{children}"</span>;
                const N = ({ children }) => <span style={{ color: num }}>{children}</span>;
                return (
                  <React.Fragment>
                    <div><Prompt />whoami</div>
                    <div style={{ color: mute }}>// ex-metis devrel · exploring ai + content</div>
                    <div style={{ marginTop: 8 }}><Prompt />cat thiru.json</div>
                    <div style={{ color: punc }}>{"{"}</div>
                    <div>&nbsp;&nbsp;<K>hackathons_won</K><span style={{ color: punc }}>: </span><N>25</N><span style={{ color: punc }}>,</span></div>
                    <div>&nbsp;&nbsp;<K>workshops_hosted</K><span style={{ color: punc }}>: </span><N>30</N><span style={{ color: punc }}>,</span></div>
                    <div>&nbsp;&nbsp;<K>countries_visited</K><span style={{ color: punc }}>: </span><N>15</N><span style={{ color: punc }}>,</span></div>
                    <div>&nbsp;&nbsp;<K>years_in_web3</K><span style={{ color: punc }}>: </span><N>4</N><span style={{ color: punc }}>,</span></div>
                    <div>&nbsp;&nbsp;<K>now</K><span style={{ color: punc }}>: </span><S>exploring AI · creating content</S><span style={{ color: punc }}>,</span></div>
                    <div>&nbsp;&nbsp;<K>learning</K><span style={{ color: punc }}>: </span><S>Japanese (JLPT)</S><span style={{ color: punc }}>,</span></div>
                    <div>&nbsp;&nbsp;<K>off_hours</K><span style={{ color: punc }}>: </span><S>running · gym · blogging</S><span style={{ color: punc }}>,</span></div>
                    <div>&nbsp;&nbsp;<K>open_to</K><span style={{ color: punc }}>: </span><S>collabs · content · talks</S></div>
                    <div style={{ color: punc }}>{"}"}</div>
                    <div style={{ marginTop: 8 }}>
                      <Prompt />
                      <span style={{
                        display: "inline-block", width: 8, height: "1.05em",
                        background: "var(--accent)", verticalAlign: "-2px",
                        animation: "blink 1.1s step-end infinite",
                      }} />
                    </div>
                  </React.Fragment>
                );
              })()}
            </div>
          </div>
        </div>

        {/* availability strip */}
        <div style={{
          marginTop: 16,
          display: "flex", alignItems: "center", gap: 10,
          fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.18em",
          textTransform: "uppercase", color: "var(--ink-mute)",
        }}>
          <span style={{ width: 6, height: 6, borderRadius: "50%", background: "oklch(0.66 0.12 150)" }} />
          Open to work · responds within a day
        </div>
      </div>
    </main>
  );
}

/* ---------- ABOUT ---------- */
function AboutSection() {
  return (
    <Page label="01 · About" title="About" kicker="From hackathon all-nighters to the front of the stage.">
      {/* stats row */}
      <div style={{
        display: "grid", gridTemplateColumns: "repeat(5, 1fr)",
        gap: 24, marginBottom: 80, paddingBottom: 56,
        borderBottom: "1px solid var(--line)",
      }}>
        {DATA.stats.map(s => (
          <div key={s.k}>
            <div style={{
              fontFamily: "var(--serif)", fontWeight: 500,
              fontSize: 56, lineHeight: 1, letterSpacing: "-0.02em",
            }}>
              {s.v}
            </div>
            <div style={{
              fontFamily: "var(--mono)", fontSize: 10,
              letterSpacing: "0.18em", textTransform: "uppercase",
              color: "var(--ink-mute)", marginTop: 12,
            }}>
              {s.k}
            </div>
          </div>
        ))}
      </div>

      {/* bio + timeline */}
      <div style={{
        display: "grid", gridTemplateColumns: "minmax(0, 1fr) minmax(0, 1fr)",
        gap: 72,
      }}>
        <div style={{ fontSize: 18, lineHeight: 1.7, color: "var(--ink-dim)" }}>
          <p style={{ margin: "0 0 24px", color: "var(--ink)", fontSize: 22, lineHeight: 1.55 }}>
            I'm <span style={{ color: "var(--accent)" }}>Thiru</span>. Until May 2026 I was Lead DevRel at <span style={{ color: "var(--ink)" }}>Metis Foundation</span>, building the developer surface for onchain AI. Right now I'm heads-down exploring AI and creating content.
          </p>
          <p style={{ margin: "0 0 20px" }}>
            Four years in web3. I've worn the hats of founding dev, lead dev, DevRel, community lead, sometimes all in the same week. I learn by shipping, then I write down what I learned so the next builder doesn't trip over it.
          </p>
          <p style={{ margin: "0 0 20px" }}>
            Over four years and a handful of teams I've shipped protocols, SDKs and onchain games, written docs that actually get read, run hackathon programs people finish, and hosted <span style={{ color: "var(--ink)" }}>30+</span> workshops for chains and protocols from Starknet to Base. As Lead DevRel at Metis I owned the developer playbook end-to-end across Hyperion, LazAI and Andromeda, lifting onboarding <span style={{ color: "var(--ink)" }}>35%</span>.
          </p>
          <p style={{ margin: 0 }}>
            These days I'm exploring AI, creating content, and learning Japanese. I've contributed to <span style={{ color: "var(--ink)" }}>Starknet</span>, <span style={{ color: "var(--ink)" }}>Okto</span>, and <span style={{ color: "var(--ink)" }}>ORA</span>, write blogs, and ship the occasional protocol of my own. Off the keyboard: running and the gym. Twenty-five hackathon wins so far.
          </p>

          {/* skills mini-grid */}
          <div style={{ marginTop: 56 }}>
            <div style={{
              fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.22em",
              color: "var(--accent)", textTransform: "uppercase", marginBottom: 20,
            }}>
              Stack
            </div>
            <div style={{ display: "grid", gridTemplateColumns: "auto 1fr", rowGap: 14, columnGap: 24 }}>
              {Object.entries(DATA.skills).map(([k, vals]) => (
                <React.Fragment key={k}>
                  <div style={{
                    fontFamily: "var(--mono)", fontSize: 11,
                    letterSpacing: "0.12em", textTransform: "uppercase",
                    color: "var(--ink-mute)", paddingTop: 2,
                  }}>
                    {k}
                  </div>
                  <div style={{ display: "flex", flexWrap: "wrap", gap: 6 }}>
                    {vals.map(v => (
                      <span key={v} style={{
                        fontSize: 13, color: "var(--ink-dim)",
                        padding: "3px 9px",
                        border: "1px solid var(--line)",
                        background: "var(--panel)",
                      }}>
                        {v}
                      </span>
                    ))}
                  </div>
                </React.Fragment>
              ))}
            </div>
          </div>
        </div>

        {/* experience */}
        <div>
          <div style={{
            border: "1px solid var(--line)",
            background: "var(--panel)",
            padding: 32,
          }}>
            <div style={{
              fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.22em",
              color: "var(--accent)", textTransform: "uppercase", marginBottom: 24,
            }}>
              Experience
            </div>
            <div style={{ position: "relative", paddingLeft: 20 }}>
              <div style={{
                position: "absolute", left: 3, top: 6, bottom: 6,
                width: 1, background: "var(--line-2)",
              }} />
              {DATA.experience.map((e, i) => (
                <div key={i} style={{ position: "relative", marginBottom: i === DATA.experience.length - 1 ? 0 : 32 }}>
                  <span style={{
                    position: "absolute", left: -20, top: 6,
                    width: 7, height: 7, borderRadius: "50%",
                    background: i === 0 ? "var(--accent)" : "var(--ink-mute)",
                    boxShadow: i === 0 ? "0 0 0 4px oklch(0.66 0.18 275 / 0.18)" : "none",
                  }} />
                  <div style={{
                    fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.18em",
                    color: "var(--ink-mute)", textTransform: "uppercase",
                  }}>
                    {e.when}
                  </div>
                  <div style={{
                    fontFamily: "var(--serif)", fontSize: 22, lineHeight: 1.2,
                    margin: "6px 0 2px", color: "var(--ink)",
                  }}>
                    {e.role}
                  </div>
                  <div style={{ fontSize: 13, color: "var(--ink-dim)", marginBottom: 8 }}>
                    <span style={{ color: "var(--accent)" }}>{e.org}</span>
                    <span style={{ color: "var(--ink-mute)" }}> · {e.kind}</span>
                  </div>
                  <ul style={{ margin: 0, padding: "0 0 0 14px", color: "var(--ink-mute)", fontSize: 13, lineHeight: 1.6 }}>
                    {e.bullets.map((b, j) => <li key={j}>{b}</li>)}
                  </ul>
                </div>
              ))}
            </div>
          </div>

          {/* chains */}
          <div style={{
            marginTop: 24,
            border: "1px solid var(--line)", background: "var(--panel)",
            padding: 28,
          }}>
            <div style={{
              fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.22em",
              color: "var(--accent)", textTransform: "uppercase", marginBottom: 16,
            }}>
              Chains shipped on
            </div>
            <div style={{ display: "flex", flexWrap: "wrap", gap: 8 }}>
              {DATA.chains.map(c => (
                <span key={c} style={{
                  fontSize: 13, padding: "5px 11px",
                  border: "1px solid var(--line-2)", color: "var(--ink-dim)",
                  fontFamily: "var(--mono)",
                }}>
                  {c}
                </span>
              ))}
            </div>
          </div>

          {/* community & workshops */}
          <div style={{
            marginTop: 24,
            border: "1px solid var(--line)", background: "var(--panel)",
            padding: 28,
          }}>
            <div style={{
              fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.22em",
              color: "var(--accent)", textTransform: "uppercase", marginBottom: 14,
            }}>
              Community &amp; workshops
            </div>
            <p style={{ fontSize: 14, color: "var(--ink-dim)", lineHeight: 1.6, margin: "0 0 18px" }}>
              Led developer communities and ran hands-on workshops for chains and protocols across the ecosystem.
            </p>
            <div style={{ display: "flex", flexWrap: "wrap", gap: 8 }}>
              {DATA.communities.map(c => (
                <span key={c} style={{
                  fontSize: 13, padding: "5px 11px",
                  border: "1px solid var(--line-2)", color: "var(--ink-dim)",
                  fontFamily: "var(--mono)",
                }}>
                  {c}
                </span>
              ))}
            </div>
          </div>
        </div>
      </div>
    </Page>
  );
}

/* ---------- SPEAKING ---------- */
function SpeakingSection() {
  const [filter, setFilter] = React.useState("All");
  const kinds = ["All", ...Array.from(new Set(DATA.speaking.map(s => s.kind)))];
  const list = filter === "All" ? DATA.speaking : DATA.speaking.filter(s => s.kind === filter);

  return (
    <Page label="02 · Speaking" title="On Stage" kicker="Conferences, hackathons, and demo halls. Some highlights from the road.">
      <div style={{ display: "flex", gap: 6, marginBottom: 36, flexWrap: "wrap" }}>
        {kinds.map(k => {
          const active = filter === k;
          return (
            <button
              key={k}
              onClick={() => setFilter(k)}
              style={{
                fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.18em",
                textTransform: "uppercase",
                padding: "8px 14px",
                background: active ? "var(--accent)" : "transparent",
                color: active ? "#0a0a14" : "var(--ink-mute)",
                border: "1px solid " + (active ? "var(--accent)" : "var(--line-2)"),
                cursor: "pointer",
                transition: "all 180ms ease",
              }}
            >
              {k}
            </button>
          );
        })}
      </div>

      <div style={{
        display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(360px, 1fr))",
        gap: 24,
      }}>
        {list.map((t, i) => (
          <div key={i} style={{
            background: "var(--panel)",
            border: "1px solid var(--line)",
            overflow: "hidden",
            display: "flex", flexDirection: "column",
            transition: "transform 220ms ease, border-color 220ms ease",
          }}
          onMouseEnter={e => { e.currentTarget.style.transform = "translateY(-3px)"; e.currentTarget.style.borderColor = "var(--accent-line)"; }}
          onMouseLeave={e => { e.currentTarget.style.transform = "translateY(0)"; e.currentTarget.style.borderColor = "var(--line)"; }}
          >
            {t.photo
            ? <img src={t.photo.split("/").map(encodeURIComponent).join("/")} alt={t.where} style={{ width: "100%", aspectRatio: "16/10", objectFit: "cover", display: "block" }} />
            : <PlaceholderImage ratio="16/10" label={`${t.kind} · ${t.where}`} tone={i % 3 === 0 ? "accent" : "ink"} />
          }
            <div style={{ padding: 24 }}>
              <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 14 }}>
                <span style={{
                  fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.18em",
                  textTransform: "uppercase",
                  padding: "4px 10px", color: "var(--accent)",
                  background: "var(--accent-soft)",
                }}>
                  {t.kind}
                </span>
                <span style={{
                  fontFamily: "var(--mono)", fontSize: 11, color: "var(--ink-mute)",
                  letterSpacing: "0.1em",
                }}>
                  {t.when}
                </span>
              </div>
              <div style={{
                fontFamily: "var(--serif)", fontSize: 26, lineHeight: 1.2,
              }}>
                <span style={{ marginRight: 8 }}>{t.flag}</span>{t.where}
              </div>
            </div>
          </div>
        ))}
      </div>
    </Page>
  );
}

/* ---------- PROJECTS ---------- */
function ProjectsSection() {
  return (
    <Page label="03 · Selected work" title={<>Things I'm <span style={{ fontStyle: "italic", color: "var(--ink-dim)" }}>proud</span> of.</>} kicker="Protocols, SDKs, games and agents. The ones I'd show you first. Scroll, and they stack.">
      <div style={{ position: "relative" }}>
        {DATA.projects.map((p, i) => (
          <article
            key={p.name}
            style={{
              position: "sticky",
              top: 92 + i * 16,
              border: "1px solid var(--line)",
              background: "var(--panel)",
              marginBottom: 24,
              boxShadow: "0 -1px 40px -12px rgba(0,0,0,0.6)",
            }}
          >
            {/* corner ticks */}
            {["tl","tr","bl","br"].map(c => (
              <span key={c} style={{
                position: "absolute", width: 9, height: 9, zIndex: 2,
                borderColor: "var(--accent)", borderStyle: "solid", borderWidth: 0,
                top:    c[0] === "t" ? -1 : "auto",
                bottom: c[0] === "b" ? -1 : "auto",
                left:   c[1] === "l" ? -1 : "auto",
                right:  c[1] === "r" ? -1 : "auto",
                borderTopWidth:    c[0] === "t" ? 1 : 0,
                borderBottomWidth: c[0] === "b" ? 1 : 0,
                borderLeftWidth:   c[1] === "l" ? 1 : 0,
                borderRightWidth:  c[1] === "r" ? 1 : 0,
              }} />
            ))}

            <div className="proud-inner" style={{
              display: "grid", gridTemplateColumns: "minmax(0,1.05fr) minmax(0,1fr)",
              minHeight: 420,
            }}>
              {/* left: text */}
              <div style={{
                padding: 40,
                display: "flex", flexDirection: "column", justifyContent: "space-between", gap: 28,
              }}>
                <div>
                  <div style={{
                    fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.2em",
                    textTransform: "uppercase", color: "var(--ink-mute)",
                  }}>
                    00{i + 1} · {p.tag}
                  </div>
                  <h3 style={{
                    fontFamily: "var(--serif)", fontWeight: 500,
                    fontSize: "clamp(38px, 4vw, 60px)", lineHeight: 1.02,
                    letterSpacing: "-0.02em", margin: "14px 0 18px",
                  }}>
                    {p.name}
                  </h3>
                  <p style={{
                    fontFamily: "var(--serif)", fontStyle: "italic",
                    fontSize: 21, lineHeight: 1.4, color: "var(--ink-dim)",
                    margin: 0, maxWidth: 460,
                  }}>
                    {p.blurb}
                  </p>
                </div>

                <div>
                  <div style={{ display: "flex", gap: 8, flexWrap: "wrap", marginBottom: 22 }}>
                    {p.stack.map(s => (
                      <span key={s} style={{
                        fontFamily: "var(--mono)", fontSize: 11,
                        padding: "4px 10px",
                        border: "1px solid var(--line-2)", color: "var(--ink-dim)",
                      }}>
                        {s}
                      </span>
                    ))}
                  </div>
                  <div style={{
                    display: "flex", gap: 24, alignItems: "center", flexWrap: "wrap",
                    paddingTop: 20, borderTop: "1px dashed var(--line-2)",
                  }}>
                    <span style={{
                      fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.16em",
                      textTransform: "uppercase", color: "var(--ink-mute)",
                    }}>
                      {p.year}
                    </span>
                    {(p.live || p.link) && (
                      <a href={p.live || p.link} target="_blank" rel="noreferrer" style={{
                        fontFamily: "var(--mono)", fontSize: 12, letterSpacing: "0.18em",
                        textTransform: "uppercase", color: "var(--accent)",
                        paddingBottom: 4, borderBottom: "1px solid var(--accent-line)",
                      }}>
                        Live ↗
                      </a>
                    )}
                    {p.repo && (
                      <a href={p.repo} target="_blank" rel="noreferrer" style={{
                        fontFamily: "var(--mono)", fontSize: 12, letterSpacing: "0.18em",
                        textTransform: "uppercase", color: "var(--ink-dim)",
                        paddingBottom: 4, borderBottom: "1px solid var(--line-2)",
                      }}>
                        Source ↗
                      </a>
                    )}
                  </div>
                </div>
              </div>

              {/* right: visual */}
              <div style={{ position: "relative", borderLeft: "1px solid var(--line)", overflow: "hidden" }}>
                {p.photo === "npm" ? (
                  <div style={{
                    position: "absolute", inset: 0,
                    background: "#0f1116",
                    display: "grid", placeItems: "center",
                  }}>
                    <div style={{ textAlign: "center" }}>
                      <svg viewBox="0 0 780 250" width="220" xmlns="http://www.w3.org/2000/svg">
                        <path fill="#CB3837" d="M240 250V0h300v250h-75V75h-75v175z"/>
                        <path fill="#CB3837" d="M0 0h240v250H75V75H0zm540 0h240v175h-75V75h-75v100h75v75H540z"/>
                        <path fill="#fff" d="M75 75h90v100H75zM615 75h75v100h-75z"/>
                      </svg>
                      <div style={{
                        fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.22em",
                        textTransform: "uppercase", color: "var(--ink-mute)", marginTop: 20,
                      }}>
                        npm package
                      </div>
                    </div>
                  </div>
                ) : p.photo ? (
                  <div style={{
                    position: "absolute", inset: 0,
                    background: "#0a0c10",
                    display: "grid", placeItems: "center",
                    padding: 40,
                  }}>
                    <img
                      src={p.photo.split("/").map(encodeURIComponent).join("/")}
                      alt={p.name}
                      style={{ maxWidth: "100%", maxHeight: "100%", objectFit: "contain", display: "block" }}
                    />
                  </div>
                ) : (
                  <div style={{ position: "absolute", inset: 0 }}>
                    <PlaceholderImage ratio="auto" label={`${p.name} · screenshot`} tone={i % 2 === 0 ? "accent" : "ink"} fill />
                  </div>
                )}
              </div>
            </div>
          </article>
        ))}
      </div>

      <style>{`
        @media (max-width: 860px) {
          .proud-inner { grid-template-columns: 1fr !important; }
          .proud-inner > div:last-child { min-height: 240px; border-left: none !important; border-top: 1px solid var(--line); }
        }
      `}</style>
    </Page>
  );
}

/* ---------- GALLERY ---------- */
function GallerySection() {
  const [lightbox, setLightbox] = React.useState(null);
  const enc = (s) => s.split("/").map(encodeURIComponent).join("/");

  return (
    <Page label="04 · Gallery" title="In Frame" kicker="Stages, booths, builders, and the occasional 6am airport selfie.">

      {lightbox !== null && (
        <div
          style={{
            position: "fixed", inset: 0, zIndex: 999,
            background: "rgba(0,0,0,0.95)",
            display: "grid", placeItems: "center",
            backdropFilter: "blur(10px)",
          }}
          onClick={() => setLightbox(null)}
        >
          <img
            src={enc(DATA.gallery[lightbox].src)}
            alt={DATA.gallery[lightbox].label}
            style={{ maxWidth: "90vw", maxHeight: "88vh", objectFit: "contain", display: "block" }}
            onClick={e => e.stopPropagation()}
          />
          <div style={{
            position: "fixed", bottom: 32, left: "50%", transform: "translateX(-50%)",
            fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.18em",
            textTransform: "uppercase", color: "var(--ink-mute)",
            display: "flex", gap: 12, alignItems: "center",
          }}>
            <span>{DATA.gallery[lightbox].label}</span>
            {DATA.gallery[lightbox].city && <span style={{ color: "var(--accent)" }}>· {DATA.gallery[lightbox].city}</span>}
          </div>
          <button
            onClick={() => setLightbox(null)}
            style={{
              position: "fixed", top: 24, right: 28,
              background: "transparent", border: "1px solid var(--line-2)",
              color: "var(--ink-mute)", fontFamily: "var(--mono)",
              fontSize: 11, letterSpacing: "0.18em", textTransform: "uppercase",
              padding: "8px 16px", cursor: "pointer",
            }}
            onMouseEnter={e => { e.currentTarget.style.color = "var(--ink)"; e.currentTarget.style.borderColor = "var(--accent-line)"; }}
            onMouseLeave={e => { e.currentTarget.style.color = "var(--ink-mute)"; e.currentTarget.style.borderColor = "var(--line-2)"; }}
          >
            ✕ close
          </button>
        </div>
      )}

      <div style={{ columnCount: 4, columnGap: 12 }} className="gallery-cols">
        {DATA.gallery.map((photo, i) => (
          <div
            key={i}
            style={{ breakInside: "avoid", marginBottom: 12, cursor: "pointer", position: "relative" }}
            onClick={() => setLightbox(i)}
          >
            <div style={{ overflow: "hidden", position: "relative" }}>
              <img
                src={enc(photo.src)}
                alt={photo.label}
                loading="lazy"
                style={{ width: "100%", display: "block", transition: "transform 400ms ease" }}
                onMouseEnter={e => { e.currentTarget.style.transform = "scale(1.04)"; }}
                onMouseLeave={e => { e.currentTarget.style.transform = "scale(1)"; }}
              />
              <div className="g-overlay" style={{
                position: "absolute", inset: 0,
                background: "rgba(7,8,10,0)", transition: "background 250ms ease",
                display: "flex", flexDirection: "column", justifyContent: "flex-end",
                padding: "10px 12px", pointerEvents: "none",
              }}>
                <div className="g-label" style={{
                  fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.18em",
                  textTransform: "uppercase", color: "transparent", transition: "color 250ms ease",
                }}>
                  {photo.label}{photo.city ? ` · ${photo.city}` : ""}
                </div>
              </div>
            </div>
          </div>
        ))}
      </div>

      <style>{`
        @media (max-width: 1100px) { .gallery-cols { column-count: 3 !important; } }
        @media (max-width: 720px)  { .gallery-cols { column-count: 2 !important; } }
        .gallery-cols > div:hover .g-overlay { background: rgba(7,8,10,0.55) !important; }
        .gallery-cols > div:hover .g-label   { color: rgba(239,236,228,0.9) !important; }
      `}</style>
    </Page>
  );
}

/* ---------- WATCH ---------- */
function WatchSection() {
  const [playing, setPlaying] = React.useState(null);

  const featured = DATA.watch.find(v => v.featured);
  const rest = DATA.watch.filter(v => !v.featured);
  const ytThumb = (id) => `https://i.ytimg.com/vi/${id}/hqdefault.jpg`;

  const PlayBtn = ({ size = 52 }) => (
    <span style={{
      width: size, height: size, borderRadius: "50%",
      background: "var(--accent)", display: "grid", placeItems: "center",
      boxShadow: `0 0 ${size * 0.6}px oklch(0.66 0.18 275 / 0.45)`,
      transition: "transform 200ms ease",
      flexShrink: 0,
    }}
    onMouseEnter={e => e.currentTarget.style.transform = "scale(1.1)"}
    onMouseLeave={e => e.currentTarget.style.transform = "scale(1)"}
    >
      <svg width={size * 0.3} height={size * 0.35} viewBox="0 0 28 32" fill="#0a0a14">
        <path d="M2 2 L26 16 L2 30 Z" />
      </svg>
    </span>
  );

  return (
    <Page label="05 · Watch" title="Recordings" kicker="Talks, walkthroughs, recaps. The unedited reel.">

      {/* ── YouTube Modal ── */}
      {playing && (
        <div
          style={{
            position: "fixed", inset: 0, zIndex: 999,
            background: "rgba(0,0,0,0.93)",
            display: "grid", placeItems: "center",
            backdropFilter: "blur(10px)",
          }}
          onClick={() => setPlaying(null)}
        >
          <div
            style={{ position: "relative", width: "min(92vw, 1280px)", aspectRatio: "16/9" }}
            onClick={e => e.stopPropagation()}
          >
            <iframe
              src={(() => {
                const v = DATA.watch.find(w => w.ytId === playing);
                const start = v && v.startAt ? `&start=${v.startAt}` : "";
                return `https://www.youtube.com/embed/${playing}?autoplay=1&rel=0${start}`;
              })()}
              style={{ width: "100%", height: "100%", border: 0, display: "block" }}
              allow="autoplay; encrypted-media; fullscreen; picture-in-picture"
              allowFullScreen
            />
          </div>
          <button
            onClick={() => setPlaying(null)}
            style={{
              position: "fixed", top: 24, right: 28,
              background: "transparent",
              border: "1px solid var(--line-2)",
              color: "var(--ink-mute)", fontFamily: "var(--mono)",
              fontSize: 11, letterSpacing: "0.18em", textTransform: "uppercase",
              padding: "8px 16px", cursor: "pointer",
              transition: "color 150ms ease, border-color 150ms ease",
            }}
            onMouseEnter={e => { e.currentTarget.style.color = "var(--ink)"; e.currentTarget.style.borderColor = "var(--accent-line)"; }}
            onMouseLeave={e => { e.currentTarget.style.color = "var(--ink-mute)"; e.currentTarget.style.borderColor = "var(--line-2)"; }}
          >
            ✕ close
          </button>
        </div>
      )}

      {/* ── Featured ── */}
      {featured && (
        <div style={{ marginBottom: 64 }}>
          <div style={{ position: "relative", overflow: "hidden" }}>
            <div style={{ aspectRatio: "21/9", overflow: "hidden", position: "relative" }}>
              <img
                src={ytThumb(featured.ytId)}
                alt={featured.title}
                style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }}
              />
              <div style={{
                position: "absolute", inset: 0,
                background: "linear-gradient(to top, rgba(7,8,10,0.65) 0%, rgba(7,8,10,0.1) 55%, rgba(7,8,10,0.25) 100%)",
              }} />
            </div>
            <button
              onClick={() => setPlaying(featured.ytId)}
              aria-label="Play"
              style={{
                position: "absolute", inset: 0, display: "grid", placeItems: "center",
                background: "transparent", border: 0, cursor: "pointer",
              }}
            >
              <PlayBtn size={88} />
            </button>
          </div>
          <h2 style={{
            fontFamily: "var(--serif)", fontSize: "clamp(28px, 3vw, 44px)", lineHeight: 1.1,
            margin: "24px 0 10px", fontWeight: 500, maxWidth: 800,
          }}>
            {featured.title}
          </h2>
          <div style={{ display: "flex", alignItems: "center", gap: 14 }}>
            <span style={{
              fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.18em",
              textTransform: "uppercase", color: "var(--accent)",
              background: "var(--accent-soft)", padding: "3px 10px",
            }}>
              {featured.tag}
            </span>
            <span style={{
              fontFamily: "var(--mono)", fontSize: 11, color: "var(--ink-mute)",
              letterSpacing: "0.12em", textTransform: "uppercase",
            }}>
              {featured.where}
            </span>
          </div>
        </div>
      )}

      {/* ── Grid ── */}
      <div style={{
        display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(300px, 1fr))",
        gap: 28,
      }}>
        {rest.map((v, i) => (
          <div key={i}>
            {v.ytId ? (
              /* YouTube card */
              <div style={{ position: "relative" }}>
                <div style={{ aspectRatio: "16/9", overflow: "hidden", position: "relative" }}>
                  <img
                    src={ytThumb(v.ytId)}
                    alt={v.title}
                    style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }}
                  />
                  <div style={{
                    position: "absolute", inset: 0,
                    background: "rgba(7,8,10,0.28)",
                  }} />
                </div>
                <button
                  onClick={() => setPlaying(v.ytId)}
                  aria-label="Play"
                  style={{
                    position: "absolute", inset: 0, display: "grid", placeItems: "center",
                    background: "transparent", border: 0, cursor: "pointer",
                  }}
                >
                  <PlayBtn size={52} />
                </button>
              </div>
            ) : (
              /* X / tweet card */
              <a
                href={v.xUrl}
                target="_blank"
                rel="noreferrer"
                style={{
                  display: "grid", placeItems: "center",
                  aspectRatio: "16/9", position: "relative", overflow: "hidden",
                  background: "linear-gradient(135deg, #0f1116, #1a1f2e)",
                  border: "1px solid var(--line)",
                  textDecoration: "none",
                  transition: "border-color 200ms ease",
                }}
                onMouseEnter={e => e.currentTarget.style.borderColor = "var(--accent-line)"}
                onMouseLeave={e => e.currentTarget.style.borderColor = "var(--line)"}
              >
                <div style={{
                  position: "absolute", inset: 0,
                  backgroundImage: "repeating-linear-gradient(135deg, transparent 0 18px, rgba(255,255,255,0.016) 18px 19px)",
                }} />
                <div style={{ textAlign: "center", position: "relative", zIndex: 1 }}>
                  <div style={{ fontFamily: "var(--mono)", fontSize: 28, color: "var(--ink)", marginBottom: 10 }}>𝕏</div>
                  <div style={{
                    fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.22em",
                    color: "var(--ink-mute)", textTransform: "uppercase",
                  }}>
                    Watch on X →
                  </div>
                </div>
              </a>
            )}

            <div style={{
              fontFamily: "var(--serif)", fontSize: 20, lineHeight: 1.3,
              marginTop: 14, color: "var(--ink)",
            }}>
              {v.title}
            </div>
            <div style={{ display: "flex", alignItems: "center", gap: 10, marginTop: 7, flexWrap: "wrap" }}>
              {v.tag && (
                <span style={{
                  fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.16em",
                  textTransform: "uppercase", color: "var(--accent)",
                  background: "var(--accent-soft)", padding: "2px 8px",
                }}>
                  {v.tag}
                </span>
              )}
              <span style={{
                fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.1em",
                color: "var(--ink-mute)", textTransform: "uppercase",
              }}>
                {v.where}
              </span>
            </div>
          </div>
        ))}
      </div>
    </Page>
  );
}

/* ---------- BUZZ ---------- */
function BuzzCard({ b }) {
  return (
    <a
      href={b.url}
      target="_blank"
      rel="noopener noreferrer"
      style={{
        display: "block",
        width: 260,
        flexShrink: 0,
        background: "var(--panel)",
        border: "1px solid var(--line)",
        borderRadius: 4,
        padding: "14px 16px",
        textDecoration: "none",
        transition: "border-color 200ms ease, background 200ms ease",
      }}
      onMouseEnter={e => { e.currentTarget.style.borderColor = "var(--line-2)"; e.currentTarget.style.background = "var(--panel-2)"; }}
      onMouseLeave={e => { e.currentTarget.style.borderColor = "var(--line)"; e.currentTarget.style.background = "var(--panel)"; }}
    >
      {/* header row */}
      <div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 10 }}>
        <div style={{
          width: 28, height: 28, borderRadius: "50%",
          overflow: "hidden", flexShrink: 0,
          background: "var(--bg-2)",
          position: "relative",
        }}>
          <img
            src={`https://unavatar.io/twitter/${b.handle}`}
            alt={b.who}
            style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }}
            onError={e => { e.target.style.display = "none"; }}
          />
        </div>
        <span style={{
          fontWeight: 600, fontSize: 12,
          color: "var(--ink)", flex: 1, minWidth: 0,
          overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap",
        }}>
          {b.who}
        </span>
        {b.verified && (
          <svg width="15" height="15" viewBox="0 0 22 22" fill="none" style={{ flexShrink: 0 }}>
            <circle cx="11" cy="11" r="11" fill="#1D9BF0" />
            <path d="M9.5 14.25L6.75 11.5L7.8125 10.4375L9.5 12.125L14.1875 7.4375L15.25 8.5L9.5 14.25Z" fill="white" />
          </svg>
        )}
        {/* X logo */}
        <svg width="13" height="13" viewBox="0 0 24 24" fill="var(--ink-mute)" style={{ flexShrink: 0 }}>
          <path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/>
        </svg>
      </div>
      {/* body */}
      <p style={{
        margin: 0,
        fontSize: 12, lineHeight: 1.55,
        color: "var(--ink-dim)",
        display: "-webkit-box",
        WebkitLineClamp: 4,
        WebkitBoxOrient: "vertical",
        overflow: "hidden",
      }}>
        {b.body}
      </p>
      {/* date */}
      <div style={{
        marginTop: 10,
        fontFamily: "var(--mono)", fontSize: 10,
        color: "var(--ink-mute)", letterSpacing: "0.1em",
      }}>
        {b.when}
      </div>
    </a>
  );
}

function BuzzRow({ items, direction = "left", speed = "35s" }) {
  const doubled = [...items, ...items];
  const anim = direction === "left" ? "buzz-scroll-left" : "buzz-scroll-right";
  return (
    <div style={{ overflow: "hidden" }}>
      <div
        className={`buzz-row-inner buzz-row-${direction}`}
        style={{
          display: "flex",
          gap: 12,
          width: "max-content",
          animation: `${anim} ${speed} linear infinite`,
        }}
        onMouseEnter={e => { e.currentTarget.style.animationPlayState = "paused"; }}
        onMouseLeave={e => { e.currentTarget.style.animationPlayState = "running"; }}
      >
        {doubled.map((b, i) => <BuzzCard key={i} b={b} />)}
      </div>
    </div>
  );
}

function BuzzSection() {
  const rows = [
    DATA.buzz.slice(0, 4),
    DATA.buzz.slice(4, 8),
    DATA.buzz.slice(8, 12),
  ];
  return (
    <Page label="06 · Buzz" title="In the Wild" kicker="What the community is saying. Or shouting.">
      <div style={{ display: "flex", flexDirection: "column", gap: 12, margin: "0 -32px" }}>
        <BuzzRow items={rows[0]} direction="left"  speed="40s" />
        <BuzzRow items={rows[1]} direction="right" speed="48s" />
        <BuzzRow items={rows[2]} direction="left"  speed="36s" />
      </div>
      <style>{`
        @keyframes buzz-scroll-left {
          from { transform: translateX(0); }
          to   { transform: translateX(-50%); }
        }
        @keyframes buzz-scroll-right {
          from { transform: translateX(-50%); }
          to   { transform: translateX(0); }
        }
        @media (prefers-reduced-motion: reduce) {
          .buzz-row-inner { animation: none !important; }
        }
      `}</style>
    </Page>
  );
}

/* ---------- CONTACT ---------- */
function ContactSection() {
  const iconFor = (id) => {
    switch (id) {
      case "x":        return "𝕏";
      case "linkedin": return "in";
      case "github":   return "⌥";
      case "youtube":  return "▶";
      case "hashnode": return "#";
      case "mail":     return "✉";
      default:         return "·";
    }
  };
  return (
    <Page label="07 · Contact" title="Say hi" kicker="Hackathons, talks, partnerships, or just a hello.">
      <div style={{
        display: "grid", gridTemplateColumns: "minmax(0, 1fr) minmax(0, 1fr)", gap: 80,
      }}>
        <div>
          <a href={`mailto:${DATA.email}`} style={{
            display: "inline-flex", alignItems: "center", gap: 14,
            background: "var(--accent)", color: "#0a0a14",
            padding: "20px 28px",
            fontFamily: "var(--mono)", fontSize: 14, letterSpacing: "0.14em",
            textTransform: "lowercase",
            transition: "transform 180ms ease",
          }}
          onMouseEnter={e => e.currentTarget.style.transform = "translateY(-2px)"}
          onMouseLeave={e => e.currentTarget.style.transform = "translateY(0)"}
          >
            <span style={{ fontSize: 18 }}>✉</span>
            {DATA.email}
          </a>

          <div style={{ marginTop: 56 }}>
            <div style={{
              fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.22em",
              color: "var(--accent)", textTransform: "uppercase", marginBottom: 16,
            }}>
              Find me elsewhere
            </div>
            <div style={{ display: "grid", gridTemplateColumns: "repeat(2, 1fr)", gap: 12 }}>
              {DATA.socials.filter(s => s.id !== "mail").map(s => (
                <a key={s.id} href={s.href} target="_blank" rel="noreferrer" style={{
                  border: "1px solid var(--line)",
                  background: "var(--panel)",
                  padding: "14px 18px",
                  display: "flex", alignItems: "center", gap: 14,
                  color: "var(--ink-dim)",
                  transition: "border-color 180ms ease, color 180ms ease",
                }}
                onMouseEnter={e => { e.currentTarget.style.borderColor = "var(--accent-line)"; e.currentTarget.style.color = "var(--ink)"; }}
                onMouseLeave={e => { e.currentTarget.style.borderColor = "var(--line)"; e.currentTarget.style.color = "var(--ink-dim)"; }}
                >
                  <span style={{
                    width: 28, height: 28, display: "grid", placeItems: "center",
                    border: "1px solid var(--line-2)",
                    fontFamily: "var(--mono)", fontSize: 13,
                    color: "var(--accent)",
                  }}>
                    {iconFor(s.id)}
                  </span>
                  <div style={{ minWidth: 0 }}>
                    <div style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--ink-mute)" }}>
                      {s.id}
                    </div>
                    <div style={{ fontSize: 13, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }}>
                      {s.label}
                    </div>
                  </div>
                </a>
              ))}
            </div>
          </div>
        </div>

        <div style={{
          border: "1px solid var(--line)",
          background: "var(--panel)",
          padding: 32,
          alignSelf: "start",
        }}>
          <div style={{
            fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.22em",
            color: "var(--accent)", textTransform: "uppercase", marginBottom: 16,
          }}>
            Booking notes
          </div>
          <p style={{
            fontFamily: "var(--serif)", fontStyle: "italic", fontSize: 22,
            lineHeight: 1.4, color: "var(--ink)", margin: "0 0 24px",
          }}>
            "Best at the intersection of devs, docs, and demos."
          </p>
          <ul style={{ margin: 0, padding: 0, listStyle: "none", display: "flex", flexDirection: "column", gap: 14 }}>
            {[
              ["Talks", "Keynotes, fireside chats, panels on onchain AI, DevRel, tooling."],
              ["Workshops", "1-3hr hands-on. Brings the codebase, leaves the stickers."],
              ["Consulting", "DevRel strategy, docs audits, hackathon programs."],
              ["Travel", "Open to US, APAC, EU, MENA, LATAM. Has visa, will travel."],
            ].map(([k, v]) => (
              <li key={k}>
                <div style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.18em", textTransform: "uppercase", color: "var(--ink-mute)", marginBottom: 4 }}>
                  {k}
                </div>
                <div style={{ fontSize: 14, color: "var(--ink-dim)", lineHeight: 1.55 }}>
                  {v}
                </div>
              </li>
            ))}
          </ul>
        </div>
      </div>
    </Page>
  );
}

Object.assign(window, {
  HomeSection, AboutSection, SpeakingSection, ProjectsSection,
  GallerySection, WatchSection, BuzzSection, ContactSection,
});
