/* Shared data + small utilities for all variations */

const BIO_SHORT =
  "Assistant Research Scientist, Department of Physics & Astronomy, Johns Hopkins University.";

const BIO_LONG = [
  "I study the atmospheres of transiting exoplanets with space telescopes such as JWST and Hubble. My current research focuses on population-level studies of exoplanet atmospheres, understanding atmospheric trends across the exoplanet population. I am also interested in the search for exomoons and Earth-like planets in the habitable zone.",
  "My current focus is population-level: not single-planet case studies, but the trends that emerge across the JWST sample.",
  "PI of multiple HST programs; Co-PI of a 182.5-hour JWST Cycle 5 program. Published in Nature, Nature Astronomy, Science, and the major astrophysical journals. Ph.D. University of Maryland, 2022 (advisor: Drake Deming). Previously Exoplanet Science Fellow at STScI (2022–2025)."
];

const RESEARCH = [
  {
    n: "01",
    year: "2026",
    tag: "Submitted · 2026",
    title: "JWST color sequence of transiting exoplanets and directly imaged substellar objects",
    body: "Placing transiting exoplanets and directly-imaged substellar objects on a single color–magnitude sequence with JWST: a unified framework for interpreting atmospheres across mass, age, and irradiation.",
    fig: "assets/color_sequence.png",
    cap: "Fu, Lothringer, Mukherjee, et al., Submitted, 2026.",
    href: "uploads/JWST_color_sequence_of_transiting_exoplanets_and_directly_imaged_substellar_objects.pdf"
  },
  {
    n: "02",
    year: "2025",
    tag: "ApJL · 2025",
    title: "Overcast mornings and clear evenings in hot Jupiter atmospheres",
    body: "The first population-level evidence for diurnal cloud cycling on hot Jupiters, systematically overcast mornings and clear evenings, from JWST NIRISS/SOSS limb asymmetries across nine planets.",
    fig: "assets/fig_overcast.png",
    cap: "Fu, Mukherjee, Stevenson, Sing, et al., ApJL, 2025.",
    href: "https://iopscience.iop.org/article/10.3847/2041-8213/adf20f"
  },
  {
    n: "03",
    year: "2025",
    tag: "ApJ · 2025",
    title: "Statistical trends in JWST transiting exoplanet atmospheres",
    body: "Eight JWST transmission spectra, normalized by scale height and overlaid, letting L-band, SO₂, CO₂, and CO features be read as a population rather than single-planet anecdotes.",
    fig: "assets/fig_statistical_trends.png",
    cap: "Fu, Stevenson, Sing, et al., ApJ, 2025.",
    href: "https://iopscience.iop.org/article/10.3847/1538-4357/ad7bb8"
  },
  {
    n: "04",
    year: "2024",
    tag: "Nature · 2024",
    title: "Hydrogen sulfide and metal-enriched atmosphere for a Jupiter-mass exoplanet",
    body: "First detection of H₂S in an exoplanet atmosphere. JWST NIRCam transmission of HD 189733b reveals metal-enrichment, CO₂, H₂O, and sulfur chemistry from a single spectrum.",
    fig: "assets/fig_h2s.png",
    cap: "Fu, Welbanks, Deming, et al., Nature, 2024.",
    href: "https://www.nature.com/articles/s41586-024-07760-y"
  },
  {
    n: "05",
    year: "2023",
    tag: "Nat. Astronomy · 2023",
    title: "A JWST transmission spectrum of a nearby Earth-sized exoplanet",
    body: "Pushing transmission spectroscopy to terrestrial worlds: JWST NIRSpec G395H rules out thick clear atmospheres on LHS 475 b, constraining models from 1× to 1000× solar metallicity.",
    fig: "assets/fig_earth_sized.png",
    cap: "Lustig-Yaeger*, Fu*, May, et al., Nature Astronomy, 2023.",
    href: "https://www.nature.com/articles/s41550-023-02064-z"
  }
];

const SELECTED = [
  { year: "2026", venue: "Submitted", title: "JWST color sequence of transiting exoplanets and directly imaged substellar objects", authors: "Fu, Lothringer, Mukherjee, et al.", href: "#" },
  { year: "2025", venue: "ApJL", title: "Overcast mornings and clear evenings in hot Jupiter exoplanet atmospheres", authors: "Fu, Mukherjee, Stevenson, Sing, et al.", href: "https://iopscience.iop.org/article/10.3847/2041-8213/adf20f" },
  { year: "2025", venue: "ApJ", title: "Statistical trends in JWST transiting exoplanet atmospheres", authors: "Fu, Stevenson, Sing, et al.", href: "https://iopscience.iop.org/article/10.3847/1538-4357/ad7bb8" },
  { year: "2024", venue: "Nature", title: "Hydrogen sulfide and metal-enriched atmosphere for a Jupiter-mass exoplanet", authors: "Fu, Welbanks, Deming, et al.", href: "https://www.nature.com/articles/s41586-024-07760-y" },
  { year: "2023", venue: "Nat. Astron.", title: "A JWST transmission spectrum of a nearby Earth-sized exoplanet", authors: "Lustig-Yaeger*, Fu*, May, et al.", href: "https://www.nature.com/articles/s41550-023-02064-z" },
  { year: "2022", venue: "ApJL", title: "Water and an escaping helium tail in the hazy, methane-depleted atmosphere of HAT-P-18b", authors: "Fu, Espinoza, Sing, et al.", href: "https://iopscience.iop.org/article/10.3847/2041-8213/ac9977" },
  { year: "2022", venue: "ApJL", title: "Strong H₂O and CO emission features in KELT-20b driven by stellar UV irradiation", authors: "Fu, Sing, Lothringer, et al.", href: "https://iopscience.iop.org/article/10.3847/2041-8213/ac4968" },
  { year: "2022", venue: "AJ", title: "The Hubble PanCET program: emission spectrum of hot Jupiter HAT-P-41b", authors: "Fu, Sing, Deming, et al.", href: "https://iopscience.iop.org/article/10.3847/1538-3881/ac58fc" },
  { year: "2021", venue: "AJ", title: "The Hubble PanCET program: transit and eclipse spectroscopy of WASP-76b", authors: "Fu, Deming, Lothringer, et al.", href: "https://iopscience.iop.org/article/10.3847/1538-3881/ac1200" },
  { year: "2017", venue: "ApJL", title: "Statistical analysis of Hubble/WFC3 transit spectroscopy of extrasolar planets", authors: "Fu, Deming, Knutson, Madhusudhan, et al.", href: "https://iopscience.iop.org/article/10.3847/2041-8213/aa8e40" }
];

const COAUTHORED = [
  { year: "2026", venue: "Science", title: "Cloudy mornings and clear evenings on a giant extrasolar world", authors: "Mukherjee, Sing, Fu, et al." },
  { year: "2025", venue: "ApJL", title: "TOI-421 b: a hot sub-Neptune with a haze-free, low mean molecular weight atmosphere", authors: "Davenport, Kempton, Nixon, Ih, Deming, Fu, et al." },
  { year: "2024", venue: "AJ", title: "A fourth planet in the Kepler-51 system revealed by transit timing variations", authors: "Kento, Libby-Roberts, Fu, et al." },
  { year: "2024", venue: "PASP", title: "Toward exoplanet transit spectroscopy using JWST/MIRI's medium resolution spectrometer", authors: "Deming, Fu, Bouwman, et al." },
  { year: "2024", venue: "AJ", title: "JWST/NIRCam transmission spectroscopy of the nearby sub-Earth GJ 341b", authors: "Kirk, Stevenson, Fu, et al." },
  { year: "2024", venue: "AJ", title: "Precise radial velocities using line bisectors", authors: "Deming, Llama, Fu, et al." },
  { year: "2023", venue: "ApJL", title: "Double trouble: two transits of the super-Earth GJ 1132 b observed with JWST NIRSpec G395H", authors: "May, MacDonald, Bennett, Fu, et al." },
  { year: "2023", venue: "ApJL", title: "High tide or riptide on the cosmic shoreline? A water-rich atmosphere or stellar contamination for the warm super-Earth GJ 486b from JWST", authors: "Moran, Stevenson, Sing, Fu, et al." },
  { year: "2023", venue: "Nature", title: "A reflective, metal-rich atmosphere for GJ 1214b from its JWST phase curve", authors: "Kempton, Zhang, Bean, Fu, et al." },
  { year: "2023", venue: "AJ", title: "Emergent spectral fluxes of hot Jupiters: an abrupt rise in day side brightness temperature under strong irradiation", authors: "Deming, Line, Knutson, Fu, et al." },
  { year: "2023", venue: "AJ", title: "Unifying high- and low-resolution observations to constrain the dayside atmosphere of KELT-20b/MASCARA-2b", authors: "Kasper, Bean, Line, Fu, et al." },
  { year: "2022", venue: "Nature", title: "Identification of carbon dioxide in an exoplanet atmosphere", authors: "JWST Transiting Exoplanet ERS Team incl. Fu" },
  { year: "2022", venue: "AJ", title: "The Hubble PanCET program: a featureless transmission spectrum for WASP-29b and evidence of enhanced atmospheric metallicity on WASP-80b", authors: "Wong, Chachan, Knutson, Fu, et al." },
  { year: "2020", venue: "ApJL", title: "UV exoplanet transmission spectral features as probes of metals and rainout", authors: "Lothringer, Fu, Sing, Barman" },
  { year: "2018", venue: "ApJ", title: "Near-infrared high-resolution imaging polarimetry of FU Ori-type objects: toward a unified scheme for low-mass protostellar evolution", authors: "Takami, Fu, Liu, Karr, Hashimoto, et al." }
];

const FACTS = [
  { k: "First-author papers", v: "12" },
  { k: "Total publications", v: "28+" },
  { k: "HST programs (PI)", v: "multiple" },
  { k: "JWST Cy 5 (Co-PI)", v: "182.5 hr" }
];

const NAV = ["about", "research", "publications", "cv", "contact"];

/* ----- Shared: star-transit animation ----- */
/* Star on the left, planet drifts across. Flux dips when planet transits. */

function TransitAnimation({ starColor = "#f6c478", planetColor = "#1a1a1a", bg = "transparent", lineColor = "#1a1a1a", mutedColor = "#9a938a", label = true, height = 260, fontFamily = "inherit" }) {
  const W = 680, H = height;
  const cxStar = 180, cyStar = H * 0.5, rStar = 46;
  const [t, setT] = React.useState(0);
  React.useEffect(() => {
    let raf, start;
    const tick = (ts) => {
      if (!start) start = ts;
      setT(((ts - start) / 6000) % 1);
      raf = requestAnimationFrame(tick);
    };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, []);

  // Planet travels from cxStar - 120 to cxStar + 120 horizontally, looping
  const x = cxStar - 140 + t * 280;
  const planetR = 14;
  // distance from center of star
  const d = Math.abs(x - cxStar);
  // transit depth model: smooth ingress/egress
  let depth = 0;
  if (d < rStar + planetR) {
    if (d < rStar - planetR) depth = 1;
    else depth = 1 - (d - (rStar - planetR)) / (2 * planetR);
  }
  const dip = depth * 0.16;

  // Build lightcurve path across time [0,1]
  const N = 160;
  const pts = [];
  for (let i = 0; i < N; i++) {
    const tt = i / (N - 1);
    const xi = cxStar - 140 + tt * 280;
    const di = Math.abs(xi - cxStar);
    let de = 0;
    if (di < rStar + planetR) {
      if (di < rStar - planetR) de = 1;
      else de = 1 - (di - (rStar - planetR)) / (2 * planetR);
    }
    const flux = 1 - de * 0.16;
    const px = 360 + tt * (W - 400);
    const py = 60 + (1 - flux) * 540; // dramatic for visibility
    pts.push([px, py]);
  }
  const path = pts.map((p, i) => (i === 0 ? "M" : "L") + p[0].toFixed(1) + " " + p[1].toFixed(1)).join(" ");

  // Cursor on lightcurve at current t
  const cIdx = Math.round(t * (N - 1));
  const cursor = pts[cIdx];

  return (
    <svg viewBox={`0 0 ${W} ${H}`} width="100%" height={H} style={{ display: "block", background: bg, overflow: "visible", fontFamily }}>
      <defs>
        <radialGradient id="starGrad" cx="0.5" cy="0.5" r="0.5">
          <stop offset="0%" stopColor={starColor} stopOpacity="1" />
          <stop offset="65%" stopColor={starColor} stopOpacity="0.95" />
          <stop offset="100%" stopColor={starColor} stopOpacity="0" />
        </radialGradient>
        <clipPath id="starClip">
          <circle cx={cxStar} cy={cyStar} r={rStar} />
        </clipPath>
      </defs>

      {/* star halo */}
      <circle cx={cxStar} cy={cyStar} r={rStar * 1.8} fill="url(#starGrad)" opacity="0.35" />
      {/* star body */}
      <circle cx={cxStar} cy={cyStar} r={rStar} fill={starColor} />
      {/* subtle limb darkening */}
      <circle cx={cxStar} cy={cyStar} r={rStar} fill={starColor} opacity="0.6" />
      <circle cx={cxStar} cy={cyStar} r={rStar} stroke="rgba(0,0,0,0.08)" strokeWidth="1" fill="none" />

      {/* planet orbit guideline */}
      <line x1={cxStar - 140} y1={cyStar} x2={cxStar + 140} y2={cyStar} stroke={mutedColor} strokeWidth="0.5" strokeDasharray="2 4" opacity="0.5" />

      {/* planet - in front when transiting (over star) */}
      <circle cx={x} cy={cyStar} r={planetR} fill={planetColor} />

      {/* Lightcurve plot */}
      <g transform={`translate(360, ${cyStar - 78})`}>
        {/* frame */}
        <line x1={0} y1={0} x2={0} y2={160} stroke={mutedColor} strokeWidth="0.75" />
        <line x1={0} y1={160} x2={W - 400} y2={160} stroke={mutedColor} strokeWidth="0.75" />
        {label && (
          <>
            <text x={-6} y={6} textAnchor="end" fontSize="10" fill={mutedColor} style={{ letterSpacing: "0.06em", textTransform: "uppercase" }}>flux</text>
            <text x={W - 400} y={175} textAnchor="end" fontSize="10" fill={mutedColor} style={{ letterSpacing: "0.06em", textTransform: "uppercase" }}>time →</text>
          </>
        )}
      </g>
      <path d={path} transform={`translate(0, ${cyStar - 78 - 60})`} fill="none" stroke={lineColor} strokeWidth="1.25" />
      {cursor && (
        <circle cx={cursor[0]} cy={cursor[1] + (cyStar - 78 - 60)} r="3" fill={lineColor} />
      )}

      {/* depth readout */}
      <g transform={`translate(${W - 10}, ${cyStar - 94})`}>
        <text textAnchor="end" fontSize="10" fill={mutedColor} style={{ letterSpacing: "0.1em", textTransform: "uppercase" }}>transit depth</text>
        <text textAnchor="end" y="18" fontSize="18" fill={lineColor} style={{ fontVariantNumeric: "tabular-nums" }}>{(dip * 100).toFixed(2)}%</text>
      </g>
    </svg>
  );
}

/* Expose to other Babel scripts */
Object.assign(window, {
  BIO_SHORT, BIO_LONG, RESEARCH, SELECTED, COAUTHORED, FACTS, NAV,
  TransitAnimation
});
