#055 style light mobile: high Indie Developer Tooling

Social Cloud Scratchpad

Notebook-light indie cloud-function workbench with runnable Val snippets, live JSON execution logs, and fork counts.

Inspired by Val Town ↗

Download .html
Fullscreen ↗

WHY THIS AESTHETIC IS UNIQUE

Makes serverless cloud functions feel as approachable and remixable as a notebook scratchpad, replacing intimidating cloud consoles with crisp hairline code cards and one-click execution.

BEST FOR

Interactive API sandboxes and cloud function runnersCode snippet sharing and developer notebooksLightweight automation and webhook studios

TAGS

COLOR PALETTE (CLICK TO COPY HEX)

TYPOGRAPHY

Display
IBM Plex Sans
Body
Inter
Mono
IBM Plex Mono
Scale
Clean 14-15px workbench chrome with 13px monospace runnable code, execution latency badges, and compact version pills.

Google Fonts Stylesheet ↗

ARCHITECTURE & MOBILE NOTES

LAYOUT

Minimalist header with Val handle breadcrumb (`@author/valName`), selectable snippet tabs (HTTP API, Scheduled Cron, Webhook), code pane, and live execution log panel.

INTERACTION

Pick a runnable Val snippet, click Run Val to execute and stream realistic JSON response + millisecond timing logs, toggle versions, or increment the remix/fork counter.

MOBILE

Code pane and output console stack vertically with 44px Run/Fork action buttons and horizontal scroll contained strictly inside code blocks.

AI AGENT GUARDRAILS

DO

  • Keep the Run button immediately visible and responsive with concrete JSON/latency output
  • Display social craft metadata (handle, version, forks, trigger type) cleanly in monospace
  • Use crisp 1px borders and calm notebook whitespace rather than heavy IDE chrome

DON'T

  • Do not overwhelm users with cloud IAM menus or multi-step deployment wizards
  • Do not leave execution panels static; clicking Run must visibly produce new output
STANDALONE SOURCE · demos/social-cloud-scratchpad.html (26.2 KB)
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Runlet — Social Cloud Function Scratchpad</title>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
  <style>
    :root {
      --canvas: #FBFBF9;
      --surface: #F3F4F6;
      --card: #FFFFFF;
      --ink: #111827;
      --ink-soft: #374151;
      --accent: #0F766E;
      --accent-hover: #0D625B;
      --accent-soft: rgba(15, 118, 110, 0.10);
      --muted: #64748B;
      --border: #E5E7EB;
      --ok: #059669;
      --amber: #D97706;
      --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
      --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
    }

    *, *::before, *::after {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    html, body {
      background: var(--canvas);
      color: var(--ink);
      font-family: var(--font-sans);
      -webkit-font-smoothing: antialiased;
      overflow-x: hidden;
    }

    /* Top Nav */
    .navbar {
      position: sticky;
      top: 0;
      z-index: 30;
      background: rgba(251, 251, 249, 0.94);
      backdrop-filter: blur(8px);
      border-bottom: 1px solid var(--border);
    }

    .nav-inner {
      max-width: 1140px;
      margin: 0 auto;
      padding: 0 20px;
      height: 58px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
    }

    .nav-left {
      display: flex;
      align-items: center;
      gap: 14px;
      min-width: 0;
    }

    .brand {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      text-decoration: none;
      color: var(--ink);
      font-weight: 700;
      font-size: 15px;
      letter-spacing: -0.02em;
      white-space: nowrap;
    }

    .brand-icon {
      width: 24px;
      height: 24px;
      border-radius: 6px;
      background: var(--accent);
      display: grid;
      place-items: center;
    }

    .nav-links {
      display: flex;
      align-items: center;
      gap: 4px;
    }

    .nav-links a {
      text-decoration: none;
      color: var(--muted);
      font-size: 13.5px;
      font-weight: 500;
      padding: 6px 10px;
      border-radius: 7px;
    }

    .nav-links a:hover {
      color: var(--ink);
      background: var(--surface);
    }

    .nav-right {
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .btn-fork {
      display: inline-flex;
      align-items: center;
      gap: 7px;
      height: 36px;
      padding: 0 12px;
      border-radius: 8px;
      border: 1px solid var(--border);
      background: var(--card);
      color: var(--ink);
      font-family: inherit;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      transition: border-color 0.14s ease, background 0.14s ease;
    }

    .btn-fork:hover {
      border-color: #CBD5E1;
      background: var(--surface);
    }

    .btn-fork.forked {
      border-color: rgba(15, 118, 110, 0.4);
      background: var(--accent-soft);
      color: var(--accent);
    }

    .fork-badge {
      font-family: var(--font-mono);
      font-size: 12px;
      padding: 1px 6px;
      border-radius: 999px;
      background: var(--surface);
      color: var(--ink-soft);
    }

    .mobile-menu-btn {
      display: none;
      width: 44px;
      height: 44px;
      border: 1px solid var(--border);
      border-radius: 8px;
      background: var(--card);
      color: var(--ink);
      align-items: center;
      justify-content: center;
      cursor: pointer;
    }

    .mobile-nav {
      display: none;
      flex-direction: column;
      padding: 10px 20px 16px;
      border-top: 1px solid var(--border);
      background: var(--card);
      gap: 4px;
    }

    .mobile-nav.open { display: flex; }

    .mobile-nav a {
      text-decoration: none;
      color: var(--ink);
      font-size: 15px;
      font-weight: 500;
      min-height: 44px;
      display: flex;
      align-items: center;
    }

    /* Main Container */
    .container {
      max-width: 1140px;
      margin: 0 auto;
      padding: 28px 20px 72px;
    }

    /* Snippet Switcher */
    .snippet-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
      gap: 12px;
      margin-bottom: 18px;
    }

    .snippet-tabs {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap;
    }

    .val-tab {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      height: 38px;
      padding: 0 14px;
      border-radius: 9px;
      border: 1px solid var(--border);
      background: var(--card);
      color: var(--ink-soft);
      font-family: inherit;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.14s ease;
    }

    .val-tab:hover {
      border-color: #CBD5E1;
      color: var(--ink);
    }

    .val-tab.active {
      background: var(--ink);
      border-color: var(--ink);
      color: #FFFFFF;
    }

    .kind-tag {
      font-family: var(--font-mono);
      font-size: 10.5px;
      text-transform: uppercase;
      padding: 2px 6px;
      border-radius: 4px;
      background: var(--surface);
      color: var(--muted);
    }

    .val-tab.active .kind-tag {
      background: rgba(255, 255, 255, 0.16);
      color: #FFFFFF;
    }

    /* Val Header Meta */
    .val-header {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      flex-wrap: wrap;
      gap: 14px;
      margin-bottom: 16px;
    }

    .val-slug {
      font-family: var(--font-mono);
      font-size: clamp(18px, 2.5vw, 22px);
      font-weight: 600;
      letter-spacing: -0.02em;
      color: var(--ink);
    }

    .val-slug span {
      color: var(--muted);
      font-weight: 400;
    }

    .val-desc {
      font-size: 14px;
      color: var(--muted);
      margin-top: 4px;
    }

    .version-pills {
      display: flex;
      align-items: center;
      gap: 6px;
      flex-wrap: wrap;
    }

    .ver-pill {
      height: 30px;
      padding: 0 10px;
      border-radius: 999px;
      border: 1px solid var(--border);
      background: var(--card);
      color: var(--muted);
      font-family: var(--font-mono);
      font-size: 11.5px;
      cursor: pointer;
      transition: all 0.14s ease;
    }

    .ver-pill.active {
      background: var(--accent-soft);
      border-color: rgba(15, 118, 110, 0.35);
      color: var(--accent);
      font-weight: 600;
    }

    /* Workbench Grid */
    .workbench {
      display: grid;
      grid-template-columns: 1.2fr 0.8fr;
      gap: 16px;
      margin-bottom: 28px;
    }

    .pane {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 12px;
      overflow: hidden;
      display: flex;
      flex-direction: column;
      min-width: 0;
    }

    .pane-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      padding: 10px 14px;
      background: var(--surface);
      border-bottom: 1px solid var(--border);
    }

    .endpoint-url {
      font-family: var(--font-mono);
      font-size: 12px;
      color: var(--ink-soft);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      min-width: 0;
    }

    .pane-actions {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-shrink: 0;
    }

    .btn-copy {
      height: 32px;
      padding: 0 10px;
      border-radius: 7px;
      border: 1px solid var(--border);
      background: var(--card);
      color: var(--ink-soft);
      font-family: var(--font-mono);
      font-size: 11.5px;
      cursor: pointer;
    }

    .btn-run {
      display: inline-flex;
      align-items: center;
      gap: 7px;
      height: 34px;
      padding: 0 14px;
      border-radius: 8px;
      border: none;
      background: var(--accent);
      color: #FFFFFF;
      font-family: inherit;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      transition: background 0.14s ease, transform 0.1s ease;
    }

    .btn-run:hover { background: var(--accent-hover); }
    .btn-run:active { transform: scale(0.98); }

    .code-area {
      width: 100%;
      min-height: 310px;
      padding: 16px;
      border: none;
      outline: none;
      resize: vertical;
      font-family: var(--font-mono);
      font-size: 13px;
      line-height: 1.65;
      color: var(--ink);
      background: var(--card);
      tab-size: 2;
    }

    .pane-foot {
      padding: 8px 14px;
      background: var(--canvas);
      border-top: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-family: var(--font-mono);
      font-size: 11.5px;
      color: var(--muted);
    }

    /* Output Console */
    .output-body {
      padding: 14px;
      display: flex;
      flex-direction: column;
      gap: 12px;
      flex: 1;
    }

    .status-strip {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      padding: 8px 10px;
      border-radius: 8px;
      background: var(--surface);
      font-family: var(--font-mono);
      font-size: 12px;
    }

    .badge-ok {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      color: var(--ok);
      font-weight: 600;
    }

    .badge-ok::before {
      content: '';
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: var(--ok);
    }

    .json-pre {
      background: #F8FAFC;
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 12px;
      font-family: var(--font-mono);
      font-size: 12.5px;
      line-height: 1.55;
      color: var(--ink);
      overflow-x: auto;
      white-space: pre;
    }

    .log-list {
      list-style: none;
      display: flex;
      flex-direction: column;
      gap: 6px;
      font-family: var(--font-mono);
      font-size: 11.5px;
      color: var(--muted);
      max-height: 120px;
      overflow-y: auto;
    }

    .log-item {
      display: flex;
      justify-content: space-between;
      gap: 8px;
      padding: 5px 8px;
      border-radius: 6px;
      background: var(--canvas);
      border: 1px solid var(--border);
    }

    /* Community Strip */
    .section-title {
      font-size: 13px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      color: var(--muted);
      margin-bottom: 12px;
    }

    .remix-grid {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 14px;
    }

    .remix-card {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 11px;
      padding: 16px;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    .remix-name {
      font-family: var(--font-mono);
      font-size: 13px;
      font-weight: 600;
      color: var(--ink);
    }

    .remix-desc {
      font-size: 13px;
      line-height: 1.5;
      color: var(--muted);
    }

    .remix-meta {
      margin-top: auto;
      font-family: var(--font-mono);
      font-size: 11.5px;
      color: var(--accent);
    }

    @media (max-width: 880px) {
      .workbench { grid-template-columns: 1fr; }
      .remix-grid { grid-template-columns: 1fr; }
    }

    @media (max-width: 680px) {
      .nav-links { display: none; }
      .mobile-menu-btn { display: inline-flex; }

      .nav-inner { padding: 0 14px; }
      .container { padding: 20px 14px 56px; }

      .val-tab, .ver-pill, .btn-run, .btn-copy, .btn-fork {
        min-height: 44px;
      }

      .code-area { min-height: 240px; font-size: 12.5px; }
    }
  </style>
</head>
<body>
  <header class="navbar">
    <div class="nav-inner">
      <div class="nav-left">
        <a href="#top" class="brand">
          <span class="brand-icon" aria-hidden="true">
            <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
              <path d="M2.5 3.5L6.5 7L2.5 10.5M7.5 10.5H11.5" stroke="#FFFFFF" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
            </svg>
          </span>
          <span>runlet</span>
        </a>
        <nav class="nav-links" aria-label="Primary">
          <a href="#workbench">Explore</a>
          <a href="#workbench">Docs</a>
          <a href="#remixes">Community</a>
        </nav>
      </div>

      <div class="nav-right">
        <button type="button" class="btn-fork" id="forkBtn">
          <svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round">
            <circle cx="4.5" cy="3.5" r="2"/>
            <circle cx="11.5" cy="3.5" r="2"/>
            <circle cx="8" cy="12.5" r="2"/>
            <path d="M4.5 5.5v1.5a3.5 3.5 0 0 0 7 0V5.5M8 10.5V8.5"/>
          </svg>
          <span id="forkLabel">Fork</span>
          <span class="fork-badge" id="forkCount">42</span>
        </button>

        <button type="button" class="mobile-menu-btn" id="mobileMenuBtn" aria-label="Toggle Menu" aria-expanded="false">
          <svg width="20" height="20" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round">
            <line x1="3" y1="6" x2="17" y2="6"/>
            <line x1="3" y1="10" x2="17" y2="10"/>
            <line x1="3" y1="14" x2="17" y2="14"/>
          </svg>
        </button>
      </div>
    </div>

    <div class="mobile-nav" id="mobileNav">
      <a href="#workbench">Live Workbench</a>
      <a href="#remixes">Community Remixes</a>
    </div>
  </header>

  <main class="container" id="top">
    <div class="snippet-bar" id="workbench">
      <div class="snippet-tabs" role="tablist">
        <button type="button" class="val-tab active" role="tab" aria-selected="true" data-val="http">
          <span class="kind-tag">HTTP</span>
          fee-calculator
        </button>
        <button type="button" class="val-tab" role="tab" aria-selected="false" data-val="cron">
          <span class="kind-tag">CRON</span>
          morning-digest
        </button>
        <button type="button" class="val-tab" role="tab" aria-selected="false" data-val="webhook">
          <span class="kind-tag">HOOK</span>
          release-notifier
        </button>
      </div>
    </div>

    <header class="val-header">
      <div>
        <h1 class="val-slug" id="valSlug"><span>@soren/</span>fee-calculator</h1>
        <p class="val-desc" id="valDesc"></p>
      </div>
      <div class="version-pills" id="versionPills" role="group" aria-label="Version History"></div>
    </header>

    <section class="workbench">
      <div class="pane">
        <div class="pane-bar">
          <span class="endpoint-url" id="endpointUrl">https://soren-feecalc.runlet.dev</span>
          <div class="pane-actions">
            <button type="button" class="btn-copy" id="copyUrlBtn">Copy URL</button>
            <button type="button" class="btn-run" id="runBtn">
              <svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor">
                <path d="M2.5 1.8L10.2 6L2.5 10.2V1.8Z"/>
              </svg>
              <span>Run Val</span>
            </button>
          </div>
        </div>
        <textarea class="code-area" id="codeArea" spellcheck="false" aria-label="Val TypeScript source code"></textarea>
        <div class="pane-foot">
          <span id="runtimeInfo">TypeScript · Deno 2.1 · Edge iad1</span>
          <span id="versionNote">v14 · Added USD rounding guard</span>
        </div>
      </div>

      <div class="pane">
        <div class="pane-bar">
          <span style="font-family:var(--font-mono);font-size:12px;font-weight:600;">Execution Output</span>
          <span style="font-family:var(--font-mono);font-size:11.5px;color:var(--muted);" id="lastRunAt">Ready</span>
        </div>
        <div class="output-body">
          <div class="status-strip">
            <span class="badge-ok" id="statusBadge">200 OK</span>
            <span id="execMs">14 ms · 6.2 MB RSS</span>
          </div>
          <pre class="json-pre" id="jsonOutput"></pre>
          <div>
            <div style="font-family:var(--font-mono);font-size:11px;color:var(--muted);margin-bottom:6px;text-transform:uppercase;">Recent Invocations</div>
            <ul class="log-list" id="logList"></ul>
          </div>
        </div>
      </div>
    </section>

    <section id="remixes">
      <h2 class="section-title">Recent Public Remixes</h2>
      <div class="remix-grid">
        <article class="remix-card">
          <div class="remix-name">@linnea/rss-to-bluesky</div>
          <p class="remix-desc">Polls an Atom feed every 15 minutes and posts new essays with OpenGraph cards.</p>
          <div class="remix-meta">CRON · 19 forks · 11 ms avg</div>
        </article>
        <article class="remix-card">
          <div class="remix-name">@kofi/sqlite-waitlist</div>
          <p class="remix-desc">Zero-config email signup endpoint backed by per-val SQLite with rate limiting.</p>
          <div class="remix-meta">HTTP · 64 forks · 9 ms avg</div>
        </article>
        <article class="remix-card">
          <div class="remix-name">@mira/linear-triage-bot</div>
          <p class="remix-desc">Receives GitHub issue webhooks and routes labeled bugs to the on-call Linear cycle.</p>
          <div class="remix-meta">WEBHOOK · 28 forks · 22 ms avg</div>
        </article>
      </div>
    </section>
  </main>

  <script>
    const VALS = {
      http: {
        author: '@soren/',
        name: 'fee-calculator',
        desc: 'HTTP endpoint returning net payout after card processing fees and currency conversion.',
        url: 'https://soren-feecalc.runlet.dev/?amount=14900&currency=USD',
        forks: 42,
        runtime: 'HTTP · Deno 2.1 · Edge iad1',
        versions: [
          { id: 'v14', label: 'v14 · current', note: 'v14 · Added integer cent rounding guard' },
          { id: 'v13', label: 'v13 · 2h ago', note: 'v13 · Support EUR and GBP FX spread' },
          { id: 'v12', label: 'v12 · Oct 19', note: 'v12 · Initial public HTTP handler' }
        ],
        code: `export default async function (req: Request): Promise<Response> {
  const url = new URL(req.url);
  const amountCents = Number(url.searchParams.get("amount") ?? 14900);
  const currency = (url.searchParams.get("currency") ?? "USD").toUpperCase();

  const feeCents = Math.round(amountCents * 0.029) + 30;
  const netCents = Math.max(0, amountCents - feeCents);

  return Response.json({
    ok: true,
    currency,
    gross: (amountCents / 100).toFixed(2),
    fee: (feeCents / 100).toFixed(2),
    net: (netCents / 100).toFixed(2),
    region: Deno.env.get("RUNLET_REGION") ?? "iad1"
  });
}`,
        runResult: () => ({
          status: '200 OK',
          ms: 11 + Math.floor(Math.random() * 9),
          payload: {
            ok: true,
            currency: 'USD',
            gross: '149.00',
            fee: '4.62',
            net: '144.38',
            region: 'iad1'
          }
        })
      },
      cron: {
        author: '@soren/',
        name: 'morning-digest',
        desc: 'Scheduled daily cron (0 8 * * *) that gathers open pull requests and emails a plain-text summary.',
        url: 'cron://0 8 * * * · UTC-5',
        forks: 27,
        runtime: 'CRON · Deno 2.1 · Scheduler',
        versions: [
          { id: 'v9', label: 'v9 · current', note: 'v9 · Skip draft PRs automatically' },
          { id: 'v8', label: 'v8 · Oct 16', note: 'v8 · Added age-in-days sorting' }
        ],
        code: `import { email } from "https://esm.runlet.dev/std/email";

export default async function (interval: Interval) {
  const prs = [
    { repo: "kanso-ui", id: 412, title: "Fix mobile drawer trap", ageDays: 1 },
    { repo: "vellum-core", id: 889, title: "Tune glyph atlas cache", ageDays: 3 }
  ];

  await email({
    subject: \`Morning PR Digest (\${prs.length} open)\`,
    text: prs.map(p => \`#\${p.id} [\${p.repo}] \${p.title}\`).join("\\n")
  });

  return { delivered: true, count: prs.length, nextRun: interval.next };
}`,
        runResult: () => ({
          status: '200 CRON',
          ms: 34 + Math.floor(Math.random() * 18),
          payload: {
            delivered: true,
            recipient: 'soren@studio.example',
            count: 2,
            nextRun: '2026-12-07T13:00:00Z'
          }
        })
      },
      webhook: {
        author: '@soren/',
        name: 'release-notifier',
        desc: 'Verifies GitHub release HMAC signatures and posts signed changelog notes to a team channel.',
        url: 'https://soren-releasehook.runlet.dev/webhook',
        forks: 19,
        runtime: 'WEBHOOK · Deno 2.1 · Edge fra1',
        versions: [
          { id: 'v6', label: 'v6 · current', note: 'v6 · Enforce SHA-256 signature header' },
          { id: 'v5', label: 'v5 · Oct 11', note: 'v5 · Parse semantic version tag' }
        ],
        code: `export default async function (req: Request): Promise<Response> {
  const sig = req.headers.get("x-hub-signature-256") ?? "sha256=verified";
  const release = {
    tag: "v2.4.0",
    repo: "mirthworks/kestrel",
    author: "clara",
    assets: 3
  };

  console.log("Verified webhook:", sig.slice(0, 18));
  return Response.json({
    accepted: true,
    notified: "#releases",
    release
  }, { status: 202 });
}`,
        runResult: () => ({
          status: '202 ACCEPTED',
          ms: 17 + Math.floor(Math.random() * 14),
          payload: {
            accepted: true,
            signatureValid: true,
            notified: '#releases',
            release: { tag: 'v2.4.0', repo: 'mirthworks/kestrel', assets: 3 }
          }
        })
      }
    };

    let activeKey = 'http';
    let forkedMap = { http: false, cron: false, webhook: false };
    let logs = [];

    const codeArea = document.getElementById('codeArea');
    const jsonOutput = document.getElementById('jsonOutput');
    const logList = document.getElementById('logList');

    function renderVal(key) {
      activeKey = key;
      const v = VALS[key];
      document.getElementById('valSlug').innerHTML = `<span>${v.author}</span>${v.name}`;
      document.getElementById('valDesc').textContent = v.desc;
      document.getElementById('endpointUrl').textContent = v.url;
      document.getElementById('runtimeInfo').textContent = v.runtime;
      codeArea.value = v.code;

      // Version pills
      const pillsEl = document.getElementById('versionPills');
      pillsEl.innerHTML = '';
      v.versions.forEach((ver, i) => {
        const btn = document.createElement('button');
        btn.type = 'button';
        btn.className = 'ver-pill' + (i === 0 ? ' active' : '');
        btn.textContent = ver.label;
        btn.addEventListener('click', () => {
          pillsEl.querySelectorAll('.ver-pill').forEach(p => p.classList.remove('active'));
          btn.classList.add('active');
          document.getElementById('versionNote').textContent = ver.note;
        });
        pillsEl.appendChild(btn);
      });
      document.getElementById('versionNote').textContent = v.versions[0].note;

      // Fork button state
      updateForkUI();

      // Active tab state
      document.querySelectorAll('.val-tab').forEach(tab => {
        const active = tab.dataset.val === key;
        tab.classList.toggle('active', active);
        tab.setAttribute('aria-selected', String(active));
      });

      executeVal(false);
    }

    function updateForkUI() {
      const v = VALS[activeKey];
      const isForked = forkedMap[activeKey];
      const forkBtn = document.getElementById('forkBtn');
      forkBtn.classList.toggle('forked', isForked);
      document.getElementById('forkLabel').textContent = isForked ? 'Forked' : 'Fork';
      document.getElementById('forkCount').textContent = v.forks + (isForked ? 1 : 0);
    }

    function executeVal(withDelay = true) {
      const v = VALS[activeKey];
      const runBtn = document.getElementById('runBtn');
      const finish = () => {
        const res = v.runResult();
        const now = new Date();
        const ts = now.toTimeString().slice(0, 8);
        document.getElementById('statusBadge').textContent = res.status;
        document.getElementById('execMs').textContent = `${res.ms} ms · 6.4 MB RSS`;
        document.getElementById('lastRunAt').textContent = `Ran at ${ts}`;
        jsonOutput.textContent = JSON.stringify(res.payload, null, 2);

        logs.unshift({ val: v.name, status: res.status, ms: res.ms, ts });
        logs = logs.slice(0, 6);
        logList.innerHTML = logs.map(l => `
          <li class="log-item">
            <span>${l.ts} · ${l.val}</span>
            <span style="color:var(--accent);font-weight:600;">${l.status} (${l.ms} ms)</span>
          </li>
        `).join('');
        runBtn.disabled = false;
        runBtn.querySelector('span').textContent = 'Run Val';
      };

      if (withDelay) {
        runBtn.disabled = true;
        runBtn.querySelector('span').textContent = 'Running...';
        setTimeout(finish, 240);
      } else {
        finish();
      }
    }

    document.querySelectorAll('.val-tab').forEach(tab => {
      tab.addEventListener('click', () => renderVal(tab.dataset.val));
    });

    document.getElementById('runBtn').addEventListener('click', () => executeVal(true));

    document.getElementById('forkBtn').addEventListener('click', () => {
      forkedMap[activeKey] = !forkedMap[activeKey];
      updateForkUI();
    });

    document.getElementById('copyUrlBtn').addEventListener('click', async function () {
      const url = document.getElementById('endpointUrl').textContent;
      try { await navigator.clipboard.writeText(url); } catch (_) {}
      this.textContent = 'Copied!';
      setTimeout(() => this.textContent = 'Copy URL', 1200);
    });

    // Mobile Nav
    const mobileMenuBtn = document.getElementById('mobileMenuBtn');
    const mobileNav = document.getElementById('mobileNav');
    mobileMenuBtn.addEventListener('click', () => {
      const open = mobileNav.classList.toggle('open');
      mobileMenuBtn.setAttribute('aria-expanded', String(open));
    });
    mobileNav.querySelectorAll('a').forEach(a => {
      a.addEventListener('click', () => {
        mobileNav.classList.remove('open');
        mobileMenuBtn.setAttribute('aria-expanded', 'false');
      });
    });

    renderVal('http');
  </script>
</body>
</html>