#110 ui light mobile: native-first Navigation & Docks

Nested Drill-Down Navigation Stack with Swipe-Back

Three-level hierarchical navigation stack with animated push/pop slide transitions and native-feeling edge swipe-back.

Inspired by OmniFocus ↗

Download .html
Fullscreen ↗

WHY THIS AESTHETIC IS UNIQUE

Brings crisp native iOS-style hierarchical clarity to the web so deep trees (Areas → Projects → Task Detail) stay effortless on small screens.

BEST FOR

Task & project managersMobile settings & preferencesNested knowledge basesDirectory & catalog browsers

TAGS

COLOR PALETTE (CLICK TO COPY HEX)

TYPOGRAPHY

Display
Plus Jakarta Sans
Body
Inter
Mono
JetBrains Mono
Scale
Clear 20px view titles, 15px list rows with right chevrons, and subtle 12px completion count badges.

Google Fonts Stylesheet ↗

ARCHITECTURE & MOBILE NOTES

LAYOUT

Single-pane animated stack on mobile with top back button + breadcrumb trail, expanding cleanly into a framed multi-level workspace on desktop.

INTERACTION

Tapping a row slides the child panel in from the right; dragging from the left edge (or tapping Back / pressing Escape) interactively scrubs and pops back one level.

MOBILE

Includes both a >=44px back button and an interactive left-edge swipe-back gesture with subtle parallax on the underlying parent view.

AI AGENT GUARDRAILS

DO

  • Always pair swipe-back gestures with a visible top-left Back button labeling the parent view
  • Preserve scroll position and state of parent levels when popping back up the stack
  • Keep stack depth to 3-4 levels max to avoid disorienting deep tunnels

DON'T

  • Do not use abrupt instant swaps without directional slide cues that show parent/child hierarchy
  • Do not trigger swipe-back from the middle of horizontal sliders or text inputs
STANDALONE SOURCE · demos/nested-drilldown-swipe-stack.html (25.6 KB)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Clearlist — Nested Drill-Down Stack with Swipe-Back</title>
<style>
  :root {
    --canvas: #F2F4F7;
    --surface: #FFFFFF;
    --ink: #111827;
    --accent: #0EA5E9;
    --accent-soft: #E0F2FE;
    --muted: #6B7280;
    --border: #E5E7EB;
    --high: #EF4444;
    --med: #F59E0B;
    --low: #10B981;
    --radius: 16px;
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  }

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

  html, body {
    height: 100%;
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--font);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    overflow-x: clip;
  }

  .app-frame {
    max-width: 740px;
    margin: 0 auto;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 12px 12px 24px;
  }

  @media (min-width: 768px) {
    .app-frame {
      padding: 28px 20px 40px;
    }
  }

  /* Header & Breadcrumbs */
  .nav-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    z-index: 10;
  }

  .back-btn {
    min-height: 44px;
    padding: 0 12px 0 8px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 650;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background 0.15s, opacity 0.15s;
  }

  .back-btn:hover { background: var(--accent-soft); }
  .back-btn.invisible { opacity: 0; pointer-events: none; }

  .breadcrumbs {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    color: var(--muted);
    overflow: hidden;
    white-space: nowrap;
  }

  .crumb-btn {
    border: none;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 5px;
    border-radius: 6px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .crumb-btn:hover { background: var(--canvas); color: var(--ink); }
  .crumb-btn.current { color: var(--ink); font-weight: 700; cursor: default; }

  .depth-pill {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--muted);
    background: var(--canvas);
    padding: 4px 9px;
    border-radius: 999px;
    flex-shrink: 0;
  }

  /* Stack Viewport */
  .stack-viewport {
    position: relative;
    flex: 1;
    min-height: 540px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(17, 24, 39, 0.06);
    touch-action: pan-y;
  }

  .stack-panel {
    position: absolute;
    inset: 0;
    background: var(--surface);
    overflow-y: auto;
    padding: 18px 16px 28px;
    will-change: transform;
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.32s;
  }

  .stack-panel.no-anim {
    transition: none !important;
  }

  .stack-panel.state-active {
    transform: translate3d(0, 0, 0);
    z-index: 3;
    box-shadow: -8px 0 24px rgba(17, 24, 39, 0.09);
  }

  .stack-panel.state-behind {
    transform: translate3d(-24%, 0, 0);
    z-index: 1;
    pointer-events: none;
    filter: brightness(0.96);
  }

  .stack-panel.state-right {
    transform: translate3d(100%, 0, 0);
    z-index: 4;
    pointer-events: none;
  }

  .swipe-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 12px;
    font-size: 0.78rem;
    color: var(--muted);
  }

  /* Panel Content Typography */
  .panel-header {
    margin-bottom: 16px;
  }

  .panel-kicker {
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent);
    margin-bottom: 3px;
  }

  .panel-title {
    font-size: 1.38rem;
    font-weight: 750;
    letter-spacing: -0.02em;
  }

  .panel-sub {
    font-size: 0.84rem;
    color: var(--muted);
    margin-top: 2px;
  }

  /* Area & Project Rows */
  .list-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .drill-row {
    width: 100%;
    min-height: 64px;
    padding: 13px 14px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: #F9FAFB;
    color: var(--ink);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    transition: background 0.15s, border-color 0.15s, transform 0.12s;
  }

  .drill-row:hover {
    background: #FFFFFF;
    border-color: #BAE6FD;
  }

  .drill-row:active {
    transform: scale(0.99);
  }

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

  .area-icon {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
  }

  .row-text {
    min-width: 0;
  }

  .row-text strong {
    display: block;
    font-size: 0.95rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .row-text span {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
  }

  .row-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    color: var(--muted);
  }

  .count-badge {
    font-size: 0.78rem;
    font-weight: 700;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--ink);
    padding: 3px 9px;
    border-radius: 999px;
  }

  /* Task Rows (Level 1) */
  .progress-bar-wrap {
    height: 6px;
    background: var(--canvas);
    border-radius: 999px;
    overflow: hidden;
    margin: 10px 0 18px;
  }

  .progress-bar-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.25s ease;
  }

  .task-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px 6px 4px;
    border-radius: 13px;
    border: 1px solid var(--border);
    background: var(--surface);
    transition: border-color 0.15s, background 0.15s;
  }

  .task-item:hover { border-color: #CBD5E1; }
  .task-item.done { background: #F9FAFB; opacity: 0.78; }

  .chk-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: grid;
    place-items: center;
    flex-shrink: 0;
  }

  .chk-circle {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid #CBD5E1;
    display: grid;
    place-items: center;
    transition: all 0.15s;
  }

  .task-item.done .chk-circle {
    background: var(--accent);
    border-color: var(--accent);
    color: #FFFFFF;
  }

  .task-body-btn {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    border: none;
    background: transparent;
    text-align: left;
    font-family: inherit;
    cursor: pointer;
    padding: 6px 4px;
  }

  .task-title {
    display: block;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--ink);
  }

  .task-item.done .task-title {
    text-decoration: line-through;
    color: var(--muted);
  }

  .task-meta {
    font-size: 0.74rem;
    color: var(--muted);
  }

  .prio-dot-btn {
    min-width: 44px;
    min-height: 44px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: grid;
    place-items: center;
    flex-shrink: 0;
  }

  .prio-pill {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 999px;
    text-transform: uppercase;
  }

  .prio-high { background: #FEE2E2; color: #DC2626; }
  .prio-med { background: #FEF3C7; color: #D97706; }
  .prio-low { background: #D1FAE5; color: #059669; }

  .quick-add {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
  }

  .quick-input {
    flex: 1;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 11px;
    border: 1px solid var(--border);
    background: var(--canvas);
    color: var(--ink);
    font-size: 0.88rem;
    font-family: inherit;
  }

  .quick-input:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--accent);
  }

  .quick-btn {
    min-height: 44px;
    padding: 0 14px;
    border: none;
    border-radius: 11px;
    background: var(--accent);
    color: #FFFFFF;
    font-weight: 700;
    font-size: 0.84rem;
    cursor: pointer;
  }

  /* Task Detail (Level 2) */
  .detail-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .detail-hero {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px;
    border-radius: 14px;
    background: #F9FAFB;
    border: 1px solid var(--border);
  }

  .detail-hero h2 {
    font-size: 1.15rem;
    font-weight: 750;
    margin-bottom: 4px;
  }

  .section-label {
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 8px;
  }

  .seg-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }

  .seg-pill {
    min-height: 44px;
    padding: 0 14px;
    border-radius: 10px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    font-size: 0.83rem;
    font-weight: 650;
    font-family: inherit;
    cursor: pointer;
  }

  .seg-pill.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: #0369A1;
  }

  .notes-area {
    width: 100%;
    min-height: 110px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #F9FAFB;
    color: var(--ink);
    font-size: 0.9rem;
    font-family: inherit;
    resize: vertical;
  }

  .notes-area:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--accent);
  }
</style>
</head>
<body>
<div class="app-frame">
  <header class="nav-bar">
    <button id="btnBack" class="back-btn invisible" type="button">
      <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>
      <span id="backLabel">Back</span>
    </button>
    <nav id="breadcrumbs" class="breadcrumbs" aria-label="Breadcrumb"></nav>
    <span id="depthPill" class="depth-pill">Level 1/3</span>
  </header>

  <main id="stackViewport" class="stack-viewport">
    <section id="panel0" class="stack-panel state-active" aria-label="Areas"></section>
    <section id="panel1" class="stack-panel state-right" aria-label="Projects and Tasks"></section>
    <section id="panel2" class="stack-panel state-right" aria-label="Task Detail"></section>
  </main>

  <div class="swipe-hint">
    <span>Tip: Swipe right anywhere on a nested panel (or press <strong>Esc</strong>) to pop back a level.</span>
  </div>
</div>

<script>
(function () {
  const DATA = [
    {
      id: "work", name: "Product & Work", color: "#0EA5E9", bg: "#E0F2FE",
      projects: [
        {
          id: "p1", name: "Q3 Mobile Launch", due: "Jun 18",
          tasks: [
            { id: "t1", title: "Finalize onboarding empty states", done: true, priority: "high", due: "Today", notes: "Confirm dark-mode contrast ratios and SVG illustration weights before handoff." },
            { id: "t2", title: "Audit 390px touch targets on settings", done: false, priority: "high", due: "Today", notes: "Every toggle row needs at least 44px vertical hit height." },
            { id: "t3", title: "Write release notes for beta testers", done: false, priority: "med", due: "Tomorrow", notes: "Highlight offline sync and new swipe-back navigation." }
          ]
        },
        {
          id: "p2", name: "Design System v2", due: "Jul 02",
          tasks: [
            { id: "t4", title: "Consolidate spacing scale tokens", done: false, priority: "med", due: "Next Week", notes: "Align 4pt grid across web and iOS tokens." },
            { id: "t5", title: "Document focus-ring accessibility spec", done: true, priority: "low", due: "Today", notes: "2px solid offset outline with 3:1 minimum contrast." }
          ]
        }
      ]
    },
    {
      id: "home", name: "Home & Travel", color: "#10B981", bg: "#D1FAE5",
      projects: [
        {
          id: "p3", name: "Lisbon Autumn Trip", due: "Sep 12",
          tasks: [
            { id: "t6", title: "Book boutique stay in Alfama", done: false, priority: "high", due: "Tomorrow", notes: "Look for balcony terrace and fast Wi-Fi." },
            { id: "t7", title: "Reserve train tickets to Porto", done: false, priority: "low", due: "Next Week", notes: "Alfa Pendular morning departure." }
          ]
        }
      ]
    },
    {
      id: "craft", name: "Studio Craft", color: "#8B5CF6", bg: "#EDE9FE",
      projects: [
        {
          id: "p4", name: "Analog Photo Zine", due: "Aug 05",
          tasks: [
            { id: "t8", title: "Scan 35mm Portra 400 contact sheets", done: false, priority: "med", due: "Tomorrow", notes: "Select 24 frames for Issue 04 sequence." },
            { id: "t9", title: "Test uncoated 120gsm paper stock", done: true, priority: "low", due: "Today", notes: "Local print shop confirmed matte warm white." }
          ]
        }
      ]
    }
  ];

  const PRIO_ORDER = ["low", "med", "high"];
  const state = {
    level: 0, // 0 = Areas, 1 = Project Tasks, 2 = Task Detail
    areaId: null,
    projectId: null,
    taskId: null
  };

  const els = {
    viewport: document.getElementById("stackViewport"),
    panels: [document.getElementById("panel0"), document.getElementById("panel1"), document.getElementById("panel2")],
    btnBack: document.getElementById("btnBack"),
    backLabel: document.getElementById("backLabel"),
    breadcrumbs: document.getElementById("breadcrumbs"),
    depthPill: document.getElementById("depthPill")
  };

  function getArea() { return DATA.find((a) => a.id === state.areaId); }
  function getProject() { const a = getArea(); return a && a.projects.find((p) => p.id === state.projectId); }
  function getTask() { const p = getProject(); return p && p.tasks.find((t) => t.id === state.taskId); }

  function updatePanelClasses() {
    els.panels.forEach((p, idx) => {
      p.classList.remove("state-active", "state-behind", "state-right");
      p.style.transform = "";
      if (idx === state.level) p.classList.add("state-active");
      else if (idx < state.level) p.classList.add("state-behind");
      else p.classList.add("state-right");
    });
  }

  function renderHeader() {
    const area = getArea();
    const proj = getProject();
    const task = getTask();

    els.depthPill.textContent = `Level ${state.level + 1}/3`;
    els.btnBack.classList.toggle("invisible", state.level === 0);
    els.backLabel.textContent = state.level === 1 ? "Areas" : (proj ? proj.name.slice(0, 14) : "Back");

    const crumbs = [`<button class="crumb-btn ${state.level === 0 ? "current" : ""}" data-level="0" type="button">Areas</button>`];
    if (state.level >= 1 && proj) {
      crumbs.push(`<span>/</span><button class="crumb-btn ${state.level === 1 ? "current" : ""}" data-level="1" type="button">${proj.name}</button>`);
    }
    if (state.level === 2 && task) {
      crumbs.push(`<span>/</span><span class="crumb-btn current">Task</span>`);
    }
    els.breadcrumbs.innerHTML = crumbs.join("");
  }

  function renderLevel0() {
    els.panels[0].innerHTML = `
      <div class="panel-header">
        <div class="panel-kicker">Workspace</div>
        <h1 class="panel-title">Areas &amp; Projects</h1>
        <p class="panel-sub">Drill into any project to manage tasks and inspect details.</p>
      </div>
      <div class="list-group">
        ${DATA.map((area) => `
          <div style="margin-bottom:8px">
            <div class="section-label" style="display:flex;align-items:center;gap:6px;margin-bottom:8px">
              <span style="width:9px;height:9px;border-radius:50%;background:${area.color};display:inline-block"></span>
              ${area.name}
            </div>
            <div class="list-group">
              ${area.projects.map((proj) => {
                const open = proj.tasks.filter((t) => !t.done).length;
                return `
                  <button class="drill-row" data-open-project="${area.id}:${proj.id}" type="button">
                    <div class="row-left">
                      <div class="area-icon" style="background:${area.bg};color:${area.color}">
                        <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/></svg>
                      </div>
                      <div class="row-text">
                        <strong>${proj.name}</strong>
                        <span>Due ${proj.due} &middot; ${proj.tasks.length} tasks</span>
                      </div>
                    </div>
                    <div class="row-right">
                      <span class="count-badge">${open} left</span>
                      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><polyline points="9 18 15 12 9 6"/></svg>
                    </div>
                  </button>
                `;
              }).join("")}
            </div>
          </div>
        `).join("")}
      </div>
    `;
  }

  function renderLevel1() {
    const area = getArea();
    const proj = getProject();
    if (!proj) return;
    const total = proj.tasks.length;
    const done = proj.tasks.filter((t) => t.done).length;
    const pct = total ? Math.round((done / total) * 100) : 0;

    els.panels[1].innerHTML = `
      <div class="panel-header">
        <div class="panel-kicker" style="color:${area.color}">${area.name}</div>
        <h1 class="panel-title">${proj.name}</h1>
        <p class="panel-sub">${done} of ${total} completed (${pct}%) &middot; Target ${proj.due}</p>
      </div>
      <div class="progress-bar-wrap"><div class="progress-bar-fill" style="width:${pct}%"></div></div>
      <form id="quickAddForm" class="quick-add">
        <input id="quickAddInput" class="quick-input" type="text" placeholder="Add a new task to ${proj.name}..." autocomplete="off">
        <button class="quick-btn" type="submit">Add</button>
      </form>
      <div class="list-group">
        ${proj.tasks.map((t) => `
          <div class="task-item ${t.done ? "done" : ""}">
            <button class="chk-btn" data-toggle-done="${t.id}" type="button" aria-label="Toggle ${t.title}">
              <span class="chk-circle">
                ${t.done ? `<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3"><polyline points="20 6 9 17 4 12"/></svg>` : ""}
              </span>
            </button>
            <button class="task-body-btn" data-open-task="${t.id}" type="button">
              <span class="task-title">${t.title}</span>
              <span class="task-meta">Due ${t.due} &middot; Tap for notes &rarr;</span>
            </button>
            <button class="prio-dot-btn" data-cycle-prio="${t.id}" type="button" aria-label="Cycle priority">
              <span class="prio-pill prio-${t.priority}">${t.priority}</span>
            </button>
          </div>
        `).join("")}
      </div>
    `;
  }

  function renderLevel2() {
    const proj = getProject();
    const task = getTask();
    if (!task) return;
    els.panels[2].innerHTML = `
      <div class="panel-header">
        <div class="panel-kicker">${proj.name} &middot; Task Detail</div>
      </div>
      <div class="detail-card">
        <div class="detail-hero">
          <button class="chk-btn" data-toggle-done="${task.id}" type="button" aria-label="Mark task complete" style="margin:-6px 0 0 -8px">
            <span class="chk-circle" style="${task.done ? "background:var(--accent);border-color:var(--accent);color:#fff" : ""}">
              ${task.done ? `<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3"><polyline points="20 6 9 17 4 12"/></svg>` : ""}
            </span>
          </button>
          <div>
            <h2 style="${task.done ? "text-decoration:line-through;color:var(--muted)" : ""}">${task.title}</h2>
            <span class="prio-pill prio-${task.priority}">${task.priority} priority</span>
          </div>
        </div>

        <div>
          <div class="section-label">Priority</div>
          <div class="seg-row">
            ${PRIO_ORDER.map((p) => `<button class="seg-pill ${task.priority === p ? "active" : ""}" data-set-prio="${p}" type="button">${p[0].toUpperCase() + p.slice(1)}</button>`).join("")}
          </div>
        </div>

        <div>
          <div class="section-label">Schedule</div>
          <div class="seg-row">
            ${["Today", "Tomorrow", "Next Week"].map((d) => `<button class="seg-pill ${task.due === d ? "active" : ""}" data-set-due="${d}" type="button">${d}</button>`).join("")}
          </div>
        </div>

        <div>
          <div class="section-label">Notes</div>
          <textarea id="taskNotes" class="notes-area" placeholder="Add context, links, or checklist details...">${task.notes}</textarea>
        </div>
      </div>
    `;
  }

  function renderAll() {
    renderHeader();
    renderLevel0();
    renderLevel1();
    renderLevel2();
    updatePanelClasses();
  }

  function popLevel() {
    if (state.level > 0) {
      state.level -= 1;
      renderAll();
    }
  }

  // Click Navigation & Actions
  els.btnBack.addEventListener("click", popLevel);
  els.breadcrumbs.addEventListener("click", (e) => {
    const btn = e.target.closest("[data-level]");
    if (!btn) return;
    const target = Number(btn.dataset.level);
    if (target < state.level) {
      state.level = target;
      renderAll();
    }
  });

  els.viewport.addEventListener("click", (e) => {
    const projBtn = e.target.closest("[data-open-project]");
    if (projBtn) {
      const [aid, pid] = projBtn.dataset.openProject.split(":");
      state.areaId = aid;
      state.projectId = pid;
      state.level = 1;
      renderAll();
      return;
    }

    const doneBtn = e.target.closest("[data-toggle-done]");
    if (doneBtn) {
      const proj = getProject();
      const t = proj && proj.tasks.find((x) => x.id === doneBtn.dataset.toggleDone);
      if (t) { t.done = !t.done; renderAll(); }
      return;
    }

    const prioBtn = e.target.closest("[data-cycle-prio]");
    if (prioBtn) {
      const proj = getProject();
      const t = proj && proj.tasks.find((x) => x.id === prioBtn.dataset.cyclePrio);
      if (t) {
        t.priority = PRIO_ORDER[(PRIO_ORDER.indexOf(t.priority) + 1) % PRIO_ORDER.length];
        renderAll();
      }
      return;
    }

    const openTaskBtn = e.target.closest("[data-open-task]");
    if (openTaskBtn) {
      state.taskId = openTaskBtn.dataset.openTask;
      state.level = 2;
      renderAll();
      return;
    }

    const setPrio = e.target.closest("[data-set-prio]");
    if (setPrio) {
      const t = getTask();
      if (t) { t.priority = setPrio.dataset.setPrio; renderAll(); }
      return;
    }

    const setDue = e.target.closest("[data-set-due]");
    if (setDue) {
      const t = getTask();
      if (t) { t.due = setDue.dataset.setDue; renderAll(); }
    }
  });

  els.viewport.addEventListener("submit", (e) => {
    if (e.target.id === "quickAddForm") {
      e.preventDefault();
      const inp = document.getElementById("quickAddInput");
      const title = inp.value.trim();
      const proj = getProject();
      if (title && proj) {
        proj.tasks.unshift({ id: "t" + Date.now(), title, done: false, priority: "med", due: "Today", notes: "" });
        renderAll();
      }
    }
  });

  els.viewport.addEventListener("input", (e) => {
    if (e.target.id === "taskNotes") {
      const t = getTask();
      if (t) t.notes = e.target.value;
    }
  });

  // Interactive Swipe-Right-to-Go-Back Gesture
  let swipe = null;

  els.viewport.addEventListener("pointerdown", (e) => {
    if (state.level === 0) return;
    if (e.target.closest("input, textarea, button")) return;
    swipe = { startX: e.clientX, startY: e.clientY, dx: 0, locked: false, id: e.pointerId };
  });

  els.viewport.addEventListener("pointermove", (e) => {
    if (!swipe || e.pointerId !== swipe.id) return;
    const dx = e.clientX - swipe.startX;
    const dy = Math.abs(e.clientY - swipe.startY);
    if (!swipe.locked) {
      if (dy > 16 && dy > Math.abs(dx)) { swipe = null; return; }
      if (dx > 12) {
        swipe.locked = true;
        els.panels[state.level].classList.add("no-anim");
        els.panels[state.level - 1].classList.add("no-anim");
      }
    }
    if (swipe.locked) {
      swipe.dx = Math.max(0, dx);
      const w = els.viewport.clientWidth || 360;
      const ratio = Math.min(1, swipe.dx / w);
      els.panels[state.level].style.transform = `translate3d(${swipe.dx}px, 0, 0)`;
      els.panels[state.level - 1].style.transform = `translate3d(${-24 * (1 - ratio)}%, 0, 0)`;
    }
  });

  function endSwipe() {
    if (!swipe) return;
    const wasLocked = swipe.locked;
    const dx = swipe.dx;
    swipe = null;
    if (!wasLocked) return;
    const cur = els.panels[state.level];
    const prev = els.panels[state.level - 1];
    cur.classList.remove("no-anim");
    prev.classList.remove("no-anim");
    const threshold = Math.min(110, (els.viewport.clientWidth || 360) * 0.28);
    if (dx > threshold) {
      popLevel();
    } else {
      updatePanelClasses();
    }
  }

  els.viewport.addEventListener("pointerup", endSwipe);
  els.viewport.addEventListener("pointercancel", endSwipe);

  document.addEventListener("keydown", (e) => {
    if (e.key === "Escape" && state.level > 0) {
      popLevel();
    }
  });

  renderAll();
})();
</script>
</body>
</html>