# #112 — Expandable Mini-Player to Full-Screen Media Sheet

> Persistent bottom mini-player that expands seamlessly into a full-screen chaptered player with speed, scrub, and sleep timer.

## Metadata

- **Index**: #112
- **Slug**: `expandable-mini-player-sheet`
- **Kind**: `ui`
- **Family**: Media & Stories
- **Theme**: `dark`
- **Mobile Strength**: `native-first`
- **Tags**: `mini-player`, `media-sheet`, `audio-player`, `chapter-scrub`, `podcast-ui`
- **Best For**: Podcast & audiobook apps, Music streaming players, Course & lecture platforms, Guided meditation apps
- **Real-World Inspiration**: [Pocket Casts](https://pocketcasts.com)
- **Detail Page**: https://templates.michaelpitts.net/t/expandable-mini-player-sheet
- **Live Demo**: https://templates.michaelpitts.net/demos/expandable-mini-player-sheet.html
- **JSON API**: https://templates.michaelpitts.net/api/templates/expandable-mini-player-sheet

## Why This Aesthetic Is Unique

Lets listeners browse episodes uninterrupted while keeping transport controls one tap away and expanding into deep chapter/speed tools on demand.

## Color Palette

| Role | Name | Hex |
|------|------|-----|
| `canvas` | Studio Obsidian | `#101218` |
| `surface` | Deck Charcoal | `#1B1E28` |
| `ink` | Pure White | `#F9FAFB` |
| `accent` | Broadcast Red | `#F43E37` |
| `muted` | Signal Gray | `#9CA3AF` |

## Typography

- **Display**: `Plus Jakarta Sans`
- **Body**: `Inter`
- **Mono**: `JetBrains Mono`
- **Scale Notes**: Tabular monospace timestamps paired with bold 18-24px episode titles and compact chapter rows.
- **Google Fonts**: https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&family=JetBrains+Mono:wght@500;600&family=Plus+Jakarta+Sans:wght@700;800&display=swap
  ```html
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&family=JetBrains+Mono:wght@500;600&family=Plus+Jakarta+Sans:wght@700;800&display=swap">
  ```

## Layout Architecture

Scrollable episode queue with a pinned bottom mini-player bar (including hairline progress strip) that morphs upward into a centered full-height player sheet.

## Interaction & Micro-Motion Rules

Simulated playback clock drives both mini and full scrubbers in sync; includes ±15s skip, 1x/1.2x/1.5x/2x speed cycler, sleep timer pill, and clickable chapter jump list.

## Mobile & Responsive Rules

Large 56px play/pause button and thumb-friendly bottom transport row inside the expanded sheet, with swipe-down or chevron button to collapse.

## Agent Guardrails

### DO
- Keep Play/Pause directly clickable on the mini-player without forcing expansion
- Synchronize playback position, episode metadata, and progress bar across mini and full views
- Add bottom padding equal to the mini-player height so the last episode row is never obscured

### DON'T
- Do not interrupt playback state when expanding or collapsing the media sheet
- Do not make seek thumbs smaller than 24-44px hit area on touch screens

## Complete Standalone Starter Code

File: `demos/expandable-mini-player-sheet.html`

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CastDeck — Expandable Mini-Player to Full-Screen Media Sheet</title>
<style>
  :root {
    --canvas: #101218;
    --surface: #1B1E28;
    --surface-hi: #252938;
    --ink: #F9FAFB;
    --accent: #F43E37;
    --accent-soft: rgba(244, 62, 55, 0.16);
    --muted: #9CA3AF;
    --border: rgba(255, 255, 255, 0.08);
    --radius: 16px;
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  }

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

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

  .feed-shell {
    max-width: 820px;
    margin: 0 auto;
    padding: 18px 14px 116px;
  }

  @media (min-width: 768px) {
    .feed-shell { padding: 28px 24px 128px; }
  }

  .feed-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
  }

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

  .brand-dot {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: var(--accent);
    display: grid;
    place-items: center;
    box-shadow: 0 6px 18px rgba(244, 62, 55, 0.32);
  }

  .brand h1 { font-size: 1.2rem; font-weight: 750; letter-spacing: -0.02em; }
  .brand p { font-size: 0.78rem; color: var(--muted); }

  .queue-badge {
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 999px;
  }

  /* Episode Feed */
  .ep-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .ep-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 13px;
    display: flex;
    align-items: center;
    gap: 13px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
  }

  .ep-card:hover { background: var(--surface-hi); }
  .ep-card.playing { border-color: var(--accent); }

  .ep-art {
    width: 64px;
    height: 64px;
    border-radius: 12px;
    overflow: hidden;
    flex-shrink: 0;
  }

  .ep-art svg { width: 100%; height: 100%; display: block; }

  .ep-meta { flex: 1; min-width: 0; }

  .ep-show {
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .ep-title {
    font-size: 0.94rem;
    font-weight: 700;
    color: var(--ink);
    margin: 2px 0 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .ep-sub {
    font-size: 0.78rem;
    color: var(--muted);
  }

  .ep-play-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--surface-hi);
    color: var(--ink);
    cursor: pointer;
    display: grid;
    place-items: center;
    flex-shrink: 0;
  }

  .ep-card.playing .ep-play-btn {
    background: var(--accent);
    color: #FFFFFF;
  }

  /* Persistent Bottom Mini-Player */
  .mini-player {
    position: fixed;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    width: calc(100% - 20px);
    max-width: 780px;
    background: #1E2230;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
    z-index: 30;
    cursor: pointer;
    touch-action: none;
  }

  .mini-progress-track {
    height: 3px;
    background: rgba(255, 255, 255, 0.1);
    width: 100%;
  }

  .mini-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.2s linear;
  }

  .mini-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 10px 9px 12px;
  }

  .mini-art {
    width: 46px;
    height: 46px;
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
  }

  .mini-art svg { width: 100%; height: 100%; display: block; }

  .mini-info { flex: 1; min-width: 0; }
  .mini-info strong {
    display: block;
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mini-info span {
    display: block;
    font-size: 0.74rem;
    color: var(--muted);
  }

  .mini-ctrl {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    display: grid;
    place-items: center;
    flex-shrink: 0;
  }

  .mini-ctrl:hover { background: rgba(255, 255, 255, 0.08); }

  /* Full-Screen Expandable Media Sheet */
  .player-sheet {
    position: fixed;
    inset: 0;
    background: linear-gradient(180deg, #1E2232 0%, #101218 46%);
    z-index: 50;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
    overflow-y: auto;
  }

  .player-sheet.open { transform: translateY(0); }
  .player-sheet.dragging { transition: none; }

  .sheet-inner {
    max-width: 560px;
    width: 100%;
    margin: 0 auto;
    padding: 12px 18px 36px;
    display: flex;
    flex-direction: column;
    gap: 18px;
  }

  .drag-handle-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 4px;
    touch-action: none;
  }

  .drag-pill {
    width: 42px;
    height: 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.24);
  }

  .sheet-icon-btn {
    min-width: 44px;
    min-height: 44px;
    border: none;
    border-radius: 12px;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    display: grid;
    place-items: center;
  }

  .sheet-icon-btn:hover { background: rgba(255, 255, 255, 0.08); }

  .hero-art {
    width: min(260px, 68vw);
    aspect-ratio: 1 / 1;
    margin: 4px auto 0;
    border-radius: 22px;
    overflow: hidden;
    box-shadow: 0 22px 48px rgba(0, 0, 0, 0.55);
  }

  .hero-art svg { width: 100%; height: 100%; display: block; }

  .hero-titles { text-align: center; }
  .hero-titles h2 { font-size: 1.22rem; font-weight: 750; margin-bottom: 4px; }
  .hero-titles p { font-size: 0.85rem; color: var(--muted); }

  /* Interactive Scrubber */
  .scrubber-block { display: flex; flex-direction: column; gap: 6px; }

  .scrub-input {
    width: 100%;
    accent-color: var(--accent);
    height: 6px;
    cursor: pointer;
  }

  .time-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.76rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
  }

  /* Transport Controls */
  .transport {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .pill-btn {
    min-height: 44px;
    min-width: 56px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink);
    font-size: 0.8rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
  }

  .pill-btn.active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
  }

  .skip-btn {
    min-width: 52px;
    min-height: 52px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--ink);
    font-size: 0.82rem;
    font-weight: 750;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .skip-btn:hover { background: rgba(255, 255, 255, 0.08); }

  .play-big {
    width: 66px;
    height: 66px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #FFFFFF;
    cursor: pointer;
    display: grid;
    place-items: center;
    box-shadow: 0 10px 26px rgba(244, 62, 55, 0.4);
  }

  /* Chapters List */
  .chapters-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
  }

  .chapters-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    margin-bottom: 10px;
  }

  .chapter-row {
    width: 100%;
    min-height: 46px;
    padding: 8px 10px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--ink);
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    text-align: left;
  }

  .chapter-row:hover { background: rgba(255, 255, 255, 0.05); }
  .chapter-row.current { background: var(--accent-soft); color: #FFFFFF; }
  .chapter-row.current .ch-time { color: var(--accent); }

  .ch-title { font-size: 0.86rem; font-weight: 600; }
  .ch-time { font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
</style>
</head>
<body>
<div class="feed-shell">
  <header class="feed-head">
    <div class="brand">
      <div class="brand-dot" aria-hidden="true">
        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#FFFFFF" stroke-width="2.2" stroke-linecap="round"><circle cx="12" cy="12" r="2.5"/><path d="M8.5 15.5a5 5 0 0 1 0-7"/><path d="M15.5 8.5a5 5 0 0 1 0 7"/><path d="M5.5 18.5a9.2 9.2 0 0 1 0-13"/><path d="M18.5 5.5a9.2 9.2 0 0 1 0 13"/></svg>
      </div>
      <div>
        <h1>CastDeck</h1>
        <p>Tap or drag the mini-player upward for chapters &amp; sleep timer</p>
      </div>
    </div>
    <span class="queue-badge">4 Episodes</span>
  </header>

  <main id="epList" class="ep-list" aria-label="Podcast episodes"></main>
</div>

<!-- Persistent Bottom Mini-Player -->
<aside id="miniPlayer" class="mini-player" role="region" aria-label="Mini audio player">
  <div class="mini-progress-track"><div id="miniFill" class="mini-progress-fill"></div></div>
  <div class="mini-row">
    <div id="miniArt" class="mini-art"></div>
    <div class="mini-info">
      <strong id="miniTitle"></strong>
      <span id="miniSub"></span>
    </div>
    <button id="miniSkip" class="mini-ctrl" type="button" aria-label="Forward 15 seconds">+15</button>
    <button id="miniPlay" class="mini-ctrl" type="button" aria-label="Play or pause"></button>
  </div>
</aside>

<!-- Full-Screen Expandable Media Sheet -->
<section id="playerSheet" class="player-sheet" aria-label="Full screen audio player">
  <div class="sheet-inner">
    <div id="sheetDragHeader" class="drag-handle-wrap">
      <button id="collapseSheet" class="sheet-icon-btn" type="button" aria-label="Collapse player">
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>
      </button>
      <div class="drag-pill" aria-hidden="true"></div>
      <span id="sleepBadge" style="font-size:0.75rem;color:var(--accent);font-weight:700;min-width:44px;text-align:right"></span>
    </div>

    <div id="heroArt" class="hero-art"></div>

    <div class="hero-titles">
      <h2 id="sheetTitle"></h2>
      <p id="sheetShow"></p>
    </div>

    <div class="scrubber-block">
      <input id="scrubInput" class="scrub-input" type="range" min="0" max="100" value="0" aria-label="Seek episode timeline">
      <div class="time-row">
        <span id="timeElapsed">0:00</span>
        <span id="chapterNow" style="color:var(--ink);font-weight:600"></span>
        <span id="timeRemain">-0:00</span>
      </div>
    </div>

    <div class="transport">
      <button id="speedBtn" class="pill-btn" type="button" aria-label="Playback speed">1.0x</button>
      <button id="back15Btn" class="skip-btn" type="button" aria-label="Back 15 seconds">-15s</button>
      <button id="sheetPlayBtn" class="play-big" type="button" aria-label="Play or pause"></button>
      <button id="fwd15Btn" class="skip-btn" type="button" aria-label="Forward 15 seconds">+15s</button>
      <button id="sleepBtn" class="pill-btn" type="button" aria-label="Sleep timer">Sleep</button>
    </div>

    <div class="chapters-card">
      <div class="chapters-head">
        <span>Chapters</span>
        <span id="chapterCount"></span>
      </div>
      <div id="chapterList"></div>
    </div>
  </div>
</section>

<script>
(function () {
  const EPISODES = [
    {
      id: "ep1", show: "Design Details Live", title: "Spatial Interfaces & Tactile Motion", date: "Today", duration: 2460,
      colors: ["#F43E37", "#7C2D12", "#FCA5A5"],
      chapters: [
        { t: 0, title: "Intro & Weekly Tooling Picks" },
        { t: 420, title: "Spring Physics vs. Cubic Beziers" },
        { t: 1180, title: "Thumb Reach Zones on 390px Screens" },
        { t: 1890, title: "Listener Q&A and Wrap-up" }
      ]
    },
    {
      id: "ep2", show: "Systems Under Hood", title: "Local-First Sync Engines Explained", date: "May 16", duration: 3120,
      colors: ["#3B82F6", "#1E3A8A", "#93C5FD"],
      chapters: [
        { t: 0, title: "Why Optimistic UI Matters" },
        { t: 740, title: "CRDTs vs. Operational Transforms" },
        { t: 1680, title: "IndexedDB & SQLite in the Browser" },
        { t: 2540, title: "Conflict Resolution Patterns" }
      ]
    },
    {
      id: "ep3", show: "Analog Craft", title: "Field Recording in Kyoto Rain", date: "May 11", duration: 1980,
      colors: ["#10B981", "#064E3B", "#6EE7B7"],
      chapters: [
        { t: 0, title: "Packing Ultra-Light Microphones" },
        { t: 620, title: "Dawn Acoustics at Philosopher's Path" },
        { t: 1340, title: "Mixing Ambient Stems for Podcasts" }
      ]
    },
    {
      id: "ep4", show: "Founders Notebook", title: "Bootstrapping Calm Software Tools", date: "May 04", duration: 2740,
      colors: ["#A855F7", "#4C1D95", "#D8B4FE"],
      chapters: [
        { t: 0, title: "Pricing for Long-Term Sustainability" },
        { t: 880, title: "Saying No to Feature Bloat" },
        { t: 1920, title: "Customer Support as Product Research" }
      ]
    }
  ];

  const SPEEDS = [1.0, 1.2, 1.5, 2.0];
  const SLEEPS = [
    { label: "Off", sec: 0 },
    { label: "15m", sec: 900 },
    { label: "30m", sec: 1800 },
    { label: "Ch.", sec: -1 } // End of chapter
  ];

  const state = {
    epIdx: 0,
    time: 438,
    playing: true,
    speedIdx: 0,
    sleepIdx: 0,
    sleepRemain: 0,
    expanded: false
  };

  const els = {
    epList: document.getElementById("epList"),
    miniPlayer: document.getElementById("miniPlayer"),
    miniFill: document.getElementById("miniFill"),
    miniArt: document.getElementById("miniArt"),
    miniTitle: document.getElementById("miniTitle"),
    miniSub: document.getElementById("miniSub"),
    miniPlay: document.getElementById("miniPlay"),
    miniSkip: document.getElementById("miniSkip"),
    sheet: document.getElementById("playerSheet"),
    sheetDragHeader: document.getElementById("sheetDragHeader"),
    collapseSheet: document.getElementById("collapseSheet"),
    heroArt: document.getElementById("heroArt"),
    sheetTitle: document.getElementById("sheetTitle"),
    sheetShow: document.getElementById("sheetShow"),
    scrubInput: document.getElementById("scrubInput"),
    timeElapsed: document.getElementById("timeElapsed"),
    timeRemain: document.getElementById("timeRemain"),
    chapterNow: document.getElementById("chapterNow"),
    speedBtn: document.getElementById("speedBtn"),
    back15Btn: document.getElementById("back15Btn"),
    sheetPlayBtn: document.getElementById("sheetPlayBtn"),
    fwd15Btn: document.getElementById("fwd15Btn"),
    sleepBtn: document.getElementById("sleepBtn"),
    sleepBadge: document.getElementById("sleepBadge"),
    chapterCount: document.getElementById("chapterCount"),
    chapterList: document.getElementById("chapterList")
  };

  function fmtTime(sec) {
    const s = Math.max(0, Math.floor(sec));
    const m = Math.floor(s / 60);
    const r = s % 60;
    return `${m}:${r < 10 ? "0" : ""}${r}`;
  }

  function coverSvg(colors, idx) {
    const [c1, c2, c3] = colors;
    return `<svg viewBox="0 0 160 160">
      <defs><linearGradient id="cg${idx}" x1="0" y1="0" x2="1" y2="1"><stop offset="0%" stop-color="${c1}"/><stop offset="100%" stop-color="${c2}"/></linearGradient></defs>
      <rect width="160" height="160" fill="url(#cg${idx})"/>
      <circle cx="80" cy="80" r="46" fill="none" stroke="${c3}" stroke-width="6" opacity="0.5"/>
      <circle cx="80" cy="80" r="24" fill="${c3}" opacity="0.88"/>
      <circle cx="80" cy="80" r="9" fill="${c2}"/>
    </svg>`;
  }

  function playIcon(isPlaying, size) {
    return isPlaying
      ? `<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="currentColor"><rect x="6" y="4" width="4.5" height="16" rx="1.2"/><rect x="13.5" y="4" width="4.5" height="16" rx="1.2"/></svg>`
      : `<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="currentColor"><polygon points="6 4 20 12 6 20 6 4"/></svg>`;
  }

  function currentEpisode() { return EPISODES[state.epIdx]; }

  function activeChapterIndex(ep, t) {
    let idx = 0;
    for (let i = 0; i < ep.chapters.length; i++) {
      if (t >= ep.chapters[i].t) idx = i;
    }
    return idx;
  }

  function renderFeed() {
    els.epList.innerHTML = EPISODES.map((ep, idx) => {
      const isCur = idx === state.epIdx;
      return `
        <article class="ep-card ${isCur ? "playing" : ""}" data-ep="${idx}">
          <div class="ep-art">${coverSvg(ep.colors, "f" + idx)}</div>
          <div class="ep-meta">
            <div class="ep-show">${ep.show}</div>
            <div class="ep-title">${ep.title}</div>
            <div class="ep-sub">${ep.date} &middot; ${fmtTime(ep.duration)} &middot; ${ep.chapters.length} chapters</div>
          </div>
          <button class="ep-play-btn" data-play-ep="${idx}" type="button" aria-label="Play ${ep.title}">
            ${playIcon(isCur && state.playing, 18)}
          </button>
        </article>
      `;
    }).join("");
  }

  function renderPlayer() {
    const ep = currentEpisode();
    const pct = (state.time / ep.duration) * 100;
    const chIdx = activeChapterIndex(ep, state.time);
    const ch = ep.chapters[chIdx];

    els.miniFill.style.width = pct.toFixed(2) + "%";
    els.miniArt.innerHTML = coverSvg(ep.colors, "m" + state.epIdx);
    els.miniTitle.textContent = ep.title;
    els.miniSub.textContent = `${ep.show} · ${fmtTime(ep.duration - state.time)} left`;
    els.miniPlay.innerHTML = playIcon(state.playing, 20);

    els.heroArt.innerHTML = coverSvg(ep.colors, "h" + state.epIdx);
    els.sheetTitle.textContent = ep.title;
    els.sheetShow.textContent = ep.show;

    els.scrubInput.max = ep.duration;
    els.scrubInput.value = Math.floor(state.time);
    els.timeElapsed.textContent = fmtTime(state.time);
    els.timeRemain.textContent = "-" + fmtTime(ep.duration - state.time);
    els.chapterNow.textContent = ch.title;

    els.sheetPlayBtn.innerHTML = playIcon(state.playing, 26);
    els.speedBtn.textContent = SPEEDS[state.speedIdx].toFixed(1) + "x";
    els.speedBtn.classList.toggle("active", state.speedIdx !== 0);

    const sl = SLEEPS[state.sleepIdx];
    els.sleepBtn.textContent = sl.sec === 0 ? "Sleep" : sl.label;
    els.sleepBtn.classList.toggle("active", sl.sec !== 0);
    els.sleepBadge.textContent = sl.sec > 0 ? fmtTime(state.sleepRemain) : (sl.sec === -1 ? "End ch." : "");

    els.chapterCount.textContent = `${chIdx + 1} / ${ep.chapters.length}`;
    els.chapterList.innerHTML = ep.chapters.map((c, i) => `
      <button class="chapter-row ${i === chIdx ? "current" : ""}" data-seek="${c.t}" type="button">
        <span class="ch-title">${i + 1}. ${c.title}</span>
        <span class="ch-time">${fmtTime(c.t)}</span>
      </button>
    `).join("");

    els.sheet.classList.toggle("open", state.expanded);
  }

  function renderAll() {
    renderFeed();
    renderPlayer();
  }

  // Simulated Live Playback Loop
  setInterval(() => {
    if (!state.playing) return;
    const ep = currentEpisode();
    const prevCh = activeChapterIndex(ep, state.time);
    const step = 0.5 * SPEEDS[state.speedIdx];
    state.time = Math.min(ep.duration, state.time + step);
    if (state.time >= ep.duration) {
      state.playing = false;
    }
    if (SLEEPS[state.sleepIdx].sec > 0) {
      state.sleepRemain = Math.max(0, state.sleepRemain - 0.5);
      if (state.sleepRemain === 0) {
        state.playing = false;
        state.sleepIdx = 0;
      }
    } else if (SLEEPS[state.sleepIdx].sec === -1) {
      if (activeChapterIndex(ep, state.time) !== prevCh) {
        state.playing = false;
        state.sleepIdx = 0;
      }
    }
    renderPlayer();
  }, 500);

  // Feed Clicks
  els.epList.addEventListener("click", (e) => {
    const card = e.target.closest("[data-ep]");
    if (!card) return;
    const idx = Number(card.dataset.ep);
    if (idx === state.epIdx) {
      state.playing = !state.playing;
    } else {
      state.epIdx = idx;
      state.time = 0;
      state.playing = true;
    }
    renderAll();
  });

  // Mini-Player Controls & Tap/Drag Up
  els.miniPlay.addEventListener("click", (e) => {
    e.stopPropagation();
    state.playing = !state.playing;
    renderAll();
  });

  els.miniSkip.addEventListener("click", (e) => {
    e.stopPropagation();
    state.time = Math.min(currentEpisode().duration, state.time + 15);
    renderPlayer();
  });

  let miniDragY = null;
  els.miniPlayer.addEventListener("pointerdown", (e) => {
    if (e.target.closest("button")) return;
    miniDragY = e.clientY;
  });
  els.miniPlayer.addEventListener("pointerup", (e) => {
    if (miniDragY === null) return;
    const dy = miniDragY - e.clientY;
    miniDragY = null;
    if (dy >= -10) {
      state.expanded = true;
      renderPlayer();
    }
  });

  // Sheet Collapse & Drag Down
  els.collapseSheet.addEventListener("click", () => {
    state.expanded = false;
    renderPlayer();
  });

  let sheetDrag = null;
  els.sheetDragHeader.addEventListener("pointerdown", (e) => {
    if (e.target.closest("button")) return;
    sheetDrag = { startY: e.clientY, dy: 0 };
    els.sheet.classList.add("dragging");
  });
  window.addEventListener("pointermove", (e) => {
    if (!sheetDrag) return;
    sheetDrag.dy = Math.max(0, e.clientY - sheetDrag.startY);
    els.sheet.style.transform = `translateY(${sheetDrag.dy}px)`;
  });
  window.addEventListener("pointerup", () => {
    if (!sheetDrag) return;
    const dy = sheetDrag.dy;
    sheetDrag = null;
    els.sheet.classList.remove("dragging");
    els.sheet.style.transform = "";
    if (dy > 90) {
      state.expanded = false;
      renderPlayer();
    }
  });

  // Full-Screen Transport Controls
  els.scrubInput.addEventListener("input", (e) => {
    state.time = Number(e.target.value);
    renderPlayer();
  });

  els.sheetPlayBtn.addEventListener("click", () => {
    state.playing = !state.playing;
    renderAll();
  });

  els.back15Btn.addEventListener("click", () => {
    state.time = Math.max(0, state.time - 15);
    renderPlayer();
  });

  els.fwd15Btn.addEventListener("click", () => {
    state.time = Math.min(currentEpisode().duration, state.time + 15);
    renderPlayer();
  });

  els.speedBtn.addEventListener("click", () => {
    state.speedIdx = (state.speedIdx + 1) % SPEEDS.length;
    renderPlayer();
  });

  els.sleepBtn.addEventListener("click", () => {
    state.sleepIdx = (state.sleepIdx + 1) % SLEEPS.length;
    state.sleepRemain = Math.max(0, SLEEPS[state.sleepIdx].sec);
    renderPlayer();
  });

  els.chapterList.addEventListener("click", (e) => {
    const row = e.target.closest("[data-seek]");
    if (!row) return;
    state.time = Number(row.dataset.seek);
    state.playing = true;
    renderAll();
  });

  document.addEventListener("keydown", (e) => {
    if (e.key === "Escape" && state.expanded) {
      state.expanded = false;
      renderPlayer();
    }
  });

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