# #126 — Omnibar Command Palette

> Keyboard-first Cmd+K launcher with fuzzy search, inline calculator, scoped filters, and a mobile thumb trigger.

## Metadata

- **Index**: #126
- **Slug**: `omnibar-command-palette`
- **Kind**: `ui`
- **Family**: Command & Navigation
- **Theme**: `dark`
- **Mobile Strength**: `high`
- **Tags**: `command-palette`, `keyboard-first`, `fuzzy-search`, `launcher`, `power-user`, `omnibar`
- **Best For**: Developer consoles and cloud dashboards, Productivity suites with 20+ actions, SaaS workspaces needing fast navigation, Cross-device tools with keyboard and touch parity
- **Real-World Inspiration**: [Raycast](https://www.raycast.com/)
- **Detail Page**: https://templates.michaelpitts.net/t/omnibar-command-palette
- **Live Demo**: https://templates.michaelpitts.net/demos/omnibar-command-palette.html
- **JSON API**: https://templates.michaelpitts.net/api/templates/omnibar-command-palette

## Why This Aesthetic Is Unique

Collapses dozens of deep menu hierarchies into a single zero-latency search bar that evaluates math expressions inline and exposes a thumb-reachable floating launcher on 390px viewports.

## Color Palette

| Role | Name | Hex |
|------|------|-----|
| `canvas` | Obsidian Void | `#0B0C10` |
| `surface` | Carbon Glass | `#15171E` |
| `ink` | Titanium White | `#F3F4F8` |
| `accent` | Raycast Coral | `#FF6363` |
| `muted` | Slate Mist | `#8B90A0` |

## Typography

- **Display**: `Inter`
- **Body**: `Inter`
- **Mono**: `JetBrains Mono`
- **Scale Notes**: 16px search input to prevent iOS zoom, 14px command titles, 11px uppercase mono group headers and keycap badges.
- **Google Fonts**: https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500;600&display=swap
  ```html
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500;600&display=swap">
  ```

## Layout Architecture

Centered frosted modal stage paired with an auxiliary live state panel on desktop; single-column full-width stack on mobile with horizontal-scroll scope chips.

## Interaction & Micro-Motion Rules

Cmd/Ctrl+K focuses and selects the query input; ArrowUp/ArrowDown move selection, Enter executes the command, Escape clears, and arithmetic expressions trigger an instant calculator banner.

## Mobile & Responsive Rules

Replaces keyboard-only Cmd+K discoverability with a fixed 48px bottom-center thumb pill, hides desktop keycap legends, and enforces 48px command row heights.

## Agent Guardrails

### DO
- Always provide an explicit visible trigger button and mobile thumb pill alongside Cmd+K.
- Keep the search input at >=16px font size so mobile browsers do not auto-zoom on focus.
- Group results semantically and show immediate feedback when a command executes.

### DON'T
- Never rely solely on keyboard shortcuts to open the palette on touch devices.
- Avoid nesting multi-level flyout submenus inside narrow command rows.

## Complete Standalone Starter Code

File: `demos/omnibar-command-palette.html`

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Omnibar Command Palette — Raycast-Inspired Pattern</title>
<style>
  :root {
    --canvas: #0b0c10;
    --surface: #15171e;
    --surface-2: #1e212b;
    --border: rgba(255,255,255,0.09);
    --ink: #f3f4f8;
    --muted: #8b90a0;
    --accent: #ff6363;
    --accent-soft: rgba(255,99,99,0.16);
    --mint: #4ade80;
    --radius: 14px;
    --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
    --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  html, body {
    min-height: 100%;
    background: radial-gradient(1200px 600px at 50% -10%, rgba(255,99,99,0.12), transparent 60%), var(--canvas);
    color: var(--ink);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
  }
  .shell {
    max-width: 1120px;
    margin: 0 auto;
    padding: 20px 18px 100px;
    display: grid;
    gap: 18px;
  }
  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
  }
  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.01em;
  }
  .brand-mark {
    width: 30px; height: 30px; border-radius: 9px;
    background: linear-gradient(135deg, #ff6363, #ff8f6b);
    display: grid; place-items: center;
    box-shadow: 0 6px 20px rgba(255,99,99,0.3);
  }
  .open-btn {
    min-height: 44px;
    padding: 0 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    font: 500 14px var(--font);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: border-color .15s, background .15s;
  }
  .open-btn:hover { border-color: rgba(255,99,99,0.5); background: var(--surface-2); }
  kbd {
    font: 600 11px var(--mono);
    padding: 3px 6px;
    border-radius: 6px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--muted);
  }
  .workspace {
    display: grid;
    grid-template-columns: 1.25fr 0.75fr;
    gap: 18px;
    align-items: start;
  }
  .palette-stage {
    background: rgba(21,23,30,0.92);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 18px;
    box-shadow: 0 28px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.03) inset;
    overflow: hidden;
    backdrop-filter: blur(20px);
  }
  .search-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
  }
  .search-row input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    outline: none;
    color: var(--ink);
    font: 500 16px var(--font);
  }
  .search-row input::placeholder { color: var(--muted); }
  .scope-chips {
    display: flex;
    gap: 6px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .scope-chips::-webkit-scrollbar { display: none; }
  .chip {
    min-height: 36px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font: 500 13px var(--font);
    white-space: nowrap;
    cursor: pointer;
    transition: all .15s;
  }
  .chip.active, .chip:hover {
    background: var(--accent-soft);
    border-color: rgba(255,99,99,0.45);
    color: var(--ink);
  }
  .calc-banner {
    display: none;
    padding: 12px 16px;
    background: linear-gradient(90deg, rgba(74,222,128,0.12), rgba(74,222,128,0.03));
    border-bottom: 1px solid rgba(74,222,128,0.25);
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }
  .calc-banner.show { display: flex; }
  .calc-val { font: 700 20px var(--mono); color: var(--mint); }
  .results {
    max-height: 410px;
    overflow-y: auto;
    padding: 8px;
  }
  .group-label {
    font: 600 11px var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    padding: 10px 10px 6px;
  }
  .cmd-item {
    width: 100%;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
    font-family: var(--font);
  }
  .cmd-item.selected {
    background: var(--surface-2);
    border-color: rgba(255,99,99,0.35);
  }
  .cmd-left { display: flex; align-items: center; gap: 11px; min-width: 0; }
  .cmd-icon {
    width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
    background: rgba(255,255,255,0.06);
    display: grid; place-items: center;
    font-size: 14px;
  }
  .cmd-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .cmd-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .cmd-meta { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
  .badge {
    font: 500 11px var(--mono);
    padding: 2px 7px;
    border-radius: 6px;
    background: rgba(255,255,255,0.06);
    color: var(--muted);
  }
  .palette-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    background: rgba(0,0,0,0.22);
    font-size: 12px;
    color: var(--muted);
  }
  .side-panel {
    display: grid;
    gap: 14px;
  }
  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
  }
  .card h2 {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 12px;
  }
  .log-list { display: grid; gap: 8px; }
  .log-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--surface-2);
    font-size: 13px;
  }
  .log-time { font: 500 11px var(--mono); color: var(--muted); flex-shrink: 0; }
  .env-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-box {
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
  }
  .stat-k { font-size: 11px; color: var(--muted); }
  .stat-v { font: 600 14px var(--mono); margin-top: 3px; }
  .thumb-fab {
    display: none;
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    min-height: 48px;
    padding: 0 20px;
    border-radius: 999px;
    border: 1px solid rgba(255,99,99,0.5);
    background: linear-gradient(135deg, #24191e, #161822);
    color: var(--ink);
    font: 600 14px var(--font);
    box-shadow: 0 12px 32px rgba(0,0,0,0.55);
    align-items: center;
    gap: 8px;
    cursor: pointer;
    z-index: 40;
  }
  .toast {
    position: fixed;
    top: 16px;
    right: 16px;
    padding: 11px 16px;
    border-radius: 10px;
    background: #1f2430;
    border: 1px solid rgba(255,99,99,0.45);
    color: var(--ink);
    font-size: 13px;
    box-shadow: 0 14px 30px rgba(0,0,0,0.45);
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
    transition: all .2s;
    z-index: 50;
  }
  .toast.show { opacity: 1; transform: translateY(0); }
  @media (max-width: 860px) {
    .workspace { grid-template-columns: 1fr; }
    .thumb-fab { display: inline-flex; }
    .desktop-hint { display: none; }
  }
</style>
</head>
<body>
<div class="shell">
  <header class="topbar">
    <div class="brand">
      <div class="brand-mark" aria-hidden="true">
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2.4" stroke-linecap="round"><path d="M5 19L19 5M11 5h8v8"/></svg>
      </div>
      <span>Raycast-Style Omnibar</span>
    </div>
    <button class="open-btn" id="focusBtn" type="button">
      <span>Jump to Command</span>
      <span class="desktop-hint"><kbd>⌘</kbd> <kbd>K</kbd></span>
    </button>
  </header>

  <main class="workspace">
    <section class="palette-stage" aria-label="Command Palette">
      <div class="search-row">
        <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#ff6363" stroke-width="2.2" stroke-linecap="round"><circle cx="11" cy="11" r="7"/><path d="M20 20l-3.5-3.5"/></svg>
        <input id="queryInput" type="text" autocomplete="off" spellcheck="false" placeholder="Search commands, run math (e.g. 240*1.15), or jump..." aria-label="Search commands">
        <button id="clearBtn" type="button" style="display:none;min-height:36px;min-width:36px;border-radius:8px;border:1px solid var(--border);background:var(--surface-2);color:var(--muted);cursor:pointer;">✕</button>
      </div>

      <div class="scope-chips" id="scopeChips" role="tablist" aria-label="Filter scope">
        <button class="chip active" data-scope="all" type="button">All</button>
        <button class="chip" data-scope="Actions" type="button">Actions</button>
        <button class="chip" data-scope="Navigation" type="button">Navigation</button>
        <button class="chip" data-scope="Snippets" type="button">Snippets</button>
        <button class="chip" data-scope="System" type="button">System</button>
      </div>

      <div class="calc-banner" id="calcBanner">
        <div>
          <div style="font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.06em;">Instant Calculator</div>
          <div class="calc-val" id="calcVal">0</div>
        </div>
        <button class="open-btn" id="copyCalcBtn" type="button">Copy Result</button>
      </div>

      <div class="results" id="results" role="listbox" aria-label="Command results"></div>

      <div class="palette-footer">
        <span id="resultCount">12 commands</span>
        <span class="desktop-hint"><kbd>↑</kbd> <kbd>↓</kbd> Navigate &nbsp; <kbd>↵</kbd> Run &nbsp; <kbd>Esc</kbd> Clear</span>
      </div>
    </section>

    <aside class="side-panel">
      <div class="card">
        <h2>Workspace State</h2>
        <div class="env-grid">
          <div class="stat-box"><div class="stat-k">Active Branch</div><div class="stat-v" id="stBranch">main</div></div>
          <div class="stat-box"><div class="stat-k">Focus Timer</div><div class="stat-v" id="stTimer">Idle</div></div>
          <div class="stat-box"><div class="stat-k">Deploy Target</div><div class="stat-v" id="stEnv">Production</div></div>
          <div class="stat-box"><div class="stat-k">Accent Mode</div><div class="stat-v" id="stAccent">Coral</div></div>
        </div>
      </div>
      <div class="card">
        <h2>Execution History</h2>
        <div class="log-list" id="logList">
          <div class="log-row"><span>Omnibar initialized</span><span class="log-time">just now</span></div>
        </div>
      </div>
    </aside>
  </main>
</div>

<button class="thumb-fab" id="thumbFab" type="button" aria-label="Focus command palette">
  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#ff6363" stroke-width="2.4" stroke-linecap="round"><circle cx="11" cy="11" r="7"/><path d="M20 20l-3.5-3.5"/></svg>
  <span>Command Palette</span>
</button>
<div class="toast" id="toast" role="status" aria-live="polite"></div>

<script>
const COMMANDS = [
  { id: 'deploy', group: 'Actions', icon: '🚀', title: 'Deploy Production Release', sub: 'Trigger zero-downtime rollout to edge nodes', key: '⌘⇧D', run: () => { setStat('stEnv', 'Deploying…'); setTimeout(() => setStat('stEnv', 'Prod v2.14'), 900); return 'Triggered Production rollout v2.14'; } },
  { id: 'branch', group: 'Actions', icon: '🌿', title: 'Switch Git Branch to feat/omnibar', sub: 'Checkout local feature branch & stash changes', key: '⌘B', run: () => { const cur = document.getElementById('stBranch').textContent; const next = cur === 'main' ? 'feat/omnibar' : 'main'; setStat('stBranch', next); return `Checked out ${next}`; } },
  { id: 'timer', group: 'Actions', icon: '⏱', title: 'Start 25m Deep Focus Timer', sub: 'Mute Slack & start Pomodoro session', key: '⌘T', run: () => { setStat('stTimer', '24:59'); return 'Started 25-minute focus sprint'; } },
  { id: 'pr', group: 'Navigation', icon: '🔀', title: 'Open Pull Request #418', sub: 'Add mobile thumb trigger to command palette', key: 'G P', run: () => 'Opened PR #418 in workspace' },
  { id: 'metrics', group: 'Navigation', icon: '📊', title: 'Jump to P95 Latency Dashboard', sub: 'Live edge telemetry · us-east & eu-central', key: 'G M', run: () => 'Navigated to Latency Dashboard (42ms p95)' },
  { id: 'docs', group: 'Navigation', icon: '📘', title: 'Search Design Token Docs', sub: 'Spacing, radii, surface elevation tokens', key: 'G D', run: () => 'Opened Design Token Reference' },
  { id: 'snip-sql', group: 'Snippets', icon: '✂️', title: 'Insert Active Users SQL Snippet', sub: 'SELECT date_trunc(\'day\', seen_at)...', key: 'S 1', run: () => 'Copied Active Users SQL snippet to clipboard' },
  { id: 'snip-standup', group: 'Snippets', icon: '📝', title: 'Expand Daily Standup Template', sub: 'Yesterday / Today / Blockers markdown block', key: 'S 2', run: () => 'Expanded Standup Template' },
  { id: 'snip-uuid', group: 'Snippets', icon: '🔑', title: 'Generate Cryptographic UUID v4', sub: 'Copy random RFC 4122 identifier', key: 'S U', run: () => `Generated UUID ${crypto.randomUUID().slice(0,18)}…` },
  { id: 'accent', group: 'System', icon: '🎨', title: 'Cycle Accent Hue (Coral / Cyan / Violet)', sub: 'Updates live CSS custom properties', key: '⌘⇧A', run: () => {
    const modes = [['Coral','#ff6363','rgba(255,99,99,0.16)'],['Cyan','#38bdf8','rgba(56,189,248,0.16)'],['Violet','#a78bfa','rgba(167,139,250,0.16)']];
    const cur = document.getElementById('stAccent').textContent;
    const idx = (modes.findIndex(m => m[0] === cur) + 1) % modes.length;
    document.documentElement.style.setProperty('--accent', modes[idx][1]);
    document.documentElement.style.setProperty('--accent-soft', modes[idx][2]);
    setStat('stAccent', modes[idx][0]);
    return `Switched palette accent to ${modes[idx][0]}`;
  }},
  { id: 'clear-cache', group: 'System', icon: '🧹', title: 'Flush Edge Asset Cache', sub: 'Purge stale CDN bundles across 14 PoPs', key: '⌘⌥C', run: () => 'Flushed 14 CDN edge PoPs (120ms)' },
  { id: 'export-log', group: 'System', icon: '📦', title: 'Reset Execution History', sub: 'Clear recent command audit trail', key: '⌘⌥R', run: () => { document.getElementById('logList').innerHTML = ''; return 'Cleared command history'; } }
];

let activeScope = 'all';
let selectedIndex = 0;
let filtered = [...COMMANDS];

const queryInput = document.getElementById('queryInput');
const resultsEl = document.getElementById('results');
const resultCount = document.getElementById('resultCount');
const clearBtn = document.getElementById('clearBtn');
const calcBanner = document.getElementById('calcBanner');
const calcVal = document.getElementById('calcVal');
const toast = document.getElementById('toast');

function setStat(id, val) { document.getElementById(id).textContent = val; }

function showToast(msg) {
  toast.textContent = msg;
  toast.classList.add('show');
  clearTimeout(showToast._t);
  showToast._t = setTimeout(() => toast.classList.remove('show'), 2400);
}

function addLog(msg) {
  const row = document.createElement('div');
  row.className = 'log-row';
  const now = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' });
  row.innerHTML = `<span>${msg}</span><span class="log-time">${now}</span>`;
  document.getElementById('logList').prepend(row);
  while (document.getElementById('logList').children.length > 6) {
    document.getElementById('logList').lastElementChild.remove();
  }
}

function evalMath(str) {
  const clean = str.trim();
  if (!/^[0-9+\-*/().\s%]+$/.test(clean) || !/[+\-*/%]/.test(clean)) return null;
  try {
    const val = Function('"use strict";return (' + clean + ')')();
    if (typeof val === 'number' && Number.isFinite(val)) return Math.round(val * 10000) / 10000;
  } catch {}
  return null;
}

function fuzzyScore(text, q) {
  if (!q) return 1;
  const t = text.toLowerCase(), s = q.toLowerCase();
  if (t.includes(s)) return 3;
  let i = 0;
  for (const ch of t) if (ch === s[i]) i++;
  return i === s.length ? 2 : 0;
}

function render() {
  const q = queryInput.value.trim();
  clearBtn.style.display = q ? 'inline-grid' : 'none';

  const mathRes = evalMath(q);
  if (mathRes !== null) {
    calcVal.textContent = mathRes.toLocaleString();
    calcBanner.classList.add('show');
  } else {
    calcBanner.classList.remove('show');
  }

  filtered = COMMANDS.filter(c => activeScope === 'all' || c.group === activeScope)
    .map(c => ({ c, score: Math.max(fuzzyScore(c.title, q), fuzzyScore(c.sub, q), fuzzyScore(c.group, q)) }))
    .filter(x => x.score > 0)
    .sort((a, b) => b.score - a.score)
    .map(x => x.c);

  if (selectedIndex >= filtered.length) selectedIndex = Math.max(0, filtered.length - 1);
  resultCount.textContent = `${filtered.length} command${filtered.length === 1 ? '' : 's'}`;

  if (!filtered.length) {
    resultsEl.innerHTML = `<div style="padding:36px 16px;text-align:center;color:var(--muted);font-size:14px;">No commands match "<strong>${q.replace(/</g,'&lt;')}</strong>". Try typing a math expression like <code>48 * 12</code>.</div>`;
    return;
  }

  const groups = {};
  filtered.forEach((cmd, idx) => {
    (groups[cmd.group] ||= []).push({ cmd, idx });
  });

  let html = '';
  for (const [grp, items] of Object.entries(groups)) {
    html += `<div class="group-label">${grp}</div>`;
    for (const { cmd, idx } of items) {
      html += `<button type="button" class="cmd-item ${idx === selectedIndex ? 'selected' : ''}" data-idx="${idx}" role="option" aria-selected="${idx === selectedIndex}">
        <div class="cmd-left">
          <div class="cmd-icon">${cmd.icon}</div>
          <div style="min-width:0;">
            <div class="cmd-title">${cmd.title}</div>
            <div class="cmd-sub">${cmd.sub}</div>
          </div>
        </div>
        <div class="cmd-meta"><kbd>${cmd.key}</kbd></div>
      </button>`;
    }
  }
  resultsEl.innerHTML = html;

  resultsEl.querySelectorAll('.cmd-item').forEach(btn => {
    btn.addEventListener('mouseenter', () => {
      selectedIndex = Number(btn.dataset.idx);
      resultsEl.querySelectorAll('.cmd-item').forEach(el => el.classList.toggle('selected', Number(el.dataset.idx) === selectedIndex));
    });
    btn.addEventListener('click', () => execute(Number(btn.dataset.idx)));
  });
}

function execute(idx) {
  const cmd = filtered[idx];
  if (!cmd) return;
  const msg = cmd.run();
  addLog(msg);
  showToast(msg);
}

queryInput.addEventListener('input', () => { selectedIndex = 0; render(); });
clearBtn.addEventListener('click', () => { queryInput.value = ''; selectedIndex = 0; render(); queryInput.focus(); });

document.getElementById('scopeChips').addEventListener('click', e => {
  const btn = e.target.closest('.chip');
  if (!btn) return;
  activeScope = btn.dataset.scope;
  document.querySelectorAll('.chip').forEach(c => c.classList.toggle('active', c === btn));
  selectedIndex = 0;
  render();
});

document.getElementById('copyCalcBtn').addEventListener('click', () => {
  const v = calcVal.textContent;
  navigator.clipboard?.writeText(v).catch(() => {});
  addLog(`Copied calculation result: ${v}`);
  showToast(`Copied ${v}`);
});

function focusPalette() {
  queryInput.scrollIntoView({ behavior: 'smooth', block: 'center' });
  queryInput.focus();
  queryInput.select();
}
document.getElementById('focusBtn').addEventListener('click', focusPalette);
document.getElementById('thumbFab').addEventListener('click', focusPalette);

window.addEventListener('keydown', e => {
  if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') {
    e.preventDefault();
    focusPalette();
    return;
  }
  if (e.key === 'ArrowDown') {
    e.preventDefault();
    if (filtered.length) { selectedIndex = (selectedIndex + 1) % filtered.length; render(); }
  } else if (e.key === 'ArrowUp') {
    e.preventDefault();
    if (filtered.length) { selectedIndex = (selectedIndex - 1 + filtered.length) % filtered.length; render(); }
  } else if (e.key === 'Enter' && document.activeElement === queryInput) {
    e.preventDefault();
    execute(selectedIndex);
  } else if (e.key === 'Escape') {
    queryInput.value = '';
    selectedIndex = 0;
    render();
  }
});

render();
</script>
</body>
</html>
```
