# #115 — Pull-to-Reveal Search & Command Drawer

> Tactile pull-down gesture (or '/' shortcut) that reveals a top search and instant-command drawer over a calm document feed.

## Metadata

- **Index**: #115
- **Slug**: `pull-to-reveal-search-drawer`
- **Kind**: `ui`
- **Family**: Search & Filtering
- **Theme**: `mixed`
- **Mobile Strength**: `native-first`
- **Tags**: `pull-to-reveal`, `search-drawer`, `rubber-band`, `quick-jump`, `document-feed`
- **Best For**: Document & note workspaces, Mobile messaging apps, Personal knowledge bases, Minimalist content feeds
- **Real-World Inspiration**: [Agenda](https://agenda.com)
- **Detail Page**: https://templates.michaelpitts.net/t/pull-to-reveal-search-drawer
- **Live Demo**: https://templates.michaelpitts.net/demos/pull-to-reveal-search-drawer.html
- **JSON API**: https://templates.michaelpitts.net/api/templates/pull-to-reveal-search-drawer

## Why This Aesthetic Is Unique

Keeps reading and browsing interfaces serene by tucking search and quick commands just above the fold, accessible via a natural downward pull.

## Color Palette

| Role | Name | Hex |
|------|------|-----|
| `canvas` | Warm Stone | `#F3F1EC` |
| `surface` | Doc White | `#FFFFFF` |
| `ink` | Graphite Ink | `#18181B` |
| `accent` | Electric Sapphire | `#2563EB` |
| `muted` | Zinc Muted | `#71717A` |

## Typography

- **Display**: `Plus Jakarta Sans`
- **Body**: `Inter`
- **Mono**: `JetBrains Mono`
- **Scale Notes**: Calm 16px document card titles with 13px metadata snippets and crisp mono keyboard hint badges.
- **Google Fonts**: https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500&family=Plus+Jakarta+Sans:wght@700&display=swap
  ```html
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500&family=Plus+Jakarta+Sans:wght@700&display=swap">
  ```

## Layout Architecture

Document card stream with a subtle top pull-affordance pill; pulling down stretches a rubber-band progress indicator and snaps open the search/command drawer.

## Interaction & Micro-Motion Rules

Pointer drag downward from the top, clicking the top search handle, or pressing '/' opens the drawer and focuses the live fuzzy filter with recent jumps and quick actions.

## Mobile & Responsive Rules

Clear tap fallback on the top pull pill guarantees discoverability alongside the rubber-band pull gesture; Escape or swipe-up dismisses cleanly.

## Agent Guardrails

### DO
- Always include a visible tap/click handle and '/' keyboard shortcut alongside the pull-down gesture
- Auto-focus the search input when the drawer opens and highlight matching query substrings
- Render a progressive stretch indicator during the pull so users know when the snap threshold is met

### DON'T
- Do not hijack normal mid-page upward scrolling when the user is not at scrollTop === 0
- Do not conflict with browser native pull-to-refresh without explicit touch-action / overscroll-behavior handling

## Complete Standalone Starter Code

File: `demos/pull-to-reveal-search-drawer.html`

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Atelier Notes — Pull-to-Reveal Search Drawer</title>
<style>
  :root {
    --canvas: #F3F1EC;
    --surface: #FFFFFF;
    --ink: #18181B;
    --accent: #2563EB;
    --accent-soft: #EFF6FF;
    --muted: #71717A;
    --border: rgba(24, 24, 27, 0.09);
    --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
    --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  }

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

  html, body {
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--font);
    min-height: 100dvh;
    overflow-x: hidden;
  }

  /* Pull-to-reveal indicator at top */
  .pull-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.15s;
  }

  .pull-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--ink);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    box-shadow: 0 8px 20px rgba(24, 24, 27, 0.22);
    transform: scale(0.9);
    transition: transform 0.12s, background 0.15s;
  }

  .pull-pill.armed {
    background: var(--accent);
    transform: scale(1);
  }

  /* Search & Command Drawer */
  .drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(24, 24, 27, 0.34);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    z-index: 30;
  }
  .drawer-backdrop.open { opacity: 1; pointer-events: auto; }

  .search-drawer {
    position: fixed;
    top: 0;
    left: 50%;
    width: min(680px, calc(100% - 20px));
    transform: translate(-50%, -108%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0 0 22px 22px;
    box-shadow: 0 24px 60px rgba(24, 24, 27, 0.22);
    z-index: 40;
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    overflow: hidden;
  }

  .search-drawer.open { transform: translate(-50%, 0); }

  .drawer-search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
  }

  .drawer-search-bar svg {
    width: 18px;
    height: 18px;
    color: var(--accent);
    flex-shrink: 0;
  }

  #cmdInput {
    flex: 1;
    border: none;
    outline: none;
    font-size: 16px;
    font-family: var(--font);
    color: var(--ink);
    background: transparent;
  }

  .close-btn {
    min-width: 44px;
    min-height: 44px;
    border: 1px solid var(--border);
    background: var(--canvas);
    color: var(--muted);
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
  }
  .close-btn:hover { color: var(--ink); }

  .drawer-body {
    max-height: 62dvh;
    overflow-y: auto;
    padding: 12px 14px 16px;
  }

  .drawer-section-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 6px 6px 8px;
  }

  .recent-jumps {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
    padding: 0 4px;
  }

  .jump-pill {
    min-height: 36px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--canvas);
    color: var(--ink);
    font-size: 12px;
    font-weight: 550;
    cursor: pointer;
    transition: all 0.14s;
  }
  .jump-pill:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

  .result-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .result-item {
    min-height: 48px;
    padding: 10px 12px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    cursor: pointer;
    transition: background 0.12s;
  }

  .result-item:hover, .result-item.selected {
    background: var(--accent-soft);
  }

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

  .result-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--canvas);
    color: var(--ink);
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
  }

  .result-item.selected .result-icon { background: var(--accent); color: #fff; }

  .result-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .result-sub {
    font-size: 12px;
    color: var(--muted);
  }

  .result-badge {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    background: var(--canvas);
    padding: 3px 8px;
    border-radius: 6px;
    flex-shrink: 0;
  }

  /* Workspace Canvas (slides down rubber-band style on pull) */
  .workspace {
    max-width: 960px;
    margin: 0 auto;
    padding: 14px 16px 60px;
    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
    touch-action: pan-y;
  }

  .workspace.pulling { transition: none; }

  .top-handle-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 18px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 16px;
  }

  .ws-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 14px;
  }

  .ws-logo {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: var(--ink);
    color: #fff;
    display: grid;
    place-items: center;
    font-family: var(--serif);
    font-size: 15px;
  }

  .pull-trigger-btn {
    min-height: 44px;
    padding: 0 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    font-size: 13px;
    font-weight: 550;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
  }
  .pull-trigger-btn:hover { border-color: var(--accent); color: var(--ink); }

  .kbd {
    font-family: ui-monospace, monospace;
    font-size: 11px;
    background: var(--canvas);
    border: 1px solid var(--border);
    padding: 1px 6px;
    border-radius: 5px;
    color: var(--ink);
  }

  .hero-strip {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
    padding: 0 4px;
  }

  .hero-strip h1 {
    font-family: var(--serif);
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
  }

  .pull-hint {
    font-size: 12px;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  /* Document grid */
  .doc-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
  }

  @media (min-width: 680px) {
    .doc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }
  @media (min-width: 920px) {
    .doc-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  }

  .doc-grid.compact {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .doc-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.16s, box-shadow 0.16s, border-color 0.16s;
    display: flex;
    flex-direction: column;
  }

  .doc-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(24, 24, 27, 0.07);
    border-color: rgba(37, 99, 235, 0.35);
  }

  .doc-cover {
    height: 112px;
    width: 100%;
    display: block;
  }

  .doc-grid.compact .doc-card {
    flex-direction: row;
    align-items: center;
    border-radius: 12px;
    padding: 10px 14px;
  }
  .doc-grid.compact .doc-cover { display: none; }

  .doc-body {
    padding: 14px 16px 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .doc-grid.compact .doc-body { padding: 0; }

  .doc-folder {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .doc-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.3;
  }

  .doc-excerpt {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.45;
  }

  .doc-footer {
    margin-top: auto;
    padding-top: 8px;
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--muted);
  }

  /* Toast */
  .toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translate(-50%, 80px);
    background: var(--ink);
    color: #fff;
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.25);
    transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 60;
    white-space: nowrap;
  }
  .toast.show { transform: translate(-50%, 0); }
</style>
</head>
<body>
  <div class="pull-indicator" id="pullIndicator">
    <div class="pull-pill" id="pullPill">↓ Pull to open Search &amp; Commands</div>
  </div>

  <div class="drawer-backdrop" id="backdrop"></div>

  <aside class="search-drawer" id="searchDrawer" role="dialog" aria-label="Search and Command Drawer" aria-hidden="true">
    <div class="drawer-search-bar">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round">
        <circle cx="11" cy="11" r="7"/><line x1="20" y1="20" x2="16.2" y2="16.2"/>
      </svg>
      <input id="cmdInput" type="text" placeholder="Jump to a note or run a command..." autocomplete="off">
      <button class="close-btn" id="closeDrawerBtn">ESC</button>
    </div>
    <div class="drawer-body">
      <div class="drawer-section-label">Recent Jumps</div>
      <div class="recent-jumps" id="recentJumps"></div>
      <div class="drawer-section-label" id="resultsLabel">Documents &amp; Commands</div>
      <ul class="result-list" id="resultList"></ul>
    </div>
  </aside>

  <main class="workspace" id="workspace">
    <header class="top-handle-bar">
      <div class="ws-brand">
        <span class="ws-logo">C</span>
        <span>Craft Space</span>
      </div>
      <button class="pull-trigger-btn" id="openDrawerBtn">
        <span>Pull down or Search</span>
        <span class="kbd">/</span>
      </button>
    </header>

    <div class="hero-strip">
      <div>
        <h1>All Documents</h1>
        <span class="pull-hint" id="filterStatus">Drag downward from anywhere on the page to reveal search</span>
      </div>
    </div>

    <section class="doc-grid" id="docGrid"></section>
  </main>

  <div class="toast" id="toast" role="status" aria-live="polite"></div>

<script>
(() => {
  const DOCS = [
    {
      id: 'q3-roadmap',
      title: 'Q3 Product Architecture & Sync Engine',
      folder: 'Engineering',
      excerpt: 'CRDT conflict resolution benchmarks, offline queue compaction, and local-first latency targets.',
      updated: '12m ago',
      words: '1,420 words',
      starred: true,
      palette: ['#DBEAFE', '#93C5FD', '#2563EB']
    },
    {
      id: 'editorial-type',
      title: 'Editorial Typography System v4',
      folder: 'Design',
      excerpt: 'Optical sizing rules for long-form serif headings paired with crisp UI sans metadata.',
      updated: '2h ago',
      words: '890 words',
      starred: true,
      palette: ['#FEF3C7', '#FCD34D', '#D97706']
    },
    {
      id: 'kyoto-field',
      title: 'Kyoto Architecture Field Notes',
      folder: 'Personal',
      excerpt: 'Timber joinery sketches, courtyard daylight angles, and quiet café acoustics near Kamogawa.',
      updated: 'Yesterday',
      words: '2,150 words',
      starred: false,
      palette: ['#D1FAE5', '#6EE7B7', '#059669']
    },
    {
      id: 'onboarding-teardown',
      title: 'First-Run Onboarding Flow Audit',
      folder: 'Design',
      excerpt: 'Reducing time-to-first-document from 48 seconds to under 9 seconds on mobile viewports.',
      updated: '2d ago',
      words: '640 words',
      starred: false,
      palette: ['#EDE9FE', '#C4B5FD', '#7C3AED']
    },
    {
      id: 'board-memo',
      title: 'Autumn Release Readiness Memo',
      folder: 'Leadership',
      excerpt: 'Launch checklist covering localization QA, enterprise SSO rollout, and support playbooks.',
      updated: '4d ago',
      words: '1,110 words',
      starred: true,
      palette: ['#FFE4E6', '#FDA4AF', '#E11D48']
    },
    {
      id: 'gesture-notes',
      title: 'Rubber-Band Gesture Physics Spec',
      folder: 'Engineering',
      excerpt: 'Damping ratios, velocity thresholds, and safe-area scroll handoffs for pull-to-reveal drawers.',
      updated: '5d ago',
      words: '780 words',
      starred: false,
      palette: ['#E0F2FE', '#7DD3FC', '#0284C7']
    }
  ];

  const COMMANDS = [
    { id: 'cmd-new', title: 'New Blank Document', sub: 'Create untitled note in workspace', badge: 'CMD', run: () => createDoc() },
    { id: 'cmd-compact', title: 'Toggle Compact List View', sub: 'Switch between gallery cards and compact rows', badge: 'VIEW', run: () => toggleCompact() },
    { id: 'cmd-starred', title: 'Filter Starred Documents', sub: 'Show only pinned favorite notes', badge: 'FILTER', run: () => toggleStarred() },
    { id: 'cmd-export', title: 'Export Workspace Markdown', sub: 'Copy all document titles as an index', badge: 'ACTION', run: () => showToast('Exported 6 documents to Markdown bundle') }
  ];

  let recentIds = ['q3-roadmap', 'editorial-type', 'gesture-notes'];
  let compactMode = false;
  let starredOnly = false;
  let drawerOpen = false;
  let selectedIdx = 0;
  let currentResults = [];

  const workspace = document.getElementById('workspace');
  const pullIndicator = document.getElementById('pullIndicator');
  const pullPill = document.getElementById('pullPill');
  const searchDrawer = document.getElementById('searchDrawer');
  const backdrop = document.getElementById('backdrop');
  const cmdInput = document.getElementById('cmdInput');
  const resultList = document.getElementById('resultList');
  const recentJumps = document.getElementById('recentJumps');
  const docGrid = document.getElementById('docGrid');
  const toastEl = document.getElementById('toast');
  const filterStatus = document.getElementById('filterStatus');

  let toastTimer = null;
  function showToast(msg) {
    toastEl.textContent = msg;
    toastEl.classList.add('show');
    clearTimeout(toastTimer);
    toastTimer = setTimeout(() => toastEl.classList.remove('show'), 2400);
  }

  function coverSvg(palette, seed) {
    const [c1, c2, c3] = palette;
    return `
      <svg class="doc-cover" viewBox="0 0 320 112" preserveAspectRatio="xMidYMid slice" aria-hidden="true">
        <rect width="320" height="112" fill="${c1}"/>
        <circle cx="${60 + (seed * 37) % 200}" cy="${30 + (seed * 19) % 50}" r="58" fill="${c2}" opacity="0.65"/>
        <path d="M0 90 Q ${90 + seed * 15} 44 190 78 T 320 64 L 320 112 L 0 112 Z" fill="${c3}" opacity="0.22"/>
        <rect x="20" y="20" width="44" height="5" rx="2.5" fill="${c3}" opacity="0.5"/>
        <rect x="20" y="31" width="76" height="4" rx="2" fill="${c3}" opacity="0.28"/>
      </svg>
    `;
  }

  function renderDocs() {
    docGrid.classList.toggle('compact', compactMode);
    const list = starredOnly ? DOCS.filter(d => d.starred) : DOCS;
    filterStatus.textContent = starredOnly
      ? `Showing ${list.length} starred documents · Pull down to search or clear`
      : 'Drag downward from anywhere on the page to reveal search';

    docGrid.innerHTML = '';
    list.forEach((doc, i) => {
      const card = document.createElement('article');
      card.className = 'doc-card';
      card.innerHTML = `
        ${coverSvg(doc.palette, i + 1)}
        <div class="doc-body">
          <div class="doc-folder">${doc.folder}${doc.starred ? ' ★' : ''}</div>
          <h2 class="doc-title"></h2>
          <p class="doc-excerpt"></p>
          <div class="doc-footer">
            <span>${doc.words}</span>
            <span>${doc.updated}</span>
          </div>
        </div>
      `;
      card.querySelector('.doc-title').textContent = doc.title;
      card.querySelector('.doc-excerpt').textContent = doc.excerpt;
      card.addEventListener('click', () => openDoc(doc));
      docGrid.appendChild(card);
    });
  }

  function openDoc(doc) {
    recentIds = [doc.id, ...recentIds.filter(id => id !== doc.id)].slice(0, 4);
    closeDrawer();
    showToast(`Opened "${doc.title}"`);
  }

  function createDoc() {
    const n = DOCS.length + 1;
    const doc = {
      id: `note-${n}`,
      title: `Untitled Draft #${n}`,
      folder: 'Inbox',
      excerpt: 'Fresh canvas created directly from the pull-to-reveal command drawer.',
      updated: 'Just now',
      words: '0 words',
      starred: false,
      palette: ['#E0E7FF', '#A5B4FC', '#4F46E5']
    };
    DOCS.unshift(doc);
    renderDocs();
    closeDrawer();
    showToast(`Created "${doc.title}"`);
  }

  function toggleCompact() {
    compactMode = !compactMode;
    renderDocs();
    closeDrawer();
    showToast(compactMode ? 'Switched to Compact List' : 'Switched to Gallery Cards');
  }

  function toggleStarred() {
    starredOnly = !starredOnly;
    renderDocs();
    closeDrawer();
    showToast(starredOnly ? 'Filtered to Starred Notes' : 'Showing All Notes');
  }

  function fuzzyScore(text, query) {
    if (!query) return 1;
    const t = text.toLowerCase();
    const q = query.toLowerCase().trim();
    if (t.includes(q)) return 100 - t.indexOf(q);
    let ti = 0, score = 0;
    for (let qi = 0; qi < q.length; qi++) {
      const idx = t.indexOf(q[qi], ti);
      if (idx === -1) return 0;
      score += idx === ti ? 5 : 2;
      ti = idx + 1;
    }
    return score;
  }

  function renderDrawerContent() {
    // Recent jump pills
    recentJumps.innerHTML = '';
    recentIds.forEach(id => {
      const doc = DOCS.find(d => d.id === id);
      if (!doc) return;
      const btn = document.createElement('button');
      btn.className = 'jump-pill';
      btn.textContent = doc.title.split(' ').slice(0, 3).join(' ');
      btn.addEventListener('click', () => openDoc(doc));
      recentJumps.appendChild(btn);
    });

    const q = cmdInput.value.trim();
    const items = [];

    DOCS.forEach(d => {
      const s = fuzzyScore(`${d.title} ${d.folder} ${d.excerpt}`, q);
      if (s > 0) items.push({ kind: 'doc', score: s, icon: 'D', title: d.title, sub: `${d.folder} · ${d.updated}`, badge: d.folder, action: () => openDoc(d) });
    });

    COMMANDS.forEach(c => {
      const s = fuzzyScore(`${c.title} ${c.sub}`, q);
      if (s > 0) items.push({ kind: 'cmd', score: s + (q ? 2 : -1), icon: '⌘', title: c.title, sub: c.sub, badge: c.badge, action: c.run });
    });

    items.sort((a, b) => b.score - a.score);
    currentResults = items;
    if (selectedIdx >= currentResults.length) selectedIdx = 0;

    resultList.innerHTML = '';
    if (currentResults.length === 0) {
      resultList.innerHTML = `<li class="result-item"><div class="result-sub">No matching documents or commands for "${q}"</div></li>`;
      return;
    }

    currentResults.forEach((item, idx) => {
      const li = document.createElement('li');
      li.className = `result-item${idx === selectedIdx ? ' selected' : ''}`;
      li.innerHTML = `
        <div class="result-left">
          <span class="result-icon">${item.icon}</span>
          <div style="min-width:0">
            <div class="result-title"></div>
            <div class="result-sub"></div>
          </div>
        </div>
        <span class="result-badge">${item.badge}</span>
      `;
      li.querySelector('.result-title').textContent = item.title;
      li.querySelector('.result-sub').textContent = item.sub;
      li.addEventListener('click', item.action);
      resultList.appendChild(li);
    });
  }

  function openDrawer() {
    drawerOpen = true;
    searchDrawer.classList.add('open');
    searchDrawer.setAttribute('aria-hidden', 'false');
    backdrop.classList.add('open');
    cmdInput.value = '';
    selectedIdx = 0;
    renderDrawerContent();
    setTimeout(() => cmdInput.focus(), 60);
  }

  function closeDrawer() {
    drawerOpen = false;
    searchDrawer.classList.remove('open');
    searchDrawer.setAttribute('aria-hidden', 'true');
    backdrop.classList.remove('open');
    cmdInput.blur();
  }

  // Pull-to-reveal pointer physics (works on touch & mouse when at scrollTop === 0)
  let pullStartY = 0;
  let pulling = false;
  let pullDist = 0;
  const THRESHOLD = 74;

  workspace.addEventListener('pointerdown', e => {
    if (drawerOpen || window.scrollY > 2) return;
    if (e.target.closest('button')) return;
    pullStartY = e.clientY;
    pulling = true;
    pullDist = 0;
  });

  window.addEventListener('pointermove', e => {
    if (!pulling) return;
    const dy = e.clientY - pullStartY;
    if (dy <= 0) {
      pullDist = 0;
      workspace.style.transform = '';
      pullIndicator.style.opacity = '0';
      return;
    }
    workspace.classList.add('pulling');
    // Rubber-band damping curve
    pullDist = Math.min(130, Math.pow(dy, 0.84));
    workspace.style.transform = `translateY(${pullDist}px)`;
    pullIndicator.style.opacity = String(Math.min(1, pullDist / 40));

    const armed = pullDist >= THRESHOLD;
    pullPill.classList.toggle('armed', armed);
    pullPill.textContent = armed ? 'Release to open Search & Commands' : '↓ Pull to open Search & Commands';
  });

  function finishPull() {
    if (!pulling) return;
    pulling = false;
    workspace.classList.remove('pulling');
    workspace.style.transform = '';
    pullIndicator.style.opacity = '0';
    pullPill.classList.remove('armed');
    if (pullDist >= THRESHOLD) openDrawer();
    pullDist = 0;
  }

  window.addEventListener('pointerup', finishPull);
  window.addEventListener('pointercancel', finishPull);

  // Controls & keyboard
  document.getElementById('openDrawerBtn').addEventListener('click', openDrawer);
  document.getElementById('closeDrawerBtn').addEventListener('click', closeDrawer);
  backdrop.addEventListener('click', closeDrawer);

  cmdInput.addEventListener('input', () => {
    selectedIdx = 0;
    renderDrawerContent();
  });

  document.addEventListener('keydown', e => {
    if (!drawerOpen && (e.key === '/' || ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k'))) {
      e.preventDefault();
      openDrawer();
      return;
    }
    if (!drawerOpen) return;
    if (e.key === 'Escape') { e.preventDefault(); closeDrawer(); }
    else if (e.key === 'ArrowDown') {
      e.preventDefault();
      selectedIdx = (selectedIdx + 1) % Math.max(1, currentResults.length);
      renderDrawerContent();
    } else if (e.key === 'ArrowUp') {
      e.preventDefault();
      selectedIdx = (selectedIdx - 1 + currentResults.length) % Math.max(1, currentResults.length);
      renderDrawerContent();
    } else if (e.key === 'Enter' && currentResults[selectedIdx]) {
      e.preventDefault();
      currentResults[selectedIdx].action();
    }
  });

  renderDocs();
})();
</script>
</body>
</html>
```
