{
  "id": 115,
  "slug": "pull-to-reveal-search-drawer",
  "name": "Pull-to-Reveal Search & Command Drawer",
  "kind": "ui",
  "family": "Search & Filtering",
  "sourceSite": {
    "name": "Agenda",
    "url": "https://agenda.com",
    "verifiedStatus": 200
  },
  "tagline": "Tactile pull-down gesture (or '/' shortcut) that reveals a top search and instant-command drawer over a calm document feed.",
  "whyUnique": "Keeps reading and browsing interfaces serene by tucking search and quick commands just above the fold, accessible via a natural downward pull.",
  "theme": "mixed",
  "mobileStrength": "native-first",
  "tags": [
    "pull-to-reveal",
    "search-drawer",
    "rubber-band",
    "quick-jump",
    "document-feed"
  ],
  "bestFor": [
    "Document & note workspaces",
    "Mobile messaging apps",
    "Personal knowledge bases",
    "Minimalist content feeds"
  ],
  "palette": [
    {
      "role": "canvas",
      "hex": "#F3F1EC",
      "name": "Warm Stone"
    },
    {
      "role": "surface",
      "hex": "#FFFFFF",
      "name": "Doc White"
    },
    {
      "role": "ink",
      "hex": "#18181B",
      "name": "Graphite Ink"
    },
    {
      "role": "accent",
      "hex": "#2563EB",
      "name": "Electric Sapphire"
    },
    {
      "role": "muted",
      "hex": "#71717A",
      "name": "Zinc Muted"
    }
  ],
  "typography": {
    "display": "Plus Jakarta Sans",
    "body": "Inter",
    "mono": "JetBrains Mono",
    "googleFontsUrl": "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",
    "scaleNotes": "Calm 16px document card titles with 13px metadata snippets and crisp mono keyboard hint badges."
  },
  "layoutNotes": "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.",
  "interactionNotes": "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.",
  "mobileNotes": "Clear tap fallback on the top pull pill guarantees discoverability alongside the rubber-band pull gesture; Escape or swipe-up dismisses cleanly.",
  "agentGuardrails": {
    "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"
    ],
    "dont": [
      "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"
    ]
  },
  "demoFile": "demos/pull-to-reveal-search-drawer.html",
  "thumbDesktop": "thumbs/pull-to-reveal-search-drawer-desktop.webp",
  "thumbMobile": "thumbs/pull-to-reveal-search-drawer-mobile.webp",
  "urls": {
    "page": "https://templates.michaelpitts.net/t/pull-to-reveal-search-drawer",
    "markdown": "https://templates.michaelpitts.net/t/pull-to-reveal-search-drawer.md",
    "api": "https://templates.michaelpitts.net/api/templates/pull-to-reveal-search-drawer",
    "demo": "https://templates.michaelpitts.net/demos/pull-to-reveal-search-drawer.html",
    "thumbDesktop": "https://templates.michaelpitts.net/thumbs/pull-to-reveal-search-drawer-desktop.webp",
    "thumbMobile": "https://templates.michaelpitts.net/thumbs/pull-to-reveal-search-drawer-mobile.webp"
  },
  "agentPrompt": "Design & build using template #115 \"Pull-to-Reveal Search & Command Drawer\" (ui / Search & Filtering, mixed theme).\nFull AI blueprint & standalone starter code: https://templates.michaelpitts.net/t/pull-to-reveal-search-drawer.md\nLive demo: https://templates.michaelpitts.net/demos/pull-to-reveal-search-drawer.html\nReal-world inspiration: Agenda (https://agenda.com)\n\nCore aesthetic: Keeps reading and browsing interfaces serene by tucking search and quick commands just above the fold, accessible via a natural downward pull.\nPalette: canvas: #F3F1EC (Warm Stone), surface: #FFFFFF (Doc White), ink: #18181B (Graphite Ink), accent: #2563EB (Electric Sapphire), muted: #71717A (Zinc Muted)\nTypography: Display=\"Plus Jakarta Sans\", Body=\"Inter\", Mono=\"JetBrains Mono\"\nLayout: 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.\nInteractions: 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.\nMobile: Clear tap fallback on the top pull pill guarantees discoverability alongside the rubber-band pull gesture; Escape or swipe-up dismisses cleanly.\n\nGuardrails:\n- DO: Always include a visible tap/click handle and '/' keyboard shortcut alongside the pull-down gesture\n- DO: Auto-focus the search input when the drawer opens and highlight matching query substrings\n- DO: Render a progressive stretch indicator during the pull so users know when the snap threshold is met\n- DON'T: Do not hijack normal mid-page upward scrolling when the user is not at scrollTop === 0\n- DON'T: Do not conflict with browser native pull-to-refresh without explicit touch-action / overscroll-behavior handling",
  "sourceCode": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<title>Atelier Notes — Pull-to-Reveal Search Drawer</title>\n<style>\n  :root {\n    --canvas: #F3F1EC;\n    --surface: #FFFFFF;\n    --ink: #18181B;\n    --accent: #2563EB;\n    --accent-soft: #EFF6FF;\n    --muted: #71717A;\n    --border: rgba(24, 24, 27, 0.09);\n    --font: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", system-ui, sans-serif;\n    --serif: Georgia, \"Iowan Old Style\", \"Times New Roman\", serif;\n  }\n\n  * { box-sizing: border-box; margin: 0; padding: 0; }\n\n  html, body {\n    background: var(--canvas);\n    color: var(--ink);\n    font-family: var(--font);\n    min-height: 100dvh;\n    overflow-x: hidden;\n  }\n\n  /* Pull-to-reveal indicator at top */\n  .pull-indicator {\n    position: fixed;\n    top: 0;\n    left: 0;\n    right: 0;\n    height: 64px;\n    display: flex;\n    align-items: center;\n    justify-content: center;\n    pointer-events: none;\n    z-index: 5;\n    opacity: 0;\n    transition: opacity 0.15s;\n  }\n\n  .pull-pill {\n    display: inline-flex;\n    align-items: center;\n    gap: 8px;\n    padding: 8px 14px;\n    border-radius: 999px;\n    background: var(--ink);\n    color: #fff;\n    font-size: 12px;\n    font-weight: 600;\n    box-shadow: 0 8px 20px rgba(24, 24, 27, 0.22);\n    transform: scale(0.9);\n    transition: transform 0.12s, background 0.15s;\n  }\n\n  .pull-pill.armed {\n    background: var(--accent);\n    transform: scale(1);\n  }\n\n  /* Search & Command Drawer */\n  .drawer-backdrop {\n    position: fixed;\n    inset: 0;\n    background: rgba(24, 24, 27, 0.34);\n    backdrop-filter: blur(4px);\n    -webkit-backdrop-filter: blur(4px);\n    opacity: 0;\n    pointer-events: none;\n    transition: opacity 0.22s ease;\n    z-index: 30;\n  }\n  .drawer-backdrop.open { opacity: 1; pointer-events: auto; }\n\n  .search-drawer {\n    position: fixed;\n    top: 0;\n    left: 50%;\n    width: min(680px, calc(100% - 20px));\n    transform: translate(-50%, -108%);\n    background: var(--surface);\n    border: 1px solid var(--border);\n    border-radius: 0 0 22px 22px;\n    box-shadow: 0 24px 60px rgba(24, 24, 27, 0.22);\n    z-index: 40;\n    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);\n    overflow: hidden;\n  }\n\n  .search-drawer.open { transform: translate(-50%, 0); }\n\n  .drawer-search-bar {\n    display: flex;\n    align-items: center;\n    gap: 10px;\n    padding: 14px 16px;\n    border-bottom: 1px solid var(--border);\n  }\n\n  .drawer-search-bar svg {\n    width: 18px;\n    height: 18px;\n    color: var(--accent);\n    flex-shrink: 0;\n  }\n\n  #cmdInput {\n    flex: 1;\n    border: none;\n    outline: none;\n    font-size: 16px;\n    font-family: var(--font);\n    color: var(--ink);\n    background: transparent;\n  }\n\n  .close-btn {\n    min-width: 44px;\n    min-height: 44px;\n    border: 1px solid var(--border);\n    background: var(--canvas);\n    color: var(--muted);\n    border-radius: 10px;\n    font-size: 12px;\n    font-weight: 600;\n    cursor: pointer;\n  }\n  .close-btn:hover { color: var(--ink); }\n\n  .drawer-body {\n    max-height: 62dvh;\n    overflow-y: auto;\n    padding: 12px 14px 16px;\n  }\n\n  .drawer-section-label {\n    font-size: 11px;\n    font-weight: 700;\n    letter-spacing: 0.06em;\n    text-transform: uppercase;\n    color: var(--muted);\n    margin: 6px 6px 8px;\n  }\n\n  .recent-jumps {\n    display: flex;\n    flex-wrap: wrap;\n    gap: 6px;\n    margin-bottom: 14px;\n    padding: 0 4px;\n  }\n\n  .jump-pill {\n    min-height: 36px;\n    padding: 0 12px;\n    border-radius: 999px;\n    border: 1px solid var(--border);\n    background: var(--canvas);\n    color: var(--ink);\n    font-size: 12px;\n    font-weight: 550;\n    cursor: pointer;\n    transition: all 0.14s;\n  }\n  .jump-pill:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }\n\n  .result-list {\n    list-style: none;\n    display: flex;\n    flex-direction: column;\n    gap: 4px;\n  }\n\n  .result-item {\n    min-height: 48px;\n    padding: 10px 12px;\n    border-radius: 12px;\n    display: flex;\n    align-items: center;\n    justify-content: space-between;\n    gap: 10px;\n    cursor: pointer;\n    transition: background 0.12s;\n  }\n\n  .result-item:hover, .result-item.selected {\n    background: var(--accent-soft);\n  }\n\n  .result-left {\n    display: flex;\n    align-items: center;\n    gap: 10px;\n    min-width: 0;\n  }\n\n  .result-icon {\n    width: 30px;\n    height: 30px;\n    border-radius: 8px;\n    background: var(--canvas);\n    color: var(--ink);\n    display: grid;\n    place-items: center;\n    font-size: 13px;\n    font-weight: 700;\n    flex-shrink: 0;\n  }\n\n  .result-item.selected .result-icon { background: var(--accent); color: #fff; }\n\n  .result-title {\n    font-size: 14px;\n    font-weight: 600;\n    color: var(--ink);\n    white-space: nowrap;\n    overflow: hidden;\n    text-overflow: ellipsis;\n  }\n  .result-sub {\n    font-size: 12px;\n    color: var(--muted);\n  }\n\n  .result-badge {\n    font-size: 11px;\n    font-weight: 600;\n    color: var(--muted);\n    background: var(--canvas);\n    padding: 3px 8px;\n    border-radius: 6px;\n    flex-shrink: 0;\n  }\n\n  /* Workspace Canvas (slides down rubber-band style on pull) */\n  .workspace {\n    max-width: 960px;\n    margin: 0 auto;\n    padding: 14px 16px 60px;\n    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);\n    touch-action: pan-y;\n  }\n\n  .workspace.pulling { transition: none; }\n\n  .top-handle-bar {\n    display: flex;\n    align-items: center;\n    justify-content: space-between;\n    gap: 10px;\n    margin-bottom: 18px;\n    padding: 8px 12px;\n    background: rgba(255, 255, 255, 0.72);\n    backdrop-filter: blur(10px);\n    border: 1px solid var(--border);\n    border-radius: 16px;\n  }\n\n  .ws-brand {\n    display: flex;\n    align-items: center;\n    gap: 8px;\n    font-weight: 700;\n    font-size: 14px;\n  }\n\n  .ws-logo {\n    width: 26px;\n    height: 26px;\n    border-radius: 8px;\n    background: var(--ink);\n    color: #fff;\n    display: grid;\n    place-items: center;\n    font-family: var(--serif);\n    font-size: 15px;\n  }\n\n  .pull-trigger-btn {\n    min-height: 44px;\n    padding: 0 14px;\n    border-radius: 12px;\n    border: 1px solid var(--border);\n    background: var(--surface);\n    color: var(--muted);\n    font-size: 13px;\n    font-weight: 550;\n    display: inline-flex;\n    align-items: center;\n    gap: 8px;\n    cursor: pointer;\n    transition: border-color 0.15s, color 0.15s;\n  }\n  .pull-trigger-btn:hover { border-color: var(--accent); color: var(--ink); }\n\n  .kbd {\n    font-family: ui-monospace, monospace;\n    font-size: 11px;\n    background: var(--canvas);\n    border: 1px solid var(--border);\n    padding: 1px 6px;\n    border-radius: 5px;\n    color: var(--ink);\n  }\n\n  .hero-strip {\n    display: flex;\n    align-items: flex-end;\n    justify-content: space-between;\n    flex-wrap: wrap;\n    gap: 10px;\n    margin-bottom: 16px;\n    padding: 0 4px;\n  }\n\n  .hero-strip h1 {\n    font-family: var(--serif);\n    font-size: 28px;\n    font-weight: 700;\n    letter-spacing: -0.02em;\n  }\n\n  .pull-hint {\n    font-size: 12px;\n    color: var(--muted);\n    display: inline-flex;\n    align-items: center;\n    gap: 6px;\n  }\n\n  /* Document grid */\n  .doc-grid {\n    display: grid;\n    grid-template-columns: 1fr;\n    gap: 14px;\n  }\n\n  @media (min-width: 680px) {\n    .doc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }\n  }\n  @media (min-width: 920px) {\n    .doc-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }\n  }\n\n  .doc-grid.compact {\n    grid-template-columns: 1fr;\n    gap: 8px;\n  }\n\n  .doc-card {\n    background: var(--surface);\n    border: 1px solid var(--border);\n    border-radius: 18px;\n    overflow: hidden;\n    cursor: pointer;\n    transition: transform 0.16s, box-shadow 0.16s, border-color 0.16s;\n    display: flex;\n    flex-direction: column;\n  }\n\n  .doc-card:hover {\n    transform: translateY(-2px);\n    box-shadow: 0 12px 28px rgba(24, 24, 27, 0.07);\n    border-color: rgba(37, 99, 235, 0.35);\n  }\n\n  .doc-cover {\n    height: 112px;\n    width: 100%;\n    display: block;\n  }\n\n  .doc-grid.compact .doc-card {\n    flex-direction: row;\n    align-items: center;\n    border-radius: 12px;\n    padding: 10px 14px;\n  }\n  .doc-grid.compact .doc-cover { display: none; }\n\n  .doc-body {\n    padding: 14px 16px 16px;\n    flex: 1;\n    display: flex;\n    flex-direction: column;\n    gap: 6px;\n  }\n  .doc-grid.compact .doc-body { padding: 0; }\n\n  .doc-folder {\n    font-size: 11px;\n    font-weight: 700;\n    color: var(--accent);\n    text-transform: uppercase;\n    letter-spacing: 0.05em;\n  }\n\n  .doc-title {\n    font-size: 16px;\n    font-weight: 700;\n    color: var(--ink);\n    line-height: 1.3;\n  }\n\n  .doc-excerpt {\n    font-size: 13px;\n    color: var(--muted);\n    line-height: 1.45;\n  }\n\n  .doc-footer {\n    margin-top: auto;\n    padding-top: 8px;\n    display: flex;\n    justify-content: space-between;\n    font-size: 11px;\n    color: var(--muted);\n  }\n\n  /* Toast */\n  .toast {\n    position: fixed;\n    bottom: 20px;\n    left: 50%;\n    transform: translate(-50%, 80px);\n    background: var(--ink);\n    color: #fff;\n    padding: 10px 16px;\n    border-radius: 12px;\n    font-size: 13px;\n    font-weight: 600;\n    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.25);\n    transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);\n    z-index: 60;\n    white-space: nowrap;\n  }\n  .toast.show { transform: translate(-50%, 0); }\n</style>\n</head>\n<body>\n  <div class=\"pull-indicator\" id=\"pullIndicator\">\n    <div class=\"pull-pill\" id=\"pullPill\">↓ Pull to open Search &amp; Commands</div>\n  </div>\n\n  <div class=\"drawer-backdrop\" id=\"backdrop\"></div>\n\n  <aside class=\"search-drawer\" id=\"searchDrawer\" role=\"dialog\" aria-label=\"Search and Command Drawer\" aria-hidden=\"true\">\n    <div class=\"drawer-search-bar\">\n      <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.2\" stroke-linecap=\"round\">\n        <circle cx=\"11\" cy=\"11\" r=\"7\"/><line x1=\"20\" y1=\"20\" x2=\"16.2\" y2=\"16.2\"/>\n      </svg>\n      <input id=\"cmdInput\" type=\"text\" placeholder=\"Jump to a note or run a command...\" autocomplete=\"off\">\n      <button class=\"close-btn\" id=\"closeDrawerBtn\">ESC</button>\n    </div>\n    <div class=\"drawer-body\">\n      <div class=\"drawer-section-label\">Recent Jumps</div>\n      <div class=\"recent-jumps\" id=\"recentJumps\"></div>\n      <div class=\"drawer-section-label\" id=\"resultsLabel\">Documents &amp; Commands</div>\n      <ul class=\"result-list\" id=\"resultList\"></ul>\n    </div>\n  </aside>\n\n  <main class=\"workspace\" id=\"workspace\">\n    <header class=\"top-handle-bar\">\n      <div class=\"ws-brand\">\n        <span class=\"ws-logo\">C</span>\n        <span>Craft Space</span>\n      </div>\n      <button class=\"pull-trigger-btn\" id=\"openDrawerBtn\">\n        <span>Pull down or Search</span>\n        <span class=\"kbd\">/</span>\n      </button>\n    </header>\n\n    <div class=\"hero-strip\">\n      <div>\n        <h1>All Documents</h1>\n        <span class=\"pull-hint\" id=\"filterStatus\">Drag downward from anywhere on the page to reveal search</span>\n      </div>\n    </div>\n\n    <section class=\"doc-grid\" id=\"docGrid\"></section>\n  </main>\n\n  <div class=\"toast\" id=\"toast\" role=\"status\" aria-live=\"polite\"></div>\n\n<script>\n(() => {\n  const DOCS = [\n    {\n      id: 'q3-roadmap',\n      title: 'Q3 Product Architecture & Sync Engine',\n      folder: 'Engineering',\n      excerpt: 'CRDT conflict resolution benchmarks, offline queue compaction, and local-first latency targets.',\n      updated: '12m ago',\n      words: '1,420 words',\n      starred: true,\n      palette: ['#DBEAFE', '#93C5FD', '#2563EB']\n    },\n    {\n      id: 'editorial-type',\n      title: 'Editorial Typography System v4',\n      folder: 'Design',\n      excerpt: 'Optical sizing rules for long-form serif headings paired with crisp UI sans metadata.',\n      updated: '2h ago',\n      words: '890 words',\n      starred: true,\n      palette: ['#FEF3C7', '#FCD34D', '#D97706']\n    },\n    {\n      id: 'kyoto-field',\n      title: 'Kyoto Architecture Field Notes',\n      folder: 'Personal',\n      excerpt: 'Timber joinery sketches, courtyard daylight angles, and quiet café acoustics near Kamogawa.',\n      updated: 'Yesterday',\n      words: '2,150 words',\n      starred: false,\n      palette: ['#D1FAE5', '#6EE7B7', '#059669']\n    },\n    {\n      id: 'onboarding-teardown',\n      title: 'First-Run Onboarding Flow Audit',\n      folder: 'Design',\n      excerpt: 'Reducing time-to-first-document from 48 seconds to under 9 seconds on mobile viewports.',\n      updated: '2d ago',\n      words: '640 words',\n      starred: false,\n      palette: ['#EDE9FE', '#C4B5FD', '#7C3AED']\n    },\n    {\n      id: 'board-memo',\n      title: 'Autumn Release Readiness Memo',\n      folder: 'Leadership',\n      excerpt: 'Launch checklist covering localization QA, enterprise SSO rollout, and support playbooks.',\n      updated: '4d ago',\n      words: '1,110 words',\n      starred: true,\n      palette: ['#FFE4E6', '#FDA4AF', '#E11D48']\n    },\n    {\n      id: 'gesture-notes',\n      title: 'Rubber-Band Gesture Physics Spec',\n      folder: 'Engineering',\n      excerpt: 'Damping ratios, velocity thresholds, and safe-area scroll handoffs for pull-to-reveal drawers.',\n      updated: '5d ago',\n      words: '780 words',\n      starred: false,\n      palette: ['#E0F2FE', '#7DD3FC', '#0284C7']\n    }\n  ];\n\n  const COMMANDS = [\n    { id: 'cmd-new', title: 'New Blank Document', sub: 'Create untitled note in workspace', badge: 'CMD', run: () => createDoc() },\n    { id: 'cmd-compact', title: 'Toggle Compact List View', sub: 'Switch between gallery cards and compact rows', badge: 'VIEW', run: () => toggleCompact() },\n    { id: 'cmd-starred', title: 'Filter Starred Documents', sub: 'Show only pinned favorite notes', badge: 'FILTER', run: () => toggleStarred() },\n    { 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') }\n  ];\n\n  let recentIds = ['q3-roadmap', 'editorial-type', 'gesture-notes'];\n  let compactMode = false;\n  let starredOnly = false;\n  let drawerOpen = false;\n  let selectedIdx = 0;\n  let currentResults = [];\n\n  const workspace = document.getElementById('workspace');\n  const pullIndicator = document.getElementById('pullIndicator');\n  const pullPill = document.getElementById('pullPill');\n  const searchDrawer = document.getElementById('searchDrawer');\n  const backdrop = document.getElementById('backdrop');\n  const cmdInput = document.getElementById('cmdInput');\n  const resultList = document.getElementById('resultList');\n  const recentJumps = document.getElementById('recentJumps');\n  const docGrid = document.getElementById('docGrid');\n  const toastEl = document.getElementById('toast');\n  const filterStatus = document.getElementById('filterStatus');\n\n  let toastTimer = null;\n  function showToast(msg) {\n    toastEl.textContent = msg;\n    toastEl.classList.add('show');\n    clearTimeout(toastTimer);\n    toastTimer = setTimeout(() => toastEl.classList.remove('show'), 2400);\n  }\n\n  function coverSvg(palette, seed) {\n    const [c1, c2, c3] = palette;\n    return `\n      <svg class=\"doc-cover\" viewBox=\"0 0 320 112\" preserveAspectRatio=\"xMidYMid slice\" aria-hidden=\"true\">\n        <rect width=\"320\" height=\"112\" fill=\"${c1}\"/>\n        <circle cx=\"${60 + (seed * 37) % 200}\" cy=\"${30 + (seed * 19) % 50}\" r=\"58\" fill=\"${c2}\" opacity=\"0.65\"/>\n        <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\"/>\n        <rect x=\"20\" y=\"20\" width=\"44\" height=\"5\" rx=\"2.5\" fill=\"${c3}\" opacity=\"0.5\"/>\n        <rect x=\"20\" y=\"31\" width=\"76\" height=\"4\" rx=\"2\" fill=\"${c3}\" opacity=\"0.28\"/>\n      </svg>\n    `;\n  }\n\n  function renderDocs() {\n    docGrid.classList.toggle('compact', compactMode);\n    const list = starredOnly ? DOCS.filter(d => d.starred) : DOCS;\n    filterStatus.textContent = starredOnly\n      ? `Showing ${list.length} starred documents · Pull down to search or clear`\n      : 'Drag downward from anywhere on the page to reveal search';\n\n    docGrid.innerHTML = '';\n    list.forEach((doc, i) => {\n      const card = document.createElement('article');\n      card.className = 'doc-card';\n      card.innerHTML = `\n        ${coverSvg(doc.palette, i + 1)}\n        <div class=\"doc-body\">\n          <div class=\"doc-folder\">${doc.folder}${doc.starred ? ' ★' : ''}</div>\n          <h2 class=\"doc-title\"></h2>\n          <p class=\"doc-excerpt\"></p>\n          <div class=\"doc-footer\">\n            <span>${doc.words}</span>\n            <span>${doc.updated}</span>\n          </div>\n        </div>\n      `;\n      card.querySelector('.doc-title').textContent = doc.title;\n      card.querySelector('.doc-excerpt').textContent = doc.excerpt;\n      card.addEventListener('click', () => openDoc(doc));\n      docGrid.appendChild(card);\n    });\n  }\n\n  function openDoc(doc) {\n    recentIds = [doc.id, ...recentIds.filter(id => id !== doc.id)].slice(0, 4);\n    closeDrawer();\n    showToast(`Opened \"${doc.title}\"`);\n  }\n\n  function createDoc() {\n    const n = DOCS.length + 1;\n    const doc = {\n      id: `note-${n}`,\n      title: `Untitled Draft #${n}`,\n      folder: 'Inbox',\n      excerpt: 'Fresh canvas created directly from the pull-to-reveal command drawer.',\n      updated: 'Just now',\n      words: '0 words',\n      starred: false,\n      palette: ['#E0E7FF', '#A5B4FC', '#4F46E5']\n    };\n    DOCS.unshift(doc);\n    renderDocs();\n    closeDrawer();\n    showToast(`Created \"${doc.title}\"`);\n  }\n\n  function toggleCompact() {\n    compactMode = !compactMode;\n    renderDocs();\n    closeDrawer();\n    showToast(compactMode ? 'Switched to Compact List' : 'Switched to Gallery Cards');\n  }\n\n  function toggleStarred() {\n    starredOnly = !starredOnly;\n    renderDocs();\n    closeDrawer();\n    showToast(starredOnly ? 'Filtered to Starred Notes' : 'Showing All Notes');\n  }\n\n  function fuzzyScore(text, query) {\n    if (!query) return 1;\n    const t = text.toLowerCase();\n    const q = query.toLowerCase().trim();\n    if (t.includes(q)) return 100 - t.indexOf(q);\n    let ti = 0, score = 0;\n    for (let qi = 0; qi < q.length; qi++) {\n      const idx = t.indexOf(q[qi], ti);\n      if (idx === -1) return 0;\n      score += idx === ti ? 5 : 2;\n      ti = idx + 1;\n    }\n    return score;\n  }\n\n  function renderDrawerContent() {\n    // Recent jump pills\n    recentJumps.innerHTML = '';\n    recentIds.forEach(id => {\n      const doc = DOCS.find(d => d.id === id);\n      if (!doc) return;\n      const btn = document.createElement('button');\n      btn.className = 'jump-pill';\n      btn.textContent = doc.title.split(' ').slice(0, 3).join(' ');\n      btn.addEventListener('click', () => openDoc(doc));\n      recentJumps.appendChild(btn);\n    });\n\n    const q = cmdInput.value.trim();\n    const items = [];\n\n    DOCS.forEach(d => {\n      const s = fuzzyScore(`${d.title} ${d.folder} ${d.excerpt}`, q);\n      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) });\n    });\n\n    COMMANDS.forEach(c => {\n      const s = fuzzyScore(`${c.title} ${c.sub}`, q);\n      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 });\n    });\n\n    items.sort((a, b) => b.score - a.score);\n    currentResults = items;\n    if (selectedIdx >= currentResults.length) selectedIdx = 0;\n\n    resultList.innerHTML = '';\n    if (currentResults.length === 0) {\n      resultList.innerHTML = `<li class=\"result-item\"><div class=\"result-sub\">No matching documents or commands for \"${q}\"</div></li>`;\n      return;\n    }\n\n    currentResults.forEach((item, idx) => {\n      const li = document.createElement('li');\n      li.className = `result-item${idx === selectedIdx ? ' selected' : ''}`;\n      li.innerHTML = `\n        <div class=\"result-left\">\n          <span class=\"result-icon\">${item.icon}</span>\n          <div style=\"min-width:0\">\n            <div class=\"result-title\"></div>\n            <div class=\"result-sub\"></div>\n          </div>\n        </div>\n        <span class=\"result-badge\">${item.badge}</span>\n      `;\n      li.querySelector('.result-title').textContent = item.title;\n      li.querySelector('.result-sub').textContent = item.sub;\n      li.addEventListener('click', item.action);\n      resultList.appendChild(li);\n    });\n  }\n\n  function openDrawer() {\n    drawerOpen = true;\n    searchDrawer.classList.add('open');\n    searchDrawer.setAttribute('aria-hidden', 'false');\n    backdrop.classList.add('open');\n    cmdInput.value = '';\n    selectedIdx = 0;\n    renderDrawerContent();\n    setTimeout(() => cmdInput.focus(), 60);\n  }\n\n  function closeDrawer() {\n    drawerOpen = false;\n    searchDrawer.classList.remove('open');\n    searchDrawer.setAttribute('aria-hidden', 'true');\n    backdrop.classList.remove('open');\n    cmdInput.blur();\n  }\n\n  // Pull-to-reveal pointer physics (works on touch & mouse when at scrollTop === 0)\n  let pullStartY = 0;\n  let pulling = false;\n  let pullDist = 0;\n  const THRESHOLD = 74;\n\n  workspace.addEventListener('pointerdown', e => {\n    if (drawerOpen || window.scrollY > 2) return;\n    if (e.target.closest('button')) return;\n    pullStartY = e.clientY;\n    pulling = true;\n    pullDist = 0;\n  });\n\n  window.addEventListener('pointermove', e => {\n    if (!pulling) return;\n    const dy = e.clientY - pullStartY;\n    if (dy <= 0) {\n      pullDist = 0;\n      workspace.style.transform = '';\n      pullIndicator.style.opacity = '0';\n      return;\n    }\n    workspace.classList.add('pulling');\n    // Rubber-band damping curve\n    pullDist = Math.min(130, Math.pow(dy, 0.84));\n    workspace.style.transform = `translateY(${pullDist}px)`;\n    pullIndicator.style.opacity = String(Math.min(1, pullDist / 40));\n\n    const armed = pullDist >= THRESHOLD;\n    pullPill.classList.toggle('armed', armed);\n    pullPill.textContent = armed ? 'Release to open Search & Commands' : '↓ Pull to open Search & Commands';\n  });\n\n  function finishPull() {\n    if (!pulling) return;\n    pulling = false;\n    workspace.classList.remove('pulling');\n    workspace.style.transform = '';\n    pullIndicator.style.opacity = '0';\n    pullPill.classList.remove('armed');\n    if (pullDist >= THRESHOLD) openDrawer();\n    pullDist = 0;\n  }\n\n  window.addEventListener('pointerup', finishPull);\n  window.addEventListener('pointercancel', finishPull);\n\n  // Controls & keyboard\n  document.getElementById('openDrawerBtn').addEventListener('click', openDrawer);\n  document.getElementById('closeDrawerBtn').addEventListener('click', closeDrawer);\n  backdrop.addEventListener('click', closeDrawer);\n\n  cmdInput.addEventListener('input', () => {\n    selectedIdx = 0;\n    renderDrawerContent();\n  });\n\n  document.addEventListener('keydown', e => {\n    if (!drawerOpen && (e.key === '/' || ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k'))) {\n      e.preventDefault();\n      openDrawer();\n      return;\n    }\n    if (!drawerOpen) return;\n    if (e.key === 'Escape') { e.preventDefault(); closeDrawer(); }\n    else if (e.key === 'ArrowDown') {\n      e.preventDefault();\n      selectedIdx = (selectedIdx + 1) % Math.max(1, currentResults.length);\n      renderDrawerContent();\n    } else if (e.key === 'ArrowUp') {\n      e.preventDefault();\n      selectedIdx = (selectedIdx - 1 + currentResults.length) % Math.max(1, currentResults.length);\n      renderDrawerContent();\n    } else if (e.key === 'Enter' && currentResults[selectedIdx]) {\n      e.preventDefault();\n      currentResults[selectedIdx].action();\n    }\n  });\n\n  renderDocs();\n})();\n</script>\n</body>\n</html>\n"
}
