// ─────────────────────────────────────────────────────────────────────────
// Variant E — Refined (lead option)
// Strong "who I am" hero emphasising current roles.
// Project cards with screenshot placeholders + click-to-open detail modal.
// Inherits Terminal's content density but in a clean, modern shell.
// ─────────────────────────────────────────────────────────────────────────

const RF = {
  bg: "#f5f3ed",
  panel: "#ffffff",
  panelSoft: "#fafaf6",
  ink: "#15151a",
  ink2: "#3a3a40",
  muted: "#7a7a82",
  rule: "#e6e3da",
  ruleSoft: "#efece4",
  accent: "#2b56d4",       // confident blue — not too cobalt, not too cliche
  accentSoft: "#e1e8fa",
  accentText: "#1f3fa6",
  sans: "'Geist', 'Inter Tight', system-ui, -apple-system, sans-serif",
  mono: "'Geist Mono', 'JetBrains Mono', ui-monospace, monospace",
};

const rfStyle = document.createElement("style");
rfStyle.id = "refined-styles";
rfStyle.textContent = `
  .rf-root *{box-sizing:border-box}
  .rf-root{background:${RF.bg};color:${RF.ink};font-family:${RF.sans};font-size:15px;line-height:1.55;letter-spacing:-0.005em;width:100%;height:100%;overflow:hidden;position:relative}
  .rf-root a{color:inherit;text-decoration:none}
  .rf-root .mono{font-family:${RF.mono};font-size:11px;letter-spacing:0.04em;text-transform:uppercase;color:${RF.muted};font-weight:500}
  .rf-root .dim{color:${RF.muted}}
  .rf-root .acc{color:${RF.accent}}
  .rf-root .display{font-family:${RF.sans};font-weight:600;letter-spacing:-0.035em;line-height:0.98}
  .rf-root .title{font-family:${RF.sans};font-weight:600;letter-spacing:-0.025em;line-height:1.1}

  .rf-card{background:${RF.panel};border:1px solid ${RF.rule};border-radius:18px;transition:border-color .2s, transform .2s, box-shadow .2s}
  .rf-card.hov:hover{border-color:#cfcabc;transform:translateY(-3px);box-shadow:0 14px 30px -18px rgba(0,0,0,.16)}

  .rf-pill{display:inline-flex;align-items:center;padding:4px 10px;border:1px solid ${RF.rule};border-radius:999px;font-size:12px;color:${RF.ink2};background:${RF.panel};font-weight:500}
  .rf-pill.acc{border-color:${RF.accent};color:${RF.accent};background:${RF.accentSoft}}
  .rf-tag{display:inline-flex;align-items:center;padding:3px 9px;border-radius:6px;font-size:10.5px;font-family:${RF.mono};letter-spacing:.04em;text-transform:uppercase;background:${RF.panelSoft};color:${RF.ink2};border:1px solid ${RF.rule};font-weight:500}

  .rf-root .rf-cv{display:inline-flex;align-items:center;gap:8px;padding:11px 18px;background:${RF.ink};color:${RF.bg};border-radius:999px;font-size:14.5px;font-weight:500;transition:background .15s, transform .15s}
  .rf-root .rf-cv:hover{background:${RF.accent};color:${RF.bg};transform:translateY(-1px)}

  /* Centered max-width container so content doesn't sprawl on wide monitors */
  .rf-pad{max-width:1240px;margin-left:auto;margin-right:auto;width:100%}

  .rf-link{position:relative}
  .rf-link::after{content:"";position:absolute;left:0;right:0;bottom:-2px;height:1px;background:currentColor;opacity:.3;transition:opacity .15s, background .15s}
  .rf-link:hover{color:${RF.accent}}
  .rf-link:hover::after{opacity:1;background:${RF.accent}}

  .rf-nav-link{padding:6px 4px;font-size:15.5px;color:${RF.ink2};font-weight:500;transition:color .15s}
  .rf-nav-link:hover{color:${RF.accent}}

  .rf-status{display:inline-flex;align-items:center;gap:8px;padding:5px 12px 5px 8px;background:${RF.panel};border:1px solid ${RF.rule};border-radius:999px;font-size:12px;font-weight:500;color:${RF.ink2}}
  .rf-status .dot{width:7px;height:7px;border-radius:50%;background:${RF.accent};box-shadow:0 0 0 4px ${RF.accentSoft};animation:rfpulse 2.6s ease-in-out infinite}
  @keyframes rfpulse{0%,100%{box-shadow:0 0 0 3px ${RF.accentSoft}}50%{box-shadow:0 0 0 6px ${RF.accentSoft}}}

  /* hero contact / social row */
  .rf-social{display:inline-flex;align-items:center;gap:8px;padding:8px 14px 8px 12px;border:1px solid ${RF.rule};border-radius:999px;font-size:13px;font-weight:500;color:${RF.ink2};background:${RF.panel};transition:border-color .15s, color .15s, transform .15s}
  .rf-social:hover{border-color:${RF.accent};color:${RF.accent};transform:translateY(-1px)}
  .rf-social svg{flex:none}
  .rf-cv-short{display:none}

  .rf-photo{background:${RF.accentSoft};border-radius:18px;
    background-image:repeating-linear-gradient(135deg,transparent 0 16px,rgba(43,86,212,.12) 16px 17px);
    display:flex;align-items:flex-end;padding:18px;color:${RF.accentText};font-family:${RF.mono};font-size:10.5px;text-transform:uppercase;letter-spacing:.1em}

  /* image-slot inside our cards — strip its border, fit the parent */
  .rf-root image-slot{display:block;width:100%;height:100%;--is-radius:0;--is-border:none}
  .rf-portrait-slot{aspect-ratio:4/5;border-radius:18px;overflow:hidden;border:1px solid ${RF.rule};background:${RF.accentSoft}}
  .rf-portrait-slot image-slot{--is-radius:0}

  /* PROJECT CARDS */
  .rf-proj{display:flex;flex-direction:column;cursor:pointer;overflow:hidden}
  .rf-proj .thumb{aspect-ratio:16/9;background:${RF.panelSoft};border-bottom:1px solid ${RF.rule};position:relative;overflow:hidden;
    background-image:linear-gradient(135deg,${RF.accentSoft} 0%, ${RF.panelSoft} 100%);
    display:flex;align-items:center;justify-content:center;color:${RF.accent};font-family:${RF.mono};font-size:11px;letter-spacing:.08em;text-transform:uppercase;font-weight:500}
  .rf-proj .thumb::after{content:"";position:absolute;inset:0;background:radial-gradient(circle at 30% 20%, rgba(255,255,255,.5) 0%, transparent 50%);pointer-events:none}
  .rf-proj .thumb svg{position:relative;z-index:1}
  .rf-proj .body{padding:18px 20px;display:flex;flex-direction:column;gap:8px;flex:1}
  .rf-proj .arrow{display:inline-flex;width:30px;height:30px;align-items:center;justify-content:center;border-radius:999px;background:${RF.panelSoft};color:${RF.ink};transition:transform .2s, background .2s, color .2s;font-size:13px;border:1px solid ${RF.rule}}
  .rf-proj:hover .arrow{background:${RF.accent};color:#fff;transform:translate(3px,-3px);border-color:${RF.accent}}

  /* ── RESPONSIVE GRID CLASSES ── */
  .rf-hero-grid{display:grid;grid-template-columns:1.8fr 1fr;gap:56px;align-items:start}
  .rf-roles-grid{display:grid;grid-template-columns:repeat(auto-fit, minmax(250px, 1fr));gap:16px}
  .rf-work-grid{display:grid;grid-template-columns:repeat(6,1fr);gap:20px}
  .rf-toolkit-grid{display:grid;grid-template-columns:1.4fr 1fr;gap:64px}
  .rf-contact-grid{display:grid;grid-template-columns:1.4fr 1fr;gap:56px;align-items:end}
  .rf-about-grid{display:grid;grid-template-columns:1.5fr 1fr;gap:40px;align-items:start}

  /* Heading with a hairline rule under it — referenced from Arda's About */
  .rf-headrule{border:0;height:1px;background:${RF.rule};margin:18px 0 28px}

  /* De-carded list styles — experience & toolkit read as clean text, not boxes */
  .rf-exprow{padding:22px 0;border-top:1px solid ${RF.rule}}
  .rf-exprow:first-child{border-top:0;padding-top:4px}
  .rf-exprow-head{display:flex;justify-content:space-between;gap:16px;align-items:baseline;flex-wrap:wrap}
  .rf-exptag{font-size:11px;font-weight:600;letter-spacing:.02em;padding:2px 9px;border-radius:999px;border:1px solid ${RF.rule};color:${RF.muted};background:${RF.panelSoft};white-space:nowrap}
  .rf-exptag.now{color:${RF.accent};border-color:${RF.accent};background:${RF.accentSoft}}
  .rf-divider{border:0;height:1px;background:${RF.rule};margin:26px 0}

  /* Honours — one emphasized tinted panel (the only non-project box) */
  .rf-honours{background:${RF.accentSoft};border:1px solid #cdd8f5;border-radius:16px;padding:24px 26px}
  .rf-honours .rf-aw{display:flex;gap:12px;padding:9px 0;border-top:1px solid rgba(31,63,166,.13);align-items:baseline}
  .rf-honours .rf-aw:first-of-type{border-top:0;padding-top:2px}

  /* Tablet */
  @media (max-width: 980px){
    .rf-work-grid{grid-template-columns:repeat(2,1fr)}
    .rf-work-grid > article{grid-column:span 1 !important}
  }

  /* Phone */
  @media (max-width: 680px){
    .rf-pad{padding-left:20px !important;padding-right:20px !important}
    .rf-hero-grid{grid-template-columns:1fr;gap:28px}
    .rf-hero-media{order:-1;align-items:center !important;width:100%}
    .rf-hero-media .rf-portrait-slot{width:190px !important}
    .rf-roles-grid{grid-template-columns:1fr}
    .rf-work-grid{grid-template-columns:1fr}
    .rf-work-grid > article{grid-column:1 / -1 !important}
    .rf-toolkit-grid{grid-template-columns:1fr}
    .rf-about-grid{grid-template-columns:1fr;gap:28px}
    .rf-contact-grid{grid-template-columns:1fr;gap:28px;align-items:start}
    .rf-brand-name{display:none}
    nav .rf-pad{padding-left:16px !important;padding-right:16px !important}
    .rf-nav-links{gap:11px !important}
    .rf-nav-link{font-size:12.5px !important;padding:6px 1px !important}
    .rf-cv .rf-cv-long{display:none}
    .rf-cv .rf-cv-short{display:inline}
    .rf-cv{padding:9px 13px !important}
    .rf-h1{font-size:46px !important}
    .rf-statement{font-size:17px !important}
    .rf-sec-h2{font-size:32px !important}
    .rf-contact-h2{font-size:44px !important}
    .rf-sec-hint{display:none}                 /* "Click any card" hint */
    .rf-modal{padding:16px !important}
    .rf-feat-title{font-size:24px !important}
  }

  /* MODAL */
  .rf-modal{position:fixed;inset:0;background:rgba(15,15,18,.45);backdrop-filter:blur(4px);z-index:50;display:flex;align-items:flex-start;justify-content:center;padding:48px 24px;overflow:auto;opacity:0;pointer-events:none;transition:opacity .2s}
  .rf-modal.open{opacity:1;pointer-events:auto}
  .rf-modal .sheet{background:${RF.bg};border:1px solid ${RF.rule};border-radius:20px;max-width:880px;width:100%;max-height:calc(100vh - 96px);display:flex;flex-direction:column;overflow:hidden;box-shadow:0 30px 60px -20px rgba(0,0,0,.4);transform:translateY(10px);transition:transform .25s ease}
  .rf-modal.open .sheet{transform:translateY(0)}
  .rf-sheet-scroll{overflow-y:auto;overflow-x:hidden;-webkit-overflow-scrolling:touch}
  .rf-modal .x{position:absolute;top:14px;right:14px;z-index:10;width:38px;height:38px;border-radius:50%;background:${RF.panel};border:1px solid ${RF.rule};display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:20px;line-height:1;color:${RF.ink2};padding:0;box-shadow:0 4px 12px -4px rgba(0,0,0,.25);transition:background .15s, color .15s, transform .15s}
  .rf-modal .x:hover{background:${RF.accent};color:#fff;border-color:${RF.accent};transform:scale(1.05)}
`;
if (!document.getElementById("refined-styles")) document.head.appendChild(rfStyle);

// Small inline SVG placeholder for project thumbnails — abstract glyph based
// on project type. User can swap in a real screenshot later.
function ProjGlyph({ kind }) {
  if (kind.includes("Full-stack") || kind.includes("Desktop")) {
    return <svg width="56" height="56" viewBox="0 0 56 56" fill="none"><rect x="6" y="10" width="44" height="32" rx="3" stroke="currentColor" strokeWidth="1.5"/><path d="M6 18h44M14 26h12M14 32h20M14 38h8" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"/></svg>;
  }
  if (kind.includes("GEO") || kind.includes("Engagement")) {
    return <svg width="56" height="56" viewBox="0 0 56 56" fill="none"><circle cx="28" cy="28" r="20" stroke="currentColor" strokeWidth="1.5"/><path d="M8 28h40M28 8c6 6 6 34 0 40M28 8c-6 6-6 34 0 40" stroke="currentColor" strokeWidth="1.5"/></svg>;
  }
  if (kind.includes("Research")) {
    return <svg width="56" height="56" viewBox="0 0 56 56" fill="none"><path d="M18 8v16l-8 22a4 4 0 003.7 5.5h28.6A4 4 0 0046 46l-8-22V8" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round"/><path d="M18 8h20M16 30h24" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"/><circle cx="22" cy="38" r="2" fill="currentColor"/><circle cx="32" cy="42" r="1.5" fill="currentColor"/></svg>;
  }
  return <svg width="56" height="56" viewBox="0 0 56 56" fill="none"><rect x="8" y="8" width="40" height="40" rx="3" stroke="currentColor" strokeWidth="1.5"/><path d="M8 20l40 16M8 36l40-16" stroke="currentColor" strokeWidth="1.5"/></svg>;
}

// Symbolic tiles for projects without a real screenshot yet — abstract, on-brand
// glyphs (not attempts to reproduce any third party's actual logo/brand mark).
function ProjIconTile({ kind, caption }) {
  const isSwitchboard = kind === "switchboard";
  return (
    <div style={{
      position: "absolute", inset: 0, display: "flex", flexDirection: "column",
      alignItems: "center", justifyContent: "center", gap: 14,
      background: isSwitchboard
        ? `linear-gradient(160deg, ${RF.accentSoft} 0%, #eef1fb 100%)`
        : `linear-gradient(160deg, #eafaf1 0%, #eef1fb 100%)`,
    }}>
      {isSwitchboard ? (
        <svg width="72" height="72" viewBox="0 0 72 72" fill="none">
          <circle cx="36" cy="36" r="7" fill={RF.accent}/>
          <circle cx="12" cy="14" r="4.5" fill="none" stroke={RF.accent} strokeWidth="2"/>
          <circle cx="60" cy="14" r="4.5" fill="none" stroke={RF.accent} strokeWidth="2"/>
          <circle cx="12" cy="58" r="4.5" fill="none" stroke={RF.accent} strokeWidth="2"/>
          <circle cx="60" cy="58" r="4.5" fill="none" stroke={RF.accent} strokeWidth="2"/>
          <path d="M15 17L31 32M57 17L41 32M15 55L31 40M57 55L41 40" stroke={RF.accent} strokeWidth="1.6" strokeLinecap="round" opacity="0.55"/>
        </svg>
      ) : (
        <svg width="72" height="72" viewBox="0 0 72 72" fill="none">
          <rect x="12" y="38" width="10" height="22" rx="2" fill="#2fae72"/>
          <rect x="28" y="26" width="10" height="34" rx="2" fill="#2fae72" opacity="0.75"/>
          <rect x="44" y="14" width="10" height="46" rx="2" fill="#2fae72" opacity="0.55"/>
          <path d="M10 60h52" stroke="#1c8a58" strokeWidth="2" strokeLinecap="round"/>
          <path d="M8 12c4 6 8 6 12 0s8-6 12 0 8 6 12 0 8-6 12 0" stroke="#1c8a58" strokeWidth="1.6" strokeLinecap="round" fill="none" opacity="0.6"/>
        </svg>
      )}
      <span className="mono" style={{ color: isSwitchboard ? RF.accentText : "#1c8a58", fontSize: 11, letterSpacing: ".04em" }}>{caption}</span>
    </div>
  );
}

function RefinedPortfolio() {
  const P = window.PORTFOLIO;
  const [openProject, setOpenProject] = React.useState(null);

  // Combined: featured first, then the rest
  const allProjectsRaw = [
    { ...P.featured, year: P.featured.period, kind: P.featured.subtitle, summary: P.featured.headline, details: P.featured.bullets, isFeatured: true },
    ...P.projects,
  ];
  // Custom row layout: 2 / 2 / 3 — Tiny Switchboard + Biostat lead, then the rest.
  const ORDER = ["tiny-switchboard", "biostat", "bilsen", "eirdx", "suggestly", "splitmate", "sars"];
  const allProjects = ORDER
    .map((id) => allProjectsRaw.find((p) => p.id === id))
    .filter(Boolean);
  const ROW_SPAN = [3, 3, 3, 3, 2, 2, 2]; // out of a 6-col grid → 2,2,3 cards per row

  React.useEffect(() => {
    const onKey = (e) => e.key === "Escape" && setOpenProject(null);
    window.addEventListener("keydown", onKey);
    return () => window.removeEventListener("keydown", onKey);
  }, []);

  return (
    <div className="rf-root">
      {/* NAV */}
      <nav style={{ position: "sticky", top: 0, zIndex: 20, background: `${RF.bg}e6`, backdropFilter: "blur(10px)", borderBottom: `1px solid ${RF.rule}` }}>
        <div className="rf-pad" style={{ display: "flex", alignItems: "center", padding: "18px 48px", gap: 24 }}>
          <div style={{ display: "flex", alignItems: "center", gap: 13 }}>
            <img src={window.IMG.portrait} alt="Esra Nur Tat" style={{ width: 40, height: 40, borderRadius: "50%", objectFit: "cover", objectPosition: "center 18%", display: "block" }}/>
            <span className="rf-brand-name" style={{ fontWeight: 600, fontSize: 17 }}>Esra Nur Tat</span>
          </div>
          <div className="rf-nav-links" style={{ marginLeft: "auto", display: "flex", alignItems: "center", gap: 28 }}>
            <a className="rf-nav-link" href="#who">About</a>
            <a className="rf-nav-link" href="#work">Work</a>
            <a className="rf-nav-link" href="#toolkit">Toolkit</a>
            <a className="rf-nav-link" href="#contact">Contact</a>
            <a className="rf-cv" href={P.cv} download>
              <svg width="12" height="12" viewBox="0 0 12 12" fill="none" style={{ flex: "none" }}><path d="M6 1.5v7M3 6l3 3 3-3M2 10.5h8" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/></svg>
              <span className="rf-cv-long">Download CV</span>
              <span className="rf-cv-short">CV</span>
            </a>
          </div>
        </div>
      </nav>

      {/* WHO — strong identity section. The whole top of the site IS the answer to "who is Esra". */}
      <header id="who" className="rf-pad" style={{ padding: "88px 48px 64px" }}>
        <div className="rf-hero-grid">
          <div>
            <div className="rf-status" style={{ marginBottom: 28 }}>
              <span className="dot"/>
              Open to collaboration
            </div>

            <h1 className="display rf-h1" style={{ fontSize: 92, margin: 0 }}>
              Hi, I'm <span className="acc">Esra Nur</span>.
            </h1>

            {/* Identity + about merged into one flowing intro */}
            <div className="rf-statement" style={{ marginTop: 26, fontSize: 20, lineHeight: 1.55, color: RF.ink2, letterSpacing: "-0.01em", maxWidth: 640 }}>
              <p style={{ margin: "0 0 16px", fontSize: 23, lineHeight: 1.4, color: RF.ink, fontWeight: 500, letterSpacing: "-0.015em" }}>
                Undergraduate researcher at <a href={P.ciceklabUrl} target="_blank" rel="noopener" className="rf-link acc">Çiçek Lab</a> and a Computer Science student at <strong style={{ fontWeight: 600 }}>Bilkent University</strong>, on full scholarship.
              </p>
              <p style={{ margin: "0 0 14px", textAlign: "justify", hyphens: "auto" }}>
                I work where AI research meets real software: training models on one side, and building the systems around them on the other. My work so far has spanned privacy-preserving genomics, LLM routing, and full-stack research tools.
              </p>
              <p style={{ margin: "0 0 14px" }}>
                Before Bilkent, I graduated from <strong style={{ fontWeight: 600, color: RF.ink }}>Ankara Science High School</strong>, Turkey's first and most selective science high school.
              </p>
              <p style={{ margin: 0, color: RF.ink, fontWeight: 500 }}>
                I'm open to <span className="acc">collaborations and feedback</span> on my work.
              </p>
            </div>

            {/* Quick contact — fast path so recruiters don't scroll to the footer */}
            <div style={{ display: "flex", gap: 10, marginTop: 22, flexWrap: "wrap" }}>
              <a className="rf-social" href={`mailto:${P.email}`}>
                <svg width="15" height="15" viewBox="0 0 16 16" fill="none"><rect x="1.5" y="3" width="13" height="10" rx="2" stroke="currentColor" strokeWidth="1.4"/><path d="M2 4.5l6 4 6-4" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round"/></svg>
                Email
              </a>
              <a className="rf-social" href={P.githubUrl} target="_blank" rel="noopener">
                <svg width="15" height="15" viewBox="0 0 16 16" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38v-1.33c-2.22.48-2.69-1.07-2.69-1.07-.36-.92-.89-1.17-.89-1.17-.73-.5.05-.49.05-.49.81.06 1.23.83 1.23.83.72 1.23 1.88.87 2.34.67.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.83-2.15-.08-.2-.36-1.02.08-2.13 0 0 .67-.22 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.11.16 1.93.08 2.13.52.56.83 1.28.83 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.74.54 1.49v2.21c0 .21.15.46.55.38A8 8 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>
                GitHub
              </a>
              <a className="rf-social" href={P.linkedinUrl} target="_blank" rel="noopener">
                <svg width="15" height="15" viewBox="0 0 16 16" fill="currentColor"><path d="M13.6 0H2.4A2.4 2.4 0 000 2.4v11.2A2.4 2.4 0 002.4 16h11.2a2.4 2.4 0 002.4-2.4V2.4A2.4 2.4 0 0013.6 0zM4.9 13.4H2.7V6.1h2.2v7.3zM3.8 5.1a1.3 1.3 0 110-2.5 1.3 1.3 0 010 2.5zm9.6 8.3h-2.2V9.9c0-.9 0-2-1.2-2s-1.4.9-1.4 1.9v3.6H6.4V6.1h2.1v1h.03c.3-.6 1-1.2 2.1-1.2 2.2 0 2.6 1.5 2.6 3.4v4.1z"/></svg>
                LinkedIn
              </a>
            </div>
          </div>

          <div className="rf-hero-media" style={{ display: "flex", flexDirection: "column", gap: 16, alignItems: "flex-start" }}>
            <div className="rf-portrait-slot" style={{ background: "#1a1a22", width: 240, maxWidth: "100%", aspectRatio: "1 / 1", borderRadius: "50%", boxShadow: `0 0 0 1px ${RF.rule}, 0 18px 36px -20px rgba(0,0,0,.3)` }}>
              <img src={window.IMG.portrait} alt="Esra Nur Tat" style={{ width: "100%", height: "100%", objectFit: "cover", objectPosition: "center 16%", display: "block" }}/>
            </div>
          </div>
        </div>

        {/* Experience — current & incoming roles, as a clean list (not cards) */}
        <div style={{ display: "flex", alignItems: "baseline", gap: 18, marginTop: 64 }}>
          <span className="mono">01</span>
          <h2 className="display rf-sec-h2" style={{ fontSize: 40, margin: 0 }}>Experience</h2>
        </div>
        <hr className="rf-headrule"/>
        <div className="rf-explist">
          {P.experience.map((e, i) => (
            <div key={i} className="rf-exprow">
              <div className="rf-exprow-head">
                <div style={{ display: "flex", alignItems: "center", gap: 12, flexWrap: "wrap" }}>
                  <h3 className="title" style={{ fontSize: 21, margin: 0 }}>{e.role}</h3>
                  {e.orgUrl ? (
                    <a href={e.orgUrl} target="_blank" rel="noopener" className="rf-link acc" style={{ fontSize: 14, fontWeight: 500 }}>{e.org} ↗</a>
                  ) : (
                    <span className="acc" style={{ fontSize: 14, fontWeight: 500 }}>{e.org}</span>
                  )}
                </div>
                <span className="mono" style={{ whiteSpace: "nowrap" }}>{e.period}</span>
              </div>
              <p style={{ fontSize: 14.5, color: RF.ink2, lineHeight: 1.55, margin: "10px 0 0", maxWidth: 760 }}>{e.note}</p>
            </div>
          ))}
        </div>
      </header>

      {/* WORK */}
      <section id="work" className="rf-pad" style={{ padding: "40px 48px 80px" }}>
        <div style={{ display: "flex", alignItems: "baseline", gap: 18, marginBottom: 0 }}>
          <span className="mono">02</span>
          <h2 className="display rf-sec-h2" style={{ fontSize: 48, margin: 0 }}>Selected work</h2>
          <span className="mono rf-sec-hint" style={{ marginLeft: "auto" }}>Click any card for details</span>
        </div>
        <hr className="rf-headrule"/>

        {/* Featured (first card spans wider) */}
        <div className="rf-work-grid">
          {allProjects.map((p, i) => {
            return (
              <article
                key={p.id}
                className="rf-card rf-proj hov"
                style={{ gridColumn: `span ${ROW_SPAN[i] || 2}` }}
                onClick={() => setOpenProject(p)}
              >
                <div className="thumb" style={{ aspectRatio: "16/9", padding: 0 }}>
                  {p.screenshot ? (
                    <img
                      src={p.screenshot}
                      alt={p.name}
                      style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", objectPosition: "top center" }}
                    />
                  ) : p.icon ? (
                    <ProjIconTile kind={p.icon} caption={p.icon === "switchboard" ? "Cohere Labs · Tiny Aya" : "Early build"} />
                  ) : (
                    <image-slot
                      id={`rf-thumb-${p.id}`}
                      placeholder={`Drop ${p.name} screenshot`}
                      shape="rect"
                      style={{ position: "absolute", inset: 0, "--is-radius": "0", "--is-border": "none" }}
                    ></image-slot>
                  )}
                  <div style={{ position: "absolute", top: 16, left: 16, display: "flex", gap: 8, zIndex: 2, pointerEvents: "none" }}>
                    {p.isFeatured && <span className="rf-pill acc" style={{ background: "rgba(255,255,255,.92)" }}>★ Featured</span>}
                    <span className="rf-pill" style={{ background: "rgba(255,255,255,.92)" }}>{p.year}</span>
                  </div>
                  <div style={{ position: "absolute", top: 16, right: 16, zIndex: 2, pointerEvents: "none" }}>
                    <span className="arrow" style={{ background: "rgba(255,255,255,.92)" }}>↗</span>
                  </div>
                </div>
                <div className="body">
                  <div className="mono">{p.kind}</div>
                  <h3 className="title rf-feat-title" style={{ fontSize: 17, margin: "0 0 2px" }}>{p.name}</h3>
                  <p style={{ fontSize: 12.5, color: RF.ink2, margin: 0, lineHeight: 1.5, display: "-webkit-box", WebkitLineClamp: 2, WebkitBoxOrient: "vertical", overflow: "hidden" }}>{p.summary}</p>
                  <div style={{ display: "flex", flexWrap: "wrap", gap: 5, marginTop: "auto", paddingTop: 8 }}>
                    {(p.stack || []).slice(0, 3).map((s) => <span key={s} className="rf-tag">{s}</span>)}
                  </div>
                </div>
              </article>
            );
          })}
        </div>
      </section>

      {/* TOOLKIT + Honours */}
      <section id="toolkit" className="rf-pad" style={{ padding: "0 48px 80px" }}>
        <div style={{ display: "flex", alignItems: "baseline", gap: 18, marginBottom: 0 }}>
          <span className="mono">03</span>
          <h2 className="display rf-sec-h2" style={{ fontSize: 48, margin: 0 }}>Toolkit & honours</h2>
        </div>
        <hr className="rf-headrule"/>

        <div className="rf-toolkit-grid">
          <div>
            <div className="mono" style={{ marginBottom: 22 }}>Stack</div>
            <div style={{ display: "grid", gridTemplateColumns: "auto 1fr", rowGap: 18, columnGap: 28, alignItems: "center" }}>
              {Object.entries(P.skills).map(([cat, items]) => (
                <React.Fragment key={cat}>
                  <div style={{ fontWeight: 600, fontSize: 14.5, letterSpacing: "-0.01em" }}>{cat}</div>
                  <div style={{ display: "flex", flexWrap: "wrap", gap: 6 }}>
                    {items.map((s) => <span key={s} className="rf-tag">{s}</span>)}
                  </div>
                </React.Fragment>
              ))}
            </div>
          </div>
          <div>
            <div className="rf-honours">
              <div className="mono" style={{ marginBottom: 16, color: RF.accentText }}>★ Honours</div>
              {P.awards.map((a, i) => (
                <div key={i} className="rf-aw">
                  <span className="mono" style={{ width: 38, color: RF.accent }}>{a.year}</span>
                  <span style={{ fontSize: 13.5, lineHeight: 1.45, color: RF.ink }}>{a.text}</span>
                </div>
              ))}
            </div>
            <hr className="rf-divider"/>
            <div className="mono" style={{ marginBottom: 12 }}>Languages</div>
            <div style={{ display: "flex", gap: 28 }}>
              <div><div style={{ fontSize: 20, fontWeight: 500 }}>Turkish</div><div className="mono">native</div></div>
              <div><div style={{ fontSize: 20, fontWeight: 500 }}>English</div><div className="mono">fluent</div></div>
            </div>
          </div>
        </div>
      </section>

      {/* CONTACT */}
      <footer id="contact" style={{ marginTop: 0, background: RF.panel, borderTop: `1px solid ${RF.rule}` }}>
        <div className="rf-pad" style={{ padding: "72px 48px 40px" }}>
        <div className="rf-contact-grid">
          <div>
            <div className="mono" style={{ marginBottom: 18 }}>04 · Contact</div>
            <h2 className="display rf-contact-h2" style={{ fontSize: 84, margin: 0 }}>
              Let's work <span className="acc">together.</span>
            </h2>
            <p style={{ fontSize: 18, color: RF.ink2, marginTop: 18, maxWidth: 540, lineHeight: 1.5 }}>
              Open to collaborations and feedback on my work. Always happy to talk research, AI, and systems.
            </p>
          </div>
          <div style={{ display: "flex", flexDirection: "column", gap: 12, fontSize: 15 }}>
            <a className="rf-link" href={`mailto:${P.email}`}>
              <span className="mono" style={{ width: 70, display: "inline-block" }}>Email</span>
              <span>{P.email}</span>
            </a>
            <a className="rf-link" href={P.githubUrl}>
              <span className="mono" style={{ width: 70, display: "inline-block" }}>GitHub</span>
              <span>{P.github} ↗</span>
            </a>
            <a className="rf-link" href={P.linkedinUrl}>
              <span className="mono" style={{ width: 70, display: "inline-block" }}>LinkedIn</span>
              <span>{P.linkedin} ↗</span>
            </a>
            <a className="rf-cv" style={{ marginTop: 12, alignSelf: "flex-start" }} href={P.cv} download>
              ↓ Download CV (PDF)
            </a>
          </div>
        </div>
        <div style={{ height: 1, background: RF.rule, margin: "48px 0 16px" }}/>
        <div style={{ display: "flex", justifyContent: "space-between", color: RF.muted, fontSize: 12 }}>
          <span className="mono">© 2026 Esra Nur Tat · Bilkent University</span>
          <span className="mono">Ankara, TR</span>
        </div>
        </div>
      </footer>

      {/* DETAIL MODAL */}
      <div className={`rf-modal ${openProject ? "open" : ""}`} onClick={() => setOpenProject(null)}>
        {openProject && (
          <div className="sheet" onClick={(e) => e.stopPropagation()} style={{ position: "relative" }}>
            <button className="x" aria-label="Close" onClick={() => setOpenProject(null)}>×</button>
            <div className="rf-sheet-scroll">
            <div style={{ height: 260, background: `linear-gradient(135deg, ${RF.accentSoft} 0%, ${RF.panelSoft} 100%)`, borderBottom: `1px solid ${RF.rule}`, position: "relative", overflow: "hidden" }}>
              {openProject.screenshot ? (
                <img
                  src={openProject.screenshot}
                  alt={openProject.name}
                  style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", objectPosition: "top center" }}
                />
              ) : openProject.icon ? (
                <ProjIconTile kind={openProject.icon} caption={openProject.icon === "switchboard" ? "Cohere Labs · Tiny Aya" : "Early build"} />
              ) : (
                <image-slot
                  id={`rf-thumb-${openProject.id}`}
                  placeholder={`Drop ${openProject.name} screenshot`}
                  shape="rect"
                  style={{ position: "absolute", inset: 0, "--is-radius": "0", "--is-border": "none" }}
                ></image-slot>
              )}
            </div>
            <div style={{ padding: "32px 36px 36px" }}>
              <div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 14 }}>
                {openProject.isFeatured && <span className="rf-pill acc">★ Featured</span>}
                <span className="mono">{openProject.kind}</span>
                <span className="mono" style={{ marginLeft: "auto" }}>{openProject.year}</span>
              </div>
              <h3 className="display" style={{ fontSize: 44, margin: "4px 0 8px" }}>{openProject.name}</h3>
              <p style={{ fontSize: 17, color: RF.ink2, lineHeight: 1.55, margin: "0 0 22px" }}>{openProject.summary}</p>

              {openProject.details && (
                <>
                  <div className="mono" style={{ marginBottom: 12 }}>What I built</div>
                  <ul style={{ paddingLeft: 0, listStyle: "none", margin: "0 0 24px" }}>
                    {openProject.details.map((d, i) => (
                      <li key={i} style={{ display: "flex", gap: 14, padding: "8px 0", fontSize: 14.5, color: RF.ink2, lineHeight: 1.55 }}>
                        <span className="mono acc" style={{ marginTop: 2 }}>0{i + 1}</span>
                        <span>{d}</span>
                      </li>
                    ))}
                  </ul>
                </>
              )}

              <div className="mono" style={{ marginBottom: 10 }}>Stack</div>
              <div style={{ display: "flex", flexWrap: "wrap", gap: 6, marginBottom: 22 }}>
                {(openProject.stack || []).map((s) => <span key={s} className="rf-tag">{s}</span>)}
              </div>

              {openProject.link && (
                <a href={openProject.link} className="rf-cv" style={{ background: RF.accent }}>
                  <svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38v-1.33c-2.22.48-2.69-1.07-2.69-1.07-.36-.92-.89-1.17-.89-1.17-.73-.5.05-.49.05-.49.81.06 1.23.83 1.23.83.72 1.23 1.88.87 2.34.67.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.83-2.15-.08-.2-.36-1.02.08-2.13 0 0 .67-.22 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.11.16 1.93.08 2.13.52.56.83 1.28.83 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.74.54 1.49v2.21c0 .21.15.46.55.38A8 8 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>
                  <span>View on GitHub ↗</span>
                </a>
              )}
            </div>
            </div>
          </div>
        )}
      </div>

      {window.ChatTwin ? <window.ChatTwin/> : null}
    </div>
  );
}

window.RefinedPortfolio = RefinedPortfolio;
