# #116 — Sticky Section-Header Alphabet/Index Jump Bar

> Alphabetical directory with sticky section headers and a touch-scrubbable vertical index rail with floating loupe.

## Metadata

- **Index**: #116
- **Slug**: `sticky-alphabet-index-bar`
- **Kind**: `ui`
- **Family**: Lists & Directories
- **Theme**: `dark`
- **Mobile Strength**: `native-first`
- **Tags**: `alphabet-index`, `sticky-headers`, `directory-list`, `touch-scrub`, `loupe-bubble`
- **Best For**: Music & vinyl artist catalogs, Contact & team directories, Glossary & medical indexes, Country & airport pickers
- **Real-World Inspiration**: [Bandcamp](https://bandcamp.com)
- **Detail Page**: https://templates.michaelpitts.net/t/sticky-alphabet-index-bar
- **Live Demo**: https://templates.michaelpitts.net/demos/sticky-alphabet-index-bar.html
- **JSON API**: https://templates.michaelpitts.net/api/templates/sticky-alphabet-index-bar

## Why This Aesthetic Is Unique

Makes browsing hundreds of sorted entries instantaneous on mobile by combining sticky orientation headers with continuous finger-scrubbing along an A-Z edge rail.

## Color Palette

| Role | Name | Hex |
|------|------|-----|
| `canvas` | Vinyl Matte | `#111317` |
| `surface` | Sleeve Slate | `#1B1F26` |
| `ink` | Liner White | `#F3F4F6` |
| `accent` | Bandcamp Cyan | `#1DA0C3` |
| `muted` | Groove Gray | `#94A3B8` |

## Typography

- **Display**: `Space Grotesk`
- **Body**: `Inter`
- **Mono**: `JetBrains Mono`
- **Scale Notes**: Bold 15px sticky letter headers, crisp 11px right-rail index letters, and a 44px floating loupe badge during scrub.
- **Google Fonts**: https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&family=JetBrains+Mono:wght@600&family=Space+Grotesk:wght@700&display=swap
  ```html
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&family=JetBrains+Mono:wght@600&family=Space+Grotesk:wght@700&display=swap">
  ```

## Layout Architecture

Single-column directory with right padding reserved for the fixed vertical A-Z index rail; sticky letter headers pin seamlessly beneath the search header.

## Interaction & Micro-Motion Rules

Tapping or dragging vertically along the A-Z rail displays a floating magnification loupe bubble and jumps immediately to that letter section while highlighting the active letter.

## Mobile & Responsive Rules

Touch-action: none on the right-edge index rail enables smooth continuous thumb scrubbing without accidental page bounce.

## Agent Guardrails

### DO
- Show a large floating magnification loupe offset to the left of the finger so the user's thumb never hides the active letter
- Reserve right-side padding on list rows so the vertical A-Z rail never overlaps row actions or badges
- Visually dim or skip letters that have zero matching items when a search filter is active

### DON'T
- Do not make the index rail wider than ~32px on 390px viewports where horizontal space is precious
- Do not use sluggish smooth-scroll animations during rapid continuous scrubbing along the index rail

## Complete Standalone Starter Code

File: `demos/sticky-alphabet-index-bar.html`

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>WaxIndex — Sticky Alphabet Artist Directory</title>
<style>
  :root {
    --canvas: #111317;
    --surface: #1B1F26;
    --surface-hover: #222731;
    --ink: #F3F4F6;
    --accent: #1DA0C3;
    --accent-soft: rgba(29, 160, 195, 0.16);
    --muted: #94A3B8;
    --border: rgba(255, 255, 255, 0.08);
    --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, monospace;
  }

  * { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

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

  .layout {
    max-width: 960px;
    margin: 0 auto;
    padding: 16px 46px 64px 14px;
  }

  @media (min-width: 760px) {
    .layout { padding: 28px 68px 80px 28px; }
  }

  .masthead {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
  }

  .brand-row {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--accent);
    display: grid;
    place-items: center;
    flex-shrink: 0;
  }

  .masthead h1 {
    font-size: 22px;
    font-weight: 750;
    letter-spacing: -0.02em;
  }

  .masthead p {
    font-size: 13px;
    color: var(--muted);
    margin-top: 2px;
  }

  .catalog-stat {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid rgba(29, 160, 195, 0.35);
    padding: 6px 10px;
    border-radius: 8px;
  }

  /* Filter toolbar */
  .toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 18px;
  }

  .search-box {
    flex: 1 1 210px;
    min-height: 44px;
    padding: 0 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    font-size: 14px;
    outline: none;
  }
  .search-box:focus { border-color: var(--accent); }

  .genre-pills {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .genre-pills::-webkit-scrollbar { display: none; }

  .genre-btn {
    min-height: 44px;
    padding: 0 13px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.14s;
  }
  .genre-btn:hover { color: var(--ink); }
  .genre-btn[aria-pressed="true"] {
    background: var(--accent);
    color: #081217;
    border-color: var(--accent);
  }

  /* Sticky Letter Sections */
  .directory {
    display: flex;
    flex-direction: column;
    gap: 18px;
  }

  .letter-section {
    scroll-margin-top: 12px;
  }

  .sticky-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px;
    background: rgba(17, 19, 23, 0.90);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
  }

  .sticky-letter {
    font-family: var(--mono);
    font-size: 16px;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: 0.04em;
  }

  .sticky-count {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--muted);
  }

  .artist-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  @media (min-width: 720px) {
    .artist-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }

  .artist-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.15s, border-color 0.15s;
  }
  .artist-card:hover {
    background: var(--surface-hover);
    border-color: rgba(29, 160, 195, 0.35);
  }

  .sleeve {
    width: 52px;
    height: 52px;
    border-radius: 8px;
    flex-shrink: 0;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.1);
  }

  .artist-info {
    flex: 1;
    min-width: 0;
  }

  .artist-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .artist-release {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
  }

  .artist-tags {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 5px;
    font-size: 11px;
    font-family: var(--mono);
  }

  .tag-genre {
    color: var(--accent);
    background: var(--accent-soft);
    padding: 2px 6px;
    border-radius: 5px;
  }
  .tag-city { color: var(--muted); }

  .save-btn {
    min-width: 44px;
    min-height: 44px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 16px;
    cursor: pointer;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    transition: all 0.14s;
  }
  .save-btn:hover { color: var(--ink); border-color: rgba(255,255,255,0.2); }
  .save-btn.saved { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

  /* Right-Edge Touch-Scrubbable Alphabet Index Rail */
  .index-rail {
    position: fixed;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 2px;
    border-radius: 999px;
    background: rgba(27, 31, 38, 0.86);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: ns-resize;
  }

  @media (min-width: 760px) {
    .index-rail { right: 16px; padding: 8px 4px; }
  }

  .index-letter {
    width: 28px;
    height: 19px;
    display: grid;
    place-items: center;
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 700;
    color: var(--muted);
    border-radius: 999px;
    transition: color 0.1s, background 0.1s, transform 0.1s;
    pointer-events: none;
  }

  .index-letter.has-items { color: var(--ink); }
  .index-letter.empty { opacity: 0.3; }
  .index-letter.active {
    background: var(--accent);
    color: #081217;
    transform: scale(1.15);
  }

  /* Floating Magnification Loupe Bubble */
  .loupe {
    position: fixed;
    right: 52px;
    top: 50%;
    width: 58px;
    height: 58px;
    border-radius: 50% 50% 6px 50%;
    transform: translateY(-50%) rotate(-45deg) scale(0.7);
    background: var(--accent);
    color: #071318;
    display: grid;
    place-items: center;
    box-shadow: 0 12px 30px rgba(29, 160, 195, 0.45);
    pointer-events: none;
    opacity: 0;
    z-index: 35;
    transition: opacity 0.14s, transform 0.14s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  }

  @media (min-width: 760px) {
    .loupe { right: 68px; }
  }

  .loupe.visible {
    opacity: 1;
    transform: translateY(-50%) rotate(-45deg) scale(1);
  }

  .loupe-char {
    transform: rotate(45deg);
    font-family: var(--mono);
    font-size: 26px;
    font-weight: 800;
  }

  .empty-dir {
    padding: 40px 20px;
    text-align: center;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 14px;
  }
</style>
</head>
<body>
  <div class="layout">
    <header class="masthead">
      <div class="brand-row">
        <div class="brand-mark" aria-hidden="true">
          <svg width="20" height="20" viewBox="0 0 24 24" fill="#081217">
            <polygon points="3,18 9,6 21,6 15,18"/>
          </svg>
        </div>
        <div>
          <h1>Independent Vinyl Catalog</h1>
          <p>Scrub the right-edge A–Z rail to jump across pressings</p>
        </div>
      </div>
      <div class="catalog-stat" id="catalogStat">28 ARTISTS · A–Z</div>
    </header>

    <div class="toolbar">
      <input id="searchInput" class="search-box" type="search" placeholder="Filter artists, pressings, or cities..." aria-label="Filter artist catalog">
      <div class="genre-pills" role="group" aria-label="Filter by genre">
        <button class="genre-btn" data-genre="all" aria-pressed="true">All</button>
        <button class="genre-btn" data-genre="Ambient" aria-pressed="false">Ambient</button>
        <button class="genre-btn" data-genre="Post-Punk" aria-pressed="false">Post-Punk</button>
        <button class="genre-btn" data-genre="Jazz" aria-pressed="false">Jazz</button>
        <button class="genre-btn" data-genre="Electronic" aria-pressed="false">Electronic</button>
      </div>
    </div>

    <main class="directory" id="directory"></main>
  </div>

  <nav class="index-rail" id="indexRail" aria-label="Alphabet Jump Index" tabindex="0"></nav>
  <div class="loupe" id="loupe" aria-hidden="true"><span class="loupe-char" id="loupeChar">A</span></div>

<script>
(() => {
  const ARTISTS = [
    { name: 'Alder & Moss', release: 'Stillwater Tapes (180g LP)', genre: 'Ambient', city: 'Portland', colors: ['#164e63','#0ea5e9','#e0f2fe'] },
    { name: 'Amina Kouri', release: 'Casablanca Nocturnes', genre: 'Jazz', city: 'Marseille', colors: ['#7c2d12','#f59e0b','#fef3c7'] },
    { name: 'Boreal Drift', release: 'Subzero Telemetry', genre: 'Electronic', city: 'Reykjavik', colors: ['#1e3a8a','#38bdf8','#f0f9ff'] },
    { name: 'Brutal Linen', release: 'Concrete Choirs', genre: 'Post-Punk', city: 'Manchester', colors: ['#3f3f46','#a1a1aa','#f4f4f5'] },
    { name: 'Cinder Block Club', release: 'Late Tram 7"', genre: 'Post-Punk', city: 'Glasgow', colors: ['#881337','#fb7185','#ffe4e6'] },
    { name: 'Daisuke Mori', release: 'Kyoto Rain Studies', genre: 'Ambient', city: 'Osaka', colors: ['#064e3b','#34d399','#d1fae5'] },
    { name: 'Elowen Quartet', release: 'Brass & Cedar', genre: 'Jazz', city: 'Bristol', colors: ['#78350f','#fbbf24','#fef9c3'] },
    { name: 'Feral Telemetry', release: 'Patchbay Ghost', genre: 'Electronic', city: 'Berlin', colors: ['#312e81','#818cf8','#e0e7ff'] },
    { name: 'Glass Harbor', release: 'Foghorn Echoes', genre: 'Ambient', city: 'Halifax', colors: ['#155e75','#22d3ee','#cffafe'] },
    { name: 'Halcyon Press', release: 'Mono Tape Vol. 3', genre: 'Electronic', city: 'Detroit', colors: ['#4c1d95','#c084fc','#f3e8ff'] },
    { name: 'Iona & The Static', release: 'Sodium Streetlights', genre: 'Post-Punk', city: 'Dublin', colors: ['#7f1d1d','#f87171','#fee2e2'] },
    { name: 'Juno Vermeer', release: 'Velvet Rhodes Sessions', genre: 'Jazz', city: 'Rotterdam', colors: ['#14532d','#4ade80','#dcfce7'] },
    { name: 'Kestrel Radio', release: 'Shortwave Winter', genre: 'Ambient', city: 'Oslo', colors: ['#0c4a6e','#7dd3fc','#e0f2fe'] },
    { name: 'Loom & Loom', release: 'Shuttle Rhythm 12"', genre: 'Electronic', city: 'Leeds', colors: ['#701a75','#e879f9','#fae8ff'] },
    { name: 'Maren Solberg', release: 'Fjord Harmonic', genre: 'Ambient', city: 'Bergen', colors: ['#134e4a','#2dd4bf','#ccfbf1'] },
    { name: 'Nadia Osei Trio', release: 'Accra Midnight', genre: 'Jazz', city: 'London', colors: ['#9a3412','#fb923c','#ffedd5'] },
    { name: 'Ochre Signals', release: 'Dust on the Needle', genre: 'Post-Punk', city: 'Melbourne', colors: ['#713f12','#eab308','#fef9c3'] },
    { name: 'Pale Concrete', release: 'Station Platform 9', genre: 'Post-Punk', city: 'Warsaw', colors: ['#27272a','#71717a','#e4e4e7'] },
    { name: 'Quarry Sound', release: 'Limestone Dubs', genre: 'Electronic', city: 'Sheffield', colors: ['#1e1b4b','#6366f1','#e0e7ff'] },
    { name: 'Riven Oak', release: 'Cello & Tape Loop', genre: 'Ambient', city: 'Montreal', colors: ['#365314','#a3e635','#ecfccb'] },
    { name: 'Sable Meridian', release: 'Blue Note Transit', genre: 'Jazz', city: 'Chicago', colors: ['#1e3a8a','#60a5fa','#dbeafe'] },
    { name: 'Taro Takahashi', release: 'Modular Tea House', genre: 'Electronic', city: 'Tokyo', colors: ['#0f766e','#5eead4','#f0fdfa'] },
    { name: 'Umber & Ash', release: 'Dry Heat EP', genre: 'Post-Punk', city: 'Tucson', colors: ['#7c2d12','#ea580c','#ffedd5'] },
    { name: 'Vespera Ensemble', release: 'Candlelight Sax', genre: 'Jazz', city: 'Vienna', colors: ['#581c87','#a855f7','#f3e8ff'] },
    { name: 'Wren Collective', release: 'Dawn Chorus Cassette', genre: 'Ambient', city: 'Edinburgh', colors: ['#065f46','#10b981','#d1fae5'] },
    { name: 'Xylo Circuit', release: 'Arpeggio Motel', genre: 'Electronic', city: 'Toronto', colors: ['#831843','#f472b6','#fce7f3'] },
    { name: 'Yuki & The Wire', release: 'Shibuya Feedback', genre: 'Post-Punk', city: 'Yokohama', colors: ['#991b1b','#ef4444','#fee2e2'] },
    { name: 'Zoraida Brass', release: 'Havana Dusk LP', genre: 'Jazz', city: 'Miami', colors: ['#92400e','#f59e0b','#fef3c7'] }
  ];

  const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
  const savedSet = new Set(['Alder & Moss', 'Nadia Osei Trio', 'Taro Takahashi']);

  let activeGenre = 'all';
  let searchQuery = '';
  let activeLetter = 'A';
  let availableLetters = new Set();

  const directoryEl = document.getElementById('directory');
  const railEl = document.getElementById('indexRail');
  const loupeEl = document.getElementById('loupe');
  const loupeChar = document.getElementById('loupeChar');
  const catalogStat = document.getElementById('catalogStat');

  function sleeveSvg([c1, c2, c3], idx) {
    return `
      <svg class="sleeve" viewBox="0 0 52 52" aria-hidden="true">
        <rect width="52" height="52" fill="${c1}"/>
        <circle cx="${16 + (idx * 9) % 24}" cy="${16 + (idx * 7) % 22}" r="18" fill="${c2}" opacity="0.82"/>
        <circle cx="26" cy="26" r="14" fill="none" stroke="${c3}" stroke-width="1.2" opacity="0.5"/>
        <circle cx="26" cy="26" r="3" fill="${c3}"/>
      </svg>
    `;
  }

  function renderRail() {
    railEl.innerHTML = '';
    ALPHABET.forEach(ch => {
      const span = document.createElement('span');
      const has = availableLetters.has(ch);
      span.className = `index-letter ${has ? 'has-items' : 'empty'}${ch === activeLetter ? ' active' : ''}`;
      span.dataset.letter = ch;
      span.textContent = ch;
      railEl.appendChild(span);
    });
  }

  function setActiveLetterUI(letter) {
    if (activeLetter === letter) return;
    activeLetter = letter;
    railEl.querySelectorAll('.index-letter').forEach(el => {
      el.classList.toggle('active', el.dataset.letter === letter);
    });
  }

  function renderDirectory() {
    const q = searchQuery.trim().toLowerCase();
    const filtered = ARTISTS.filter(a => {
      const genreOk = activeGenre === 'all' || a.genre === activeGenre;
      const queryOk = !q || `${a.name} ${a.release} ${a.city} ${a.genre}`.toLowerCase().includes(q);
      return genreOk && queryOk;
    });

    const grouped = new Map();
    filtered.forEach(a => {
      const ch = a.name[0].toUpperCase();
      if (!grouped.has(ch)) grouped.set(ch, []);
      grouped.get(ch).push(a);
    });

    availableLetters = new Set(grouped.keys());
    catalogStat.textContent = `${filtered.length} ARTISTS · ${availableLetters.size} SECTIONS`;

    directoryEl.innerHTML = '';
    if (filtered.length === 0) {
      directoryEl.innerHTML = `<div class="empty-dir">No vinyl pressings match your current filter.</div>`;
      renderRail();
      return;
    }

    let idx = 0;
    for (const ch of ALPHABET) {
      const items = grouped.get(ch);
      if (!items) continue;
      const section = document.createElement('section');
      section.className = 'letter-section';
      section.id = `sec-${ch}`;
      section.dataset.letter = ch;

      section.innerHTML = `
        <div class="sticky-header">
          <span class="sticky-letter">${ch}</span>
          <span class="sticky-count">${items.length} ${items.length === 1 ? 'PRESSING' : 'PRESSINGS'}</span>
        </div>
        <div class="artist-list"></div>
      `;

      const listEl = section.querySelector('.artist-list');
      items.forEach(artist => {
        idx++;
        const card = document.createElement('article');
        card.className = 'artist-card';
        const isSaved = savedSet.has(artist.name);
        card.innerHTML = `
          ${sleeveSvg(artist.colors, idx)}
          <div class="artist-info">
            <div class="artist-name">${artist.name}</div>
            <div class="artist-release">${artist.release}</div>
            <div class="artist-tags">
              <span class="tag-genre">${artist.genre}</span>
              <span class="tag-city">${artist.city}</span>
            </div>
          </div>
          <button class="save-btn${isSaved ? ' saved' : ''}" aria-label="Wishlist ${artist.name}" aria-pressed="${isSaved}">
            ${isSaved ? '★' : '☆'}
          </button>
        `;
        card.querySelector('.save-btn').addEventListener('click', e => {
          const btn = e.currentTarget;
          if (savedSet.has(artist.name)) savedSet.delete(artist.name);
          else savedSet.add(artist.name);
          const nowSaved = savedSet.has(artist.name);
          btn.classList.toggle('saved', nowSaved);
          btn.setAttribute('aria-pressed', String(nowSaved));
          btn.textContent = nowSaved ? '★' : '☆';
        });
        listEl.appendChild(card);
      });

      directoryEl.appendChild(section);
    }

    if (!availableLetters.has(activeLetter) && availableLetters.size > 0) {
      activeLetter = [...availableLetters][0];
    }
    renderRail();
  }

  // Scrubbing interaction on right-edge index rail
  let scrubbing = false;

  function jumpToClientY(clientY, smooth = false) {
    const rect = railEl.getBoundingClientRect();
    const ratio = Math.max(0, Math.min(0.9999, (clientY - rect.top) / rect.height));
    const idx = Math.floor(ratio * ALPHABET.length);
    const letter = ALPHABET[idx];

    // Position magnification loupe vertically aligned with finger/pointer
    const clampedY = Math.max(rect.top + 10, Math.min(rect.bottom - 10, clientY));
    loupeEl.style.top = `${clampedY}px`;
    loupeChar.textContent = letter;
    loupeEl.classList.add('visible');

    // Find exact or nearest available section
    let targetLetter = letter;
    if (!availableLetters.has(targetLetter) && availableLetters.size > 0) {
      let best = null, bestDist = 99;
      for (const ch of availableLetters) {
        const d = Math.abs(ch.charCodeAt(0) - letter.charCodeAt(0));
        if (d < bestDist) { bestDist = d; best = ch; }
      }
      targetLetter = best;
    }

    if (targetLetter) {
      setActiveLetterUI(targetLetter);
      const sec = document.getElementById(`sec-${targetLetter}`);
      if (sec) {
        sec.scrollIntoView({ behavior: smooth ? 'smooth' : 'auto', block: 'start' });
      }
    }
  }

  railEl.addEventListener('pointerdown', e => {
    scrubbing = true;
    railEl.setPointerCapture(e.pointerId);
    jumpToClientY(e.clientY, true);
  });

  railEl.addEventListener('pointermove', e => {
    if (!scrubbing) return;
    jumpToClientY(e.clientY, false);
  });

  const endScrub = () => {
    if (!scrubbing) return;
    scrubbing = false;
    setTimeout(() => { if (!scrubbing) loupeEl.classList.remove('visible'); }, 220);
  };
  railEl.addEventListener('pointerup', endScrub);
  railEl.addEventListener('pointercancel', endScrub);

  // Keyboard navigation on rail
  railEl.addEventListener('keydown', e => {
    const list = [...availableLetters];
    if (!list.length) return;
    const curIdx = Math.max(0, list.indexOf(activeLetter));
    if (e.key === 'ArrowDown') {
      e.preventDefault();
      const next = list[(curIdx + 1) % list.length];
      setActiveLetterUI(next);
      document.getElementById(`sec-${next}`)?.scrollIntoView({ behavior: 'smooth', block: 'start' });
    } else if (e.key === 'ArrowUp') {
      e.preventDefault();
      const prev = list[(curIdx - 1 + list.length) % list.length];
      setActiveLetterUI(prev);
      document.getElementById(`sec-${prev}`)?.scrollIntoView({ behavior: 'smooth', block: 'start' });
    }
  });

  // Sync active letter during normal page scroll
  let scrollTicking = false;
  window.addEventListener('scroll', () => {
    if (scrubbing || scrollTicking) return;
    scrollTicking = true;
    requestAnimationFrame(() => {
      const sections = document.querySelectorAll('.letter-section');
      let current = activeLetter;
      for (const sec of sections) {
        if (sec.getBoundingClientRect().top <= 64) current = sec.dataset.letter;
      }
      setActiveLetterUI(current);
      scrollTicking = false;
    });
  }, { passive: true });

  // Search & genre filters
  document.getElementById('searchInput').addEventListener('input', e => {
    searchQuery = e.target.value;
    renderDirectory();
  });

  document.querySelectorAll('.genre-btn').forEach(btn => {
    btn.addEventListener('click', () => {
      document.querySelectorAll('.genre-btn').forEach(b => b.setAttribute('aria-pressed', 'false'));
      btn.setAttribute('aria-pressed', 'true');
      activeGenre = btn.dataset.genre;
      renderDirectory();
    });
  });

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