/* About screen — the manifesto + scroll-down explainer.

   Page 0 in the flow: visible in the top nav, always reachable, and the
   default landing for fresh visits (no URL hash, no ?room=). Returning
   users who land on a hashed/shared URL skip straight into their saved
   state and never see this screen unless they click the About tab.

   Layout: manifesto hero above the fold (headline + sub + CTA), longer
   explainer below the fold (why / what / how + the three modes). */
/* global React, FRAMEWORK */

function About({ setScreen }) {
  const beginSetup = () => setScreen("landing");

  return (
    <div style={{ maxWidth: 1100, margin: "0 auto", padding: "56px 32px 96px" }}>
      {/* ─────────────────────────────────────────────────────────────
         MANIFESTO — above the fold
         ───────────────────────────────────────────────────────────── */}
      <header style={{ marginBottom: 80 }}>
        <div className="eyebrow violet" style={{ marginBottom: 18 }}>
          Protein Engineering · North star
        </div>
        <h1 style={{
          fontFamily: "var(--font-jakarta)",
          fontSize: "clamp(2.4rem, 4.5vw, 4.4rem)",
          fontWeight: 800,
          lineHeight: 0.96,
          letterSpacing: "-0.025em",
          margin: 0,
          color: "var(--fg-1)",
          textWrap: "balance",
          maxWidth: 980,
        }}>
          Decide what matters
          <span style={{ color: "var(--c-violet)" }}>.</span>
          <br />
          Before the work starts.
        </h1>
        <p style={{
          maxWidth: 720,
          marginTop: 28,
          fontFamily: "var(--font-serif)",
          fontSize: 19,
          lineHeight: 1.55,
          color: "var(--fg-2)",
        }}>
          A protein-engineering team that hasn't agreed on its quality attributes is silently
          optimizing for different things. This tool gives the team the language to align —
          and a wall poster to keep that alignment visible while the lab work runs.
        </p>
        <div style={{
          marginTop: 32,
          display: "flex", alignItems: "center", gap: 18, flexWrap: "wrap",
        }}>
          <button
            className="btn btn-primary"
            onClick={beginSetup}
            style={{ padding: "14px 24px", fontSize: 15 }}
          >
            Begin setup
            <span aria-hidden style={{ fontFamily: "var(--font-mono)", marginLeft: 4 }}>→</span>
          </button>
          <div style={{
            fontSize: 13, color: "var(--fg-4)", fontStyle: "italic",
            maxWidth: 380, lineHeight: 1.4,
          }}>
            10–15 minutes alone. 30–60 with the team. No login, no account,
            session lives in the URL.
          </div>
        </div>
      </header>

      {/* Visual divider — set the explainer apart from the manifesto */}
      <div style={{
        marginBottom: 64, paddingTop: 6,
        borderTop: "1px solid var(--border-default)",
        display: "flex", justifyContent: "center",
      }}>
        <div style={{
          marginTop: -10, padding: "0 14px",
          background: "var(--surface-cream)",
          fontFamily: "var(--font-mono)", fontSize: 11,
          letterSpacing: "0.18em", color: "var(--fg-4)",
        }}>WHY · WHAT · HOW</div>
      </div>

      {/* ─────────────────────────────────────────────────────────────
         EXPLAINER — below the fold
         ───────────────────────────────────────────────────────────── */}

      <ExplainerSection
        eyebrow="01 · North star"
        heading="Without a north star, every decision is a negotiation."
      >
        <p>
          Every protein-engineering project optimizes for <em>something</em>. If your
          team hasn't said what, you're silently optimizing for different things —
          stability for one, manufacturability for another, affinity for the third.
          By month three, you've spent the budget on an asset nobody asked for.
        </p>
        <p>
          The fix is upfront: agree on what success looks like, write it down,
          and keep it visible while the lab work runs. Decisions that were
          arguments before become five-second checks against the wall.
        </p>
      </ExplainerSection>

      <ExplainerSection
        eyebrow="02 · The framework"
        heading="10 groups. 56 attributes. Most don't matter for your project — and that's the point."
      >
        <p>
          The framework covers every quality attribute a protein-engineering team
          might care about: binding affinity, stability under stress, expression
          yield, immunogenicity, evolvability under selection, governance and
          provenance. For any specific project, only 8–15 of the 56 leaves are
          real priorities.
        </p>
        <p>
          The other ~40 are <strong>knowingly out of scope</strong>, and saying so
          explicitly is itself the alignment. The sparsity is the signal.
        </p>
        <GroupGrid />
      </ExplainerSection>

      <ExplainerSection
        eyebrow="03 · The process"
        heading="Pick. Print. Hang."
      >
        <ProcessSteps />
        <p style={{ marginTop: 24 }}>
          Next time someone proposes a trade-off — "should we sacrifice some
          thermostability for a 2× expression bump?" — you don't argue. The
          poster already gives you the answer.
        </p>
      </ExplainerSection>

      <ExplainerSection
        eyebrow="04 · Three ways to use it"
        heading="One framework, three modes."
      >
        <div style={{
          display: "grid",
          gridTemplateColumns: "repeat(auto-fit, minmax(280px, 1fr))",
          gap: 18,
          marginTop: 8,
        }}>
          <ModeCard
            title="Self-serve"
            blurb="One person, 15 minutes, your laptop. Walk through the framework, pick what matters, print the poster."
          />
          <ModeCard
            title="Workshop"
            blurb="Multi-person, projected to the room. Each participant joins on their phone via a 3-word room code; everyone votes in real time."
            accent="violet"
          />
          <ModeCard
            title="Share"
            blurb="Every session is a shareable URL — bookmark it, send it to a colleague, post it in Slack. State lives in the link."
          />
        </div>
      </ExplainerSection>

      {/* Bottom CTA — repeat the primary action so the user doesn't have
          to scroll back up */}
      <div style={{
        marginTop: 64,
        padding: "36px 32px",
        background: "var(--surface-navy)",
        color: "var(--fg-on-dark)",
        borderRadius: "var(--radius-xl)",
        display: "flex", alignItems: "center", justifyContent: "space-between",
        gap: 24, flexWrap: "wrap",
      }}>
        <div style={{ maxWidth: 560 }}>
          <div style={{
            fontFamily: "var(--font-mono)", fontSize: 11,
            letterSpacing: "0.18em", color: "rgba(255,255,255,0.55)",
            marginBottom: 8,
          }}>READY?</div>
          <h2 style={{
            fontFamily: "var(--font-jakarta)", fontWeight: 700,
            fontSize: 28, letterSpacing: "-0.02em", lineHeight: 1.15,
            margin: 0, color: "#fff",
          }}>
            Open the framework and pick what matters for your project.
          </h2>
        </div>
        <button
          className="btn btn-primary"
          onClick={beginSetup}
          style={{ padding: "14px 24px", fontSize: 15 }}
        >
          Begin setup
          <span aria-hidden style={{ fontFamily: "var(--font-mono)", marginLeft: 4 }}>→</span>
        </button>
      </div>

      {/* Tiny credit — same Crane attribution as the poster footers */}
      <div style={{
        marginTop: 32, textAlign: "center",
        fontFamily: "var(--font-mono)", fontSize: 10.5,
        letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--fg-4)",
      }}>
        <a href="https://cranebioworks.com" target="_blank" rel="noopener noreferrer"
           style={{ color: "var(--fg-3)", textDecoration: "none", borderBottom: "1px dotted rgba(34,49,83,0.2)" }}>
          Crane Bioworks
        </a>
        <span style={{ margin: "0 10px", color: "var(--fg-5)" }}>·</span>
        <a href="mailto:hello@cranebioworks.com"
           style={{ color: "var(--fg-3)", textDecoration: "none", borderBottom: "1px dotted rgba(34,49,83,0.2)" }}>
          hello@cranebioworks.com
        </a>
        <span style={{ margin: "0 10px", color: "var(--fg-5)" }}>·</span>
        <span>Built with ❤ from 🇧🇪 🇪🇺</span>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────────────────────
// Pieces
// ─────────────────────────────────────────────────────────────────────────────

function ExplainerSection({ eyebrow, heading, children }) {
  return (
    <section style={{ marginBottom: 72, maxWidth: 880 }}>
      <div className="eyebrow" style={{ marginBottom: 14, color: "var(--c-emerald-600)" }}>
        {eyebrow}
      </div>
      <h2 style={{
        fontFamily: "var(--font-jakarta)",
        fontSize: "clamp(1.6rem, 2.6vw, 2.2rem)",
        fontWeight: 700,
        letterSpacing: "-0.02em",
        lineHeight: 1.15,
        margin: "0 0 22px",
        color: "var(--fg-1)",
        textWrap: "balance",
      }}>{heading}</h2>
      <div style={{
        fontFamily: "var(--font-serif)",
        fontSize: 16.5,
        lineHeight: 1.65,
        color: "var(--fg-2)",
      }}>{children}</div>
    </section>
  );
}

function GroupGrid() {
  // Render the 10 group names as a quick visual of the framework's surface
  // area — gives a sense of breadth without forcing the reader into the
  // full leaf list.
  const groups = (typeof window !== "undefined" && window.FRAMEWORK && window.FRAMEWORK.groups) || [];
  if (groups.length === 0) return null;
  return (
    <div style={{
      marginTop: 22,
      display: "grid",
      gridTemplateColumns: "repeat(auto-fit, minmax(160px, 1fr))",
      gap: 6,
    }}>
      {groups.map(g => (
        <div key={g.id} style={{
          padding: "10px 14px",
          background: "rgba(255,255,255,0.6)",
          border: "1px solid var(--border-default)",
          borderRadius: 10,
          display: "flex", alignItems: "baseline", gap: 8,
        }}>
          <span style={{
            fontFamily: "var(--font-mono)", fontSize: 10,
            color: "var(--fg-4)", letterSpacing: "0.1em",
          }}>{String(g.id).padStart(2, "0")}</span>
          <span style={{
            fontFamily: "var(--font-jakarta)", fontWeight: 600, fontSize: 13,
            color: "var(--fg-1)", letterSpacing: "-0.005em",
          }}>{g.name}</span>
        </div>
      ))}
    </div>
  );
}

function ProcessSteps() {
  const steps = [
    {
      tier: "Lead",
      target: "3–5",
      blurb: "The project lives or dies on these. Spell out the metric or threshold where you can.",
      color: "var(--c-violet)",
    },
    {
      tier: "Follow",
      target: "5–10",
      blurb: "Tracked. Should land in spec; not the thing the program optimizes for.",
      color: "var(--c-emerald)",
    },
    {
      tier: "Out of scope",
      target: "the rest",
      blurb: "Knowingly excluded. The framework is bigger than this project — and saying so out loud is the alignment.",
      color: "rgba(34,49,83,0.35)",
    },
  ];
  return (
    <div style={{
      marginTop: 20,
      display: "grid",
      gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))",
      gap: 14,
    }}>
      {steps.map((s) => (
        <div key={s.tier} style={{
          padding: 20,
          borderRadius: 14,
          background: "rgba(255,255,255,0.65)",
          border: "1px solid var(--border-default)",
        }}>
          <div style={{
            display: "flex", alignItems: "center", gap: 8, marginBottom: 8,
          }}>
            <span style={{
              width: 10, height: 10, borderRadius: 999, background: s.color,
            }} />
            <h3 style={{
              fontFamily: "var(--font-jakarta)", fontWeight: 700,
              fontSize: 16, letterSpacing: "-0.01em", margin: 0,
            }}>{s.tier}</h3>
            <span style={{
              marginLeft: "auto",
              fontFamily: "var(--font-mono)", fontSize: 10,
              letterSpacing: "0.14em", color: "var(--fg-4)",
              textTransform: "uppercase",
            }}>target · {s.target}</span>
          </div>
          <p style={{
            margin: 0, fontFamily: "var(--font-serif)", fontSize: 14,
            color: "var(--fg-3)", lineHeight: 1.5, fontStyle: "italic",
          }}>{s.blurb}</p>
        </div>
      ))}
    </div>
  );
}

function ModeCard({ title, blurb, accent }) {
  const isViolet = accent === "violet";
  return (
    <div style={{
      padding: 20,
      borderRadius: 14,
      background: isViolet ? "rgba(104,90,217,0.06)" : "rgba(255,255,255,0.55)",
      border: `1px solid ${isViolet ? "rgba(104,90,217,0.22)" : "var(--border-default)"}`,
    }}>
      <h3 style={{
        fontFamily: "var(--font-jakarta)", fontWeight: 700,
        fontSize: 17, letterSpacing: "-0.01em",
        margin: "0 0 8px",
        color: isViolet ? "var(--c-violet-deep)" : "var(--fg-1)",
      }}>{title}</h3>
      <p style={{
        margin: 0, fontFamily: "var(--font-serif)", fontSize: 14,
        color: "var(--fg-3)", lineHeight: 1.55,
      }}>{blurb}</p>
    </div>
  );
}

window.About = About;
