#103 ui light mobile: native-first Maps & Spatial Discovery

Split Map + Peekable List Sheet

Bidirectionally synced map pins and peekable card list that transforms cleanly from mobile sheet to desktop split.

Inspired by AllTrails ↗

Download .html
Fullscreen ↗

WHY THIS AESTHETIC IS UNIQUE

Bridges geographic exploration and structured comparison by highlighting matching pins and cards in lockstep across both phone and desktop viewports.

BEST FOR

Outdoor & trail directoriesReal estate & hotel findersLocal store locatorsEvent & venue discovery

TAGS

COLOR PALETTE (CLICK TO COPY HEX)

TYPOGRAPHY

Display
Outfit
Body
Inter
Mono
JetBrains Mono
Scale
Scannable 16px trail titles paired with compact mono distance/elevation metrics and pill difficulty badges.

Google Fonts Stylesheet ↗

ARCHITECTURE & MOBILE NOTES

LAYOUT

Desktop displays a 55/45 split with persistent map on one side and scrollable cards on the other; mobile stacks a peekable draggable sheet over the full-height map.

INTERACTION

Selecting a map pin scrolls and highlights its corresponding card, while tapping a card centers and pulses its pin; difficulty chips filter both views simultaneously.

MOBILE

Quick Map/List toggle pill plus draggable sheet handle allow effortless switching on 390px screens without losing filter state.

AI AGENT GUARDRAILS

DO

  • Maintain bidirectional selection sync between map markers and list cards
  • Keep filter chips accessible above both the map and the list so counts stay visible
  • Render crisp inline SVG or canvas vector maps so markers never misalign across aspect ratios

DON'T

  • Do not force horizontal scrolling on mobile to see both map and list side by side
  • Do not reset map pan or active filters when collapsing the mobile sheet
STANDALONE SOURCE · demos/split-map-list-sheet.html (22.1 KB)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>RidgeLine — Split Topographic Map &amp; Peekable Trail Sheet</title>
<style>
  :root {
    --canvas: #F5F3EE;
    --surface: #FFFFFF;
    --surface-warm: #EDE9DF;
    --ink: #1B2A1F;
    --muted: #647067;
    --accent: #2D6A4F;
    --accent-light: #D8F3DC;
    --easy: #2D6A4F;
    --moderate: #B45309;
    --hard: #B91C1C;
    --border: #DDD8CC;
    --sheet-h: 46vh;
  }

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

  html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--canvas);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  }

  .layout {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  /* Top Header Bar */
  .topbar {
    height: 60px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    z-index: 30;
    flex-shrink: 0;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 800;
    font-size: 16px;
    letter-spacing: -0.02em;
    color: var(--ink);
  }

  .brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
  }

  .region-tag {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
    background: var(--canvas);
    padding: 6px 11px;
    border-radius: 999px;
    border: 1px solid var(--border);
    white-space: nowrap;
  }

  /* Main Split Container */
  .workspace {
    position: relative;
    flex: 1;
    min-height: 0;
    width: 100%;
  }

  /* Topographic Map Pane */
  .map-pane {
    position: absolute;
    inset: 0;
    background: #EAE6D9;
    overflow: hidden;
  }

  .topo-svg {
    width: 100%;
    height: 100%;
    display: block;
    user-select: none;
  }

  .trail-line {
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 4;
    opacity: 0.32;
    transition: opacity 0.22s ease, stroke-width 0.22s ease;
  }

  .trail-line.active {
    opacity: 1;
    stroke-width: 6.5;
    filter: drop-shadow(0 2px 5px rgba(27, 42, 31, 0.28));
  }

  .pin-group {
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .pin-pill {
    fill: #FFFFFF;
    stroke: #1B2A1F;
    stroke-width: 1.8;
    transition: fill 0.18s ease, stroke 0.18s ease;
  }

  .pin-text {
    fill: #1B2A1F;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    font-weight: 700;
    pointer-events: none;
  }

  .pin-group.active .pin-pill {
    fill: #2D6A4F;
    stroke: #FFFFFF;
    stroke-width: 2.2;
  }

  .pin-group.active .pin-text {
    fill: #FFFFFF;
  }

  .pin-group.hidden-pin {
    opacity: 0.18;
    pointer-events: none;
  }

  /* Floating Map Legend */
  .map-legend {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 14px rgba(27, 42, 31, 0.08);
    z-index: 10;
  }

  .map-legend strong {
    color: var(--ink);
  }

  /* Peekable List Sheet (Mobile) / Split List Pane (Desktop) */
  .list-sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--sheet-h);
    background: var(--surface);
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    border-top: 1px solid var(--border);
    box-shadow: 0 -10px 30px rgba(27, 42, 31, 0.14);
    display: flex;
    flex-direction: column;
    z-index: 20;
    transition: height 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .list-sheet.dragging {
    transition: none;
  }

  .sheet-handle-bar {
    padding: 10px 16px 8px;
    cursor: grab;
    touch-action: none;
    user-select: none;
    flex-shrink: 0;
  }

  .sheet-handle-bar:active {
    cursor: grabbing;
  }

  .pill-grab {
    width: 42px;
    height: 4.5px;
    border-radius: 999px;
    background: #C9C4B8;
    margin: 0 auto 10px;
  }

  .sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .sheet-head h1 {
    font-size: 16px;
    font-weight: 700;
  }

  .peek-toggle {
    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: 600;
    cursor: pointer;
  }

  /* Difficulty Filters */
  .filters {
    display: flex;
    gap: 7px;
    padding: 4px 16px 12px;
    overflow-x: auto;
    scrollbar-width: none;
    border-bottom: 1px solid #EFECE4;
    flex-shrink: 0;
  }

  .filters::-webkit-scrollbar {
    display: none;
  }

  .filter-chip {
    min-height: 36px;
    padding: 0 13px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
  }

  .filter-chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
  }

  /* Trail Cards */
  .trail-list {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .trail-card {
    border: 1.5px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    padding: 13px 14px;
    cursor: pointer;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  }

  .trail-card:hover {
    border-color: #A3BEA8;
  }

  .trail-card.active {
    border-color: var(--accent);
    background: #F9FCF9;
    box-shadow: 0 4px 18px rgba(45, 106, 79, 0.13);
  }

  .card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
  }

  .trail-name {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.25;
  }

  .trail-area {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
  }

  .save-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--canvas);
    color: var(--muted);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: all 0.15s ease;
  }

  .save-btn.saved {
    background: #FEE2E2;
    border-color: #FCA5A5;
    color: #DC2626;
  }

  .stats-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 12px;
    color: var(--muted);
  }

  .diff-pill {
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  .diff-easy { background: #DCFCE7; color: #166534; }
  .diff-moderate { background: #FEF3C7; color: #92400E; }
  .diff-hard { background: #FEE2E2; color: #991B1B; }

  .mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 600;
    color: var(--ink);
  }

  /* Elevation Sparkline */
  .spark-box {
    background: var(--canvas);
    border-radius: 10px;
    padding: 7px 10px 5px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .spark-svg {
    flex: 1;
    height: 30px;
    overflow: visible;
  }

  .spark-label {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
  }

  /* Desktop 55/45 Split Layout */
  @media (min-width: 960px) {
    .workspace {
      display: grid;
      grid-template-columns: 55% 45%;
    }

    .map-pane {
      position: relative;
      inset: auto;
      height: 100%;
      border-right: 1px solid var(--border);
    }

    .list-sheet {
      position: relative;
      inset: auto;
      height: 100% !important;
      border-radius: 0;
      border-top: none;
      box-shadow: none;
    }

    .pill-grab,
    .peek-toggle {
      display: none;
    }

    .sheet-handle-bar {
      cursor: default;
      padding: 16px 20px 10px;
    }

    .filters {
      padding: 4px 20px 14px;
    }

    .trail-list {
      padding: 14px 20px 28px;
    }
  }
</style>
</head>
<body>
<div class="layout">
  <header class="topbar">
    <div class="brand">
      <span class="brand-mark" aria-hidden="true">
        <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M3 19l6-11 4 7 3-5 5 9H3z"/></svg>
      </span>
      RidgeLine
    </div>
    <span class="region-tag">Cascade Foothills &middot; 5 Trails</span>
  </header>

  <div class="workspace">
    <!-- Topographic Map -->
    <section class="map-pane" aria-label="Interactive topographic trail map">
      <div class="map-legend">
        <strong id="selectedTrailBanner">Eagle Crest Loop</strong>
        <span id="selectedGainBanner">+1,180 ft</span>
      </div>

      <svg id="topoSvg" class="topo-svg" viewBox="0 0 760 620" preserveAspectRatio="xMidYMid slice">
        <!-- Base terrain -->
        <rect width="760" height="620" fill="#EBE7DA"/>

        <!-- Topographic contour rings -->
        <g fill="none" stroke="#D5CEBC" stroke-width="1.4">
          <ellipse cx="210" cy="180" rx="190" ry="125" transform="rotate(-14 210 180)"/>
          <ellipse cx="210" cy="180" rx="145" ry="92" transform="rotate(-14 210 180)"/>
          <ellipse cx="210" cy="180" rx="95" ry="58" transform="rotate(-14 210 180)"/>
          <ellipse cx="210" cy="180" rx="48" ry="28" transform="rotate(-14 210 180)"/>

          <ellipse cx="560" cy="430" rx="220" ry="145" transform="rotate(18 560 430)"/>
          <ellipse cx="560" cy="430" rx="168" ry="108" transform="rotate(18 560 430)"/>
          <ellipse cx="560" cy="430" rx="112" ry="70" transform="rotate(18 560 430)"/>
          <ellipse cx="560" cy="430" rx="58" ry="34" transform="rotate(18 560 430)"/>

          <ellipse cx="585" cy="155" rx="140" ry="88" transform="rotate(-22 585 155)"/>
          <ellipse cx="585" cy="155" rx="92" ry="55" transform="rotate(-22 585 155)"/>
          <ellipse cx="585" cy="155" rx="44" ry="25" transform="rotate(-22 585 155)"/>
        </g>

        <!-- Forest patches -->
        <path d="M40 420 Q135 370 215 445 Q235 535 120 565 Q30 530 40 420 Z" fill="#DDE6D5" opacity="0.7"/>
        <path d="M420 65 Q530 35 645 95 Q675 185 570 220 Q450 185 420 65 Z" fill="#DDE6D5" opacity="0.65"/>

        <!-- Alpine Lake & Creek -->
        <path d="M315 265 Q360 238 408 272 Q420 315 368 332 Q305 320 315 265 Z" fill="#BDD8E8" stroke="#99BFD6" stroke-width="2"/>
        <path d="M355 330 C340 390, 290 445, 250 620" fill="none" stroke="#BDD8E8" stroke-width="5" stroke-linecap="round"/>

        <!-- Trail Paths -->
        <path id="trail-eagle" class="trail-line active" stroke="#2D6A4F" d="M160 210 C175 140, 265 130, 278 195 C288 242, 200 255, 160 210 Z"/>
        <path id="trail-mirror" class="trail-line" stroke="#2D6A4F" d="M295 280 C325 225, 420 228, 430 295 C435 342, 345 358, 295 280 Z"/>
        <path id="trail-granite" class="trail-line" stroke="#B91C1C" d="M465 445 C495 365, 625 355, 650 435 C665 495, 535 520, 465 445 Z"/>
        <path id="trail-cedar" class="trail-line" stroke="#B45309" d="M95 455 Q150 415 225 470 T295 520"/>
        <path id="trail-skyline" class="trail-line" stroke="#B91C1C" d="M495 160 C530 105, 640 100, 665 168 C640 205, 545 208, 495 160 Z"/>

        <!-- Interactive Elevation Pins -->
        <g id="pinsLayer"></g>
      </svg>
    </section>

    <!-- Peekable Bottom Sheet (Mobile) / Right List Pane (Desktop) -->
    <section id="listSheet" class="list-sheet" aria-label="Trail list">
      <div id="sheetHandle" class="sheet-handle-bar">
        <div class="pill-grab"></div>
        <div class="sheet-head">
          <h1 id="resultHeading">5 Trails Nearby</h1>
          <button id="peekToggle" class="peek-toggle" type="button">Expand List</button>
        </div>
      </div>

      <div class="filters" role="tablist" aria-label="Filter trails by difficulty">
        <button class="filter-chip active" data-diff="all" type="button">All</button>
        <button class="filter-chip" data-diff="Easy" type="button">Easy</button>
        <button class="filter-chip" data-diff="Moderate" type="button">Moderate</button>
        <button class="filter-chip" data-diff="Hard" type="button">Hard</button>
        <button class="filter-chip" data-diff="saved" type="button">Saved</button>
      </div>

      <div id="trailList" class="trail-list"></div>
    </section>
  </div>
</div>

<script>
(() => {
  const TRAILS = [
    {
      id: 'eagle',
      name: 'Eagle Crest Loop',
      area: 'North Ridge Wilderness',
      difficulty: 'Moderate',
      distance: '4.8 mi',
      gain: '+1,180 ft',
      time: '2h 15m',
      rating: '4.8',
      reviews: 412,
      pin: { x: 215, y: 185 },
      profile: [18, 22, 29, 36, 48, 54, 46, 38, 26, 20]
    },
    {
      id: 'mirror',
      name: 'Mirror Tarn Boardwalk',
      area: 'Glacier Basin Park',
      difficulty: 'Easy',
      distance: '2.6 mi',
      gain: '+420 ft',
      time: '1h 05m',
      rating: '4.9',
      reviews: 628,
      pin: { x: 365, y: 290 },
      profile: [24, 26, 28, 30, 31, 30, 28, 27, 25, 24]
    },
    {
      id: 'granite',
      name: 'Granite Spire Traverse',
      area: 'South Summit Reserve',
      difficulty: 'Hard',
      distance: '7.4 mi',
      gain: '+2,040 ft',
      time: '4h 10m',
      rating: '4.9',
      reviews: 194,
      pin: { x: 560, y: 432 },
      profile: [12, 18, 28, 42, 58, 66, 60, 44, 24, 14]
    },
    {
      id: 'cedar',
      name: 'Cedar Creek Canyon',
      area: 'Lower Valley Trailhead',
      difficulty: 'Easy',
      distance: '3.4 mi',
      gain: '+640 ft',
      time: '1h 30m',
      rating: '4.6',
      reviews: 285,
      pin: { x: 185, y: 472 },
      profile: [16, 20, 25, 32, 34, 30, 28, 24, 20, 17]
    },
    {
      id: 'skyline',
      name: 'Skyline Saddle Spur',
      area: 'East Alpine Crest',
      difficulty: 'Hard',
      distance: '6.1 mi',
      gain: '+1,520 ft',
      time: '3h 20m',
      rating: '4.7',
      reviews: 158,
      pin: { x: 580, y: 155 },
      profile: [15, 24, 38, 48, 56, 52, 46, 36, 22, 16]
    }
  ];

  const pinsLayer = document.getElementById('pinsLayer');
  const trailList = document.getElementById('trailList');
  const listSheet = document.getElementById('listSheet');
  const sheetHandle = document.getElementById('sheetHandle');
  const peekToggle = document.getElementById('peekToggle');
  const resultHeading = document.getElementById('resultHeading');
  const selectedTrailBanner = document.getElementById('selectedTrailBanner');
  const selectedGainBanner = document.getElementById('selectedGainBanner');

  let selectedId = 'eagle';
  let activeFilter = 'all';
  let savedIds = new Set(['mirror']);
  let sheetExpanded = false;

  function buildSparkline(points, active) {
    const w = 160;
    const h = 30;
    const max = 70;
    const step = w / (points.length - 1);
    const coords = points.map((v, i) => [i * step, h - (v / max) * (h - 4) - 2]);
    const lineD = coords.map((p, i) => `${i === 0 ? 'M' : 'L'}${p[0].toFixed(1)} ${p[1].toFixed(1)}`).join(' ');
    const areaD = `${lineD} L${w} ${h} L0 ${h} Z`;
    const stroke = active ? '#2D6A4F' : '#647067';
    const fill = active ? 'rgba(45, 106, 79, 0.18)' : 'rgba(100, 112, 103, 0.14)';
    return `
      <svg class="spark-svg" viewBox="0 0 ${w} ${h}" preserveAspectRatio="none" aria-hidden="true">
        <path d="${areaD}" fill="${fill}"/>
        <path d="${lineD}" fill="none" stroke="${stroke}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
      </svg>
    `;
  }

  function getFilteredTrails() {
    if (activeFilter === 'all') return TRAILS;
    if (activeFilter === 'saved') return TRAILS.filter(t => savedIds.has(t.id));
    return TRAILS.filter(t => t.difficulty === activeFilter);
  }

  function syncMap() {
    const visibleIds = new Set(getFilteredTrails().map(t => t.id));
    TRAILS.forEach(t => {
      const path = document.getElementById(`trail-${t.id}`);
      if (path) {
        path.classList.toggle('active', t.id === selectedId);
        path.style.display = visibleIds.has(t.id) ? '' : 'none';
      }
    });

    pinsLayer.innerHTML = TRAILS.map(t => {
      const isAct = t.id === selectedId;
      const hidden = !visibleIds.has(t.id);
      return `
        <g class="pin-group ${isAct ? 'active' : ''} ${hidden ? 'hidden-pin' : ''}"
           data-pin-id="${t.id}"
           transform="translate(${t.pin.x}, ${t.pin.y})"
           role="button" tabindex="0" aria-label="${t.name}, elevation gain ${t.gain}">
          <rect class="pin-pill" x="-36" y="-15" width="72" height="26" rx="13"/>
          <text class="pin-text" x="0" y="2" text-anchor="middle">${t.gain}</text>
        </g>
      `;
    }).join('');

    const sel = TRAILS.find(t => t.id === selectedId);
    if (sel) {
      selectedTrailBanner.textContent = sel.name;
      selectedGainBanner.textContent = `${sel.distance} · ${sel.gain}`;
    }
  }

  function renderList() {
    const items = getFilteredTrails();
    resultHeading.textContent = `${items.length} Trail${items.length === 1 ? '' : 's'} Nearby`;

    if (!items.length) {
      trailList.innerHTML = `<div style="padding:28px 12px;text-align:center;color:#647067;font-size:14px;">No trails match this filter yet. Tap a heart icon to save favorites.</div>`;
      return;
    }

    trailList.innerHTML = items.map(t => {
      const isAct = t.id === selectedId;
      const isSaved = savedIds.has(t.id);
      const diffCls = t.difficulty === 'Easy' ? 'diff-easy' : t.difficulty === 'Moderate' ? 'diff-moderate' : 'diff-hard';
      return `
        <article class="trail-card ${isAct ? 'active' : ''}" data-card-id="${t.id}" tabindex="0">
          <div class="card-top">
            <div>
              <div class="trail-name">${t.name}</div>
              <div class="trail-area">${t.area} &middot; ★ ${t.rating} (${t.reviews})</div>
            </div>
            <button class="save-btn ${isSaved ? 'saved' : ''}" data-save-id="${t.id}" type="button" aria-label="Save ${t.name}" aria-pressed="${isSaved}">
              <svg width="18" height="18" viewBox="0 0 24 24" fill="${isSaved ? 'currentColor' : 'none'}" stroke="currentColor" stroke-width="2.1">
                <path d="M20.8 4.6a5.5 5.5 0 0 0-7.8 0L12 5.7l-1-1.1a5.5 5.5 0 0 0-7.8 7.8l1 1.1L12 21l7.8-7.5 1-1.1a5.5 5.5 0 0 0 0-7.8z"/>
              </svg>
            </button>
          </div>
          <div class="stats-row">
            <span class="diff-pill ${diffCls}">${t.difficulty}</span>
            <span class="mono">${t.distance}</span>
            <span>&middot;</span>
            <span class="mono">${t.gain}</span>
            <span>&middot;</span>
            <span>Est. ${t.time}</span>
          </div>
          <div class="spark-box">
            ${buildSparkline(t.profile, isAct)}
            <span class="spark-label">Elev. Profile</span>
          </div>
        </article>
      `;
    }).join('');
  }

  function selectTrail(id, scrollCard = false) {
    selectedId = id;
    syncMap();
    renderList();
    if (scrollCard) {
      const card = trailList.querySelector(`[data-card-id="${id}"]`);
      if (card) card.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
    }
  }

  // Bidirectional sync: Map pin -> List card
  pinsLayer.addEventListener('click', (e) => {
    const pin = e.target.closest('[data-pin-id]');
    if (!pin) return;
    selectTrail(pin.dataset.pinId, true);
  });

  // Bidirectional sync: List card -> Map pin
  trailList.addEventListener('click', (e) => {
    const saveBtn = e.target.closest('[data-save-id]');
    if (saveBtn) {
      e.stopPropagation();
      const id = saveBtn.dataset.saveId;
      if (savedIds.has(id)) savedIds.delete(id);
      else savedIds.add(id);
      renderList();
      syncMap();
      return;
    }
    const card = e.target.closest('[data-card-id]');
    if (!card) return;
    selectTrail(card.dataset.cardId, false);
  });

  // Filter chips
  document.querySelectorAll('.filter-chip').forEach(chip => {
    chip.addEventListener('click', () => {
      activeFilter = chip.dataset.diff;
      document.querySelectorAll('.filter-chip').forEach(c => c.classList.toggle('active', c === chip));
      const items = getFilteredTrails();
      if (items.length && !items.some(t => t.id === selectedId)) {
        selectedId = items[0].id;
      }
      syncMap();
      renderList();
    });
  });

  // Mobile sheet peek / expand toggle & pointer drag
  function setMobileSheet(expanded) {
    sheetExpanded = expanded;
    listSheet.style.setProperty('--sheet-h', expanded ? '70vh' : '30vh');
    peekToggle.textContent = expanded ? 'Show Map' : 'Expand List';
  }

  peekToggle.addEventListener('click', () => setMobileSheet(!sheetExpanded));

  let dragging = false;
  let startY = 0;
  let startH = 0;

  sheetHandle.addEventListener('pointerdown', (e) => {
    if (window.innerWidth >= 960 || e.target.closest('.peek-toggle')) return;
    dragging = true;
    startY = e.clientY;
    startH = listSheet.getBoundingClientRect().height;
    listSheet.classList.add('dragging');
    sheetHandle.setPointerCapture(e.pointerId);
  });

  sheetHandle.addEventListener('pointermove', (e) => {
    if (!dragging) return;
    const vh = window.innerHeight;
    const nextH = Math.max(vh * 0.22, Math.min(vh * 0.78, startH + (startY - e.clientY)));
    listSheet.style.setProperty('--sheet-h', `${(nextH / vh) * 100}vh`);
  });

  function endDrag() {
    if (!dragging) return;
    dragging = false;
    listSheet.classList.remove('dragging');
    const pct = (listSheet.getBoundingClientRect().height / window.innerHeight) * 100;
    setMobileSheet(pct > 48);
  }

  sheetHandle.addEventListener('pointerup', endDrag);
  sheetHandle.addEventListener('pointercancel', endDrag);

  syncMap();
  renderList();
})();
</script>
</body>
</html>