Docked Picture-in-Picture / Floating Context Reference Card
Draggable corner-snapping Picture-in-Picture card that keeps video context alive while scrolling time-coded notes.
Inspired by Vimeo ↗
WHY THIS AESTHETIC IS UNIQUE
Enables effortless split-attention workflows—watching a tutorial or call while reading structured notes—by magnetically snapping to whichever corner stays out of the way.
BEST FOR
TAGS
COLOR PALETTE (CLICK TO COPY HEX)
TYPOGRAPHY
- Display
- Plus Jakarta Sans
- Body
- Inter
- Mono
- JetBrains Mono
- Scale
- Mono timecode chips (00:58) paired with clean 15px workshop note cards and compact PiP HUD labels.
ARCHITECTURE & MOBILE NOTES
LAYOUT
Main video stage plus scrollable time-coded chapter notes and a desktop snap-corner rail; scrolling past the main stage automatically surfaces the floating PiP card.
INTERACTION
Drag the PiP header anywhere and release to magnetically snap to the nearest safe viewport corner; includes minimize-to-pill, return-to-top, close, and synchronized canvas playback.
MOBILE
PiP width scales gracefully via min(296px, calc(100vw - 24px)) and can be minimized to a slim audio/timecode bar so dense reading remains unobstructed.
AI AGENT GUARDRAILS
DO
- Snap the dragged PiP card magnetically to safe viewport corners with padding so it never drifts off-screen
- Offer a Minimize toggle that collapses the video frame into a compact control pill on small screens
- Keep playback state and chapter timestamps 100% synchronized between main stage and PiP
DON'T
- Do not block dismissal; always include a clear Close and Return-to-Stage button on the PiP header
- Do not lock the PiP to a single corner where it might permanently cover a primary CTA
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Docked Picture-in-Picture & Floating Reference Card</title>
<style>
:root {
--canvas: #0B1120;
--surface: #131C31;
--surface-2: #1B2742;
--ink: #F1F5F9;
--accent: #00ADEF;
--accent-soft: rgba(0, 173, 239, 0.16);
--muted: #94A3B8;
--border: rgba(148, 163, 184, 0.16);
--radius: 16px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
background: var(--canvas);
color: var(--ink);
font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
line-height: 1.55;
overflow-x: hidden;
-webkit-font-smoothing: antialiased;
}
header.topbar {
position: sticky;
top: 0;
z-index: 30;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 12px 18px;
background: rgba(11, 17, 32, 0.88);
backdrop-filter: blur(12px);
border-bottom: 1px solid var(--border);
}
.brand {
display: flex;
align-items: center;
gap: 10px;
font-weight: 700;
font-size: 0.95rem;
letter-spacing: -0.01em;
}
.brand-dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 12px var(--accent);
}
.topbar-actions {
display: flex;
align-items: center;
gap: 8px;
}
.pill-btn {
min-height: 44px;
padding: 0 14px;
border-radius: 999px;
border: 1px solid var(--border);
background: var(--surface);
color: var(--ink);
font-size: 0.82rem;
font-weight: 600;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 6px;
transition: background 0.18s, border-color 0.18s, transform 0.12s;
}
.pill-btn:hover { background: var(--surface-2); border-color: rgba(0, 173, 239, 0.45); }
.pill-btn:active { transform: scale(0.97); }
.pill-btn.active { background: var(--accent-soft); border-color: var(--accent); color: #7DD3FC; }
.layout {
max-width: 1120px;
margin: 0 auto;
padding: 20px 18px 220px;
display: grid;
grid-template-columns: 1fr;
gap: 24px;
}
@media (min-width: 960px) {
.layout {
grid-template-columns: minmax(0, 1.55fr) minmax(290px, 0.85fr);
padding: 28px 28px 140px;
align-items: start;
}
}
.hero-stage {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
overflow: hidden;
position: relative;
}
.stage-canvas-wrap {
position: relative;
aspect-ratio: 16 / 9;
background: #070C18;
overflow: hidden;
}
canvas#mainCanvas {
width: 100%;
height: 100%;
display: block;
}
.stage-overlay-bar {
position: absolute;
left: 12px;
right: 12px;
bottom: 12px;
display: flex;
align-items: center;
gap: 10px;
padding: 8px 12px;
background: rgba(11, 17, 32, 0.82);
backdrop-filter: blur(8px);
border: 1px solid rgba(255,255,255,0.1);
border-radius: 12px;
}
.icon-btn {
width: 44px;
height: 44px;
flex-shrink: 0;
border-radius: 10px;
border: none;
background: rgba(255,255,255,0.08);
color: var(--ink);
cursor: pointer;
display: grid;
place-items: center;
transition: background 0.15s;
}
.icon-btn:hover { background: rgba(0, 173, 239, 0.25); }
.scrubber {
flex: 1;
display: flex;
flex-direction: column;
gap: 4px;
}
.scrubber input[type="range"] {
width: 100%;
accent-color: var(--accent);
cursor: pointer;
height: 6px;
}
.time-row {
display: flex;
justify-content: space-between;
font-size: 0.72rem;
font-variant-numeric: tabular-nums;
color: var(--muted);
}
.stage-meta {
padding: 16px 18px;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.stage-meta h1 {
font-size: clamp(1.1rem, 2.4vw, 1.38rem);
letter-spacing: -0.02em;
line-height: 1.25;
}
.stage-meta p {
font-size: 0.85rem;
color: var(--muted);
margin-top: 2px;
}
.notes-section {
display: flex;
flex-direction: column;
gap: 14px;
margin-top: 22px;
}
.section-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.section-head h2 {
font-size: 1rem;
font-weight: 700;
letter-spacing: -0.01em;
}
.hint-badge {
font-size: 0.75rem;
color: #7DD3FC;
background: var(--accent-soft);
padding: 4px 10px;
border-radius: 999px;
}
.chapter-card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 14px;
padding: 16px;
cursor: pointer;
transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.chapter-card:hover {
border-color: rgba(0, 173, 239, 0.45);
background: var(--surface-2);
}
.chapter-card.active {
border-color: var(--accent);
box-shadow: 0 0 0 1px rgba(0, 173, 239, 0.35);
}
.chapter-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 6px;
}
.timestamp-chip {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 0.76rem;
font-weight: 600;
color: var(--accent);
background: var(--accent-soft);
padding: 3px 8px;
border-radius: 6px;
}
.chapter-card h3 {
font-size: 0.96rem;
margin-bottom: 6px;
}
.chapter-card p {
font-size: 0.86rem;
color: var(--muted);
}
.spec-list {
margin-top: 10px;
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.spec-tag {
font-size: 0.74rem;
color: #CBD5E1;
background: rgba(255,255,255,0.05);
border: 1px solid var(--border);
padding: 3px 8px;
border-radius: 6px;
}
aside.rail {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 18px;
display: flex;
flex-direction: column;
gap: 14px;
}
aside.rail h2 { font-size: 0.96rem; }
.corner-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.corner-btn {
min-height: 44px;
border-radius: 10px;
border: 1px solid var(--border);
background: var(--surface-2);
color: var(--ink);
font-size: 0.8rem;
font-weight: 600;
cursor: pointer;
transition: border-color 0.15s, background 0.15s;
}
.corner-btn.active {
border-color: var(--accent);
background: var(--accent-soft);
color: #7DD3FC;
}
.status-line {
font-size: 0.8rem;
color: var(--muted);
background: rgba(0,0,0,0.22);
padding: 10px 12px;
border-radius: 10px;
border: 1px solid var(--border);
}
.status-line strong { color: var(--ink); }
/* Floating Picture-in-Picture Card */
.pip-card {
position: fixed;
z-index: 60;
width: min(296px, calc(100vw - 24px));
background: #10192D;
border: 1px solid rgba(0, 173, 239, 0.55);
border-radius: 16px;
box-shadow: 0 22px 48px rgba(0, 0, 0, 0.58), 0 0 0 1px rgba(255,255,255,0.06);
overflow: hidden;
touch-action: none;
user-select: none;
opacity: 0;
pointer-events: none;
transform: scale(0.92);
transition: opacity 0.22s ease, transform 0.22s ease, left 0.28s cubic-bezier(.22,1,.36,1), top 0.28s cubic-bezier(.22,1,.36,1);
}
.pip-card.visible {
opacity: 1;
pointer-events: auto;
transform: scale(1);
}
.pip-card.dragging {
transition: opacity 0.22s ease, transform 0.1s ease;
cursor: grabbing;
box-shadow: 0 28px 60px rgba(0, 0, 0, 0.72), 0 0 0 2px var(--accent);
}
.pip-card.minimized .pip-video-wrap {
display: none;
}
.pip-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 8px 10px;
background: rgba(15, 23, 42, 0.94);
cursor: grab;
border-bottom: 1px solid var(--border);
}
.pip-drag-label {
display: flex;
align-items: center;
gap: 6px;
font-size: 0.74rem;
font-weight: 600;
color: #CBD5E1;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.pip-controls {
display: flex;
align-items: center;
gap: 4px;
}
.pip-mini-btn {
width: 34px;
height: 34px;
border-radius: 8px;
border: none;
background: rgba(255,255,255,0.07);
color: var(--ink);
cursor: pointer;
display: grid;
place-items: center;
font-size: 0.8rem;
}
.pip-mini-btn:hover { background: rgba(0, 173, 239, 0.25); }
.pip-video-wrap {
position: relative;
aspect-ratio: 16 / 9;
background: #060B14;
}
canvas#pipCanvas {
width: 100%;
height: 100%;
display: block;
}
.pip-footer {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 10px;
background: #131D34;
}
.pip-progress {
flex: 1;
height: 4px;
background: rgba(255,255,255,0.12);
border-radius: 999px;
overflow: hidden;
}
.pip-progress-fill {
height: 100%;
width: 24%;
background: var(--accent);
border-radius: 999px;
}
.pip-time {
font-size: 0.72rem;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
color: var(--muted);
}
</style>
</head>
<body>
<header class="topbar">
<div class="brand">
<span class="brand-dot" aria-hidden="true"></span>
<span>CineLab Studio · PiP Reference</span>
</div>
<div class="topbar-actions">
<button id="togglePipBtn" class="pill-btn active" type="button" aria-pressed="true">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="4" width="18" height="16" rx="2"/><rect x="12" y="11" width="7" height="6" rx="1" fill="currentColor"/></svg>
<span>Float PiP</span>
</button>
</div>
</header>
<main class="layout">
<div>
<section class="hero-stage" id="heroStage" aria-label="Main workshop player">
<div class="stage-canvas-wrap">
<canvas id="mainCanvas" width="640" height="360"></canvas>
<div class="stage-overlay-bar">
<button id="playPauseBtn" class="icon-btn" type="button" aria-label="Play or pause video">
<svg id="playIcon" width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><rect x="6" y="5" width="4" height="14" rx="1"/><rect x="14" y="5" width="4" height="14" rx="1"/></svg>
</button>
<div class="scrubber">
<input id="seekRange" type="range" min="0" max="180" value="32" aria-label="Playback timeline">
<div class="time-row">
<span id="curTimeLabel">00:32</span>
<span id="activeChapterLabel">Ch. 1 · Key Light Ratio</span>
<span>03:00</span>
</div>
</div>
</div>
</div>
<div class="stage-meta">
<div>
<h1>Cinematography Lighting Breakdown: Three-Point Neon</h1>
<p>Scroll through the shot notes below — the player docks into a draggable corner PiP automatically.</p>
</div>
<button id="scrollNotesBtn" class="pill-btn" type="button">Jump to Notes ↓</button>
</div>
</section>
<section class="notes-section" id="notesSection" aria-label="Time-coded workshop notes">
<div class="section-head">
<h2>Time-Coded Workshop Notes</h2>
<span class="hint-badge">Tap any chapter to seek</span>
</div>
<article class="chapter-card active" data-time="12" data-title="Ch. 1 · Key Light Ratio">
<div class="chapter-top">
<span class="timestamp-chip">00:12</span>
<span style="font-size:0.75rem;color:var(--muted)">45° Key · 4800K</span>
</div>
<h3>1. Setting the 4:1 Key-to-Fill Contrast Ratio</h3>
<p>Position the softbox 45 degrees off-axis with a double-diffused silk. Keep fill two stops below key so cheekbone falloff retains sculptural depth without crushing shadows.</p>
<div class="spec-list">
<span class="spec-tag">Aperture f/2.0</span>
<span class="spec-tag">ISO 800</span>
<span class="spec-tag">180° Shutter</span>
</div>
</article>
<article class="chapter-card" data-time="58" data-title="Ch. 2 · Cyan Rim Separation">
<div class="chapter-top">
<span class="timestamp-chip">00:58</span>
<span style="font-size:0.75rem;color:var(--muted)">Back Edge · Cyan Gel</span>
</div>
<h3>2. Sculpting Silhouette with Cyan Practical Rim</h3>
<p>Introduce a 2-foot LED tube dialed to 195° hue behind the subject's left shoulder. Aim away from the lens barrel to prevent veiling flare while tracing a crisp rim edge.</p>
<div class="spec-list">
<span class="spec-tag">Hue 195°</span>
<span class="spec-tag">Output 35%</span>
<span class="spec-tag">Grid 40°</span>
</div>
</article>
<article class="chapter-card" data-time="104" data-title="Ch. 3 · Atmospheric Haze">
<div class="chapter-top">
<span class="timestamp-chip">01:44</span>
<span style="font-size:0.75rem;color:var(--muted)">Depth Layering</span>
</div>
<h3>3. Controlling Haze Density for Volumetric Beams</h3>
<p>Pulse water-based haze for 4 seconds, then circulate with a silent fan so shafts stay even across takes. Monitor waveform midtones to keep black floor below 12 IRE.</p>
<div class="spec-list">
<span class="spec-tag">Black Floor 10 IRE</span>
<span class="spec-tag">Haze Level Low</span>
<span class="spec-tag">24 fps</span>
</div>
</article>
<article class="chapter-card" data-time="148" data-title="Ch. 4 · LUT & Skin Protection">
<div class="chapter-top">
<span class="timestamp-chip">02:28</span>
<span style="font-size:0.75rem;color:var(--muted)">Color Pipeline</span>
</div>
<h3>4. Protecting Skin Tones Against Cool Ambience</h3>
<p>Use a vectorscope qualifier to anchor skin along the flesh-tone line while pushing shadows toward slate blue. Avoid global saturation boosts that clip neon highlights.</p>
<div class="spec-list">
<span class="spec-tag">Rec.709</span>
<span class="spec-tag">Vectorscope Check</span>
<span class="spec-tag">Soft Clip</span>
</div>
</article>
</section>
</div>
<aside class="rail" aria-label="PiP docking controls">
<h2>PiP Snap Corners</h2>
<p style="font-size:0.82rem;color:var(--muted)">Drag the floating card anywhere on screen and release — it magnetically snaps to the nearest safe viewport corner, or pick one below:</p>
<div class="corner-grid">
<button class="corner-btn" data-corner="tl" type="button">↖ Top Left</button>
<button class="corner-btn" data-corner="tr" type="button">↗ Top Right</button>
<button class="corner-btn" data-corner="bl" type="button">↙ Bottom Left</button>
<button class="corner-btn active" data-corner="br" type="button">↘ Bottom Right</button>
</div>
<div class="status-line">
<div>Mode: <strong id="pipStateText">Floating (Bottom Right)</strong></div>
<div>Tip: Minimize PiP to a compact audio pill while reading dense notes.</div>
</div>
</aside>
</main>
<aside id="pipCard" class="pip-card visible" role="region" aria-label="Floating picture-in-picture reference card">
<div class="pip-header" id="pipHandle">
<div class="pip-drag-label">
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" opacity="0.65"><circle cx="9" cy="6" r="1.8"/><circle cx="15" cy="6" r="1.8"/><circle cx="9" cy="12" r="1.8"/><circle cx="15" cy="12" r="1.8"/><circle cx="9" cy="18" r="1.8"/><circle cx="15" cy="18" r="1.8"/></svg>
<span id="pipTitle">Ch. 1 · Key Light Ratio</span>
</div>
<div class="pip-controls">
<button id="pipMinBtn" class="pip-mini-btn" type="button" title="Minimize or expand" aria-label="Minimize PiP">—</button>
<button id="pipTopBtn" class="pip-mini-btn" type="button" title="Return to main stage" aria-label="Return to main player">⤢</button>
<button id="pipCloseBtn" class="pip-mini-btn" type="button" title="Hide PiP" aria-label="Close PiP">✕</button>
</div>
</div>
<div class="pip-video-wrap">
<canvas id="pipCanvas" width="320" height="180"></canvas>
</div>
<div class="pip-footer">
<button id="pipPlayBtn" class="pip-mini-btn" type="button" aria-label="Play or pause from PiP">❚❚</button>
<div class="pip-progress"><div id="pipProgressFill" class="pip-progress-fill"></div></div>
<span id="pipTime" class="pip-time">00:32</span>
</div>
</aside>
<script>
(() => {
const mainCanvas = document.getElementById('mainCanvas');
const pipCanvas = document.getElementById('pipCanvas');
const mainCtx = mainCanvas.getContext('2d');
const pipCtx = pipCanvas.getContext('2d');
const seekRange = document.getElementById('seekRange');
const curTimeLabel = document.getElementById('curTimeLabel');
const pipTime = document.getElementById('pipTime');
const pipProgressFill = document.getElementById('pipProgressFill');
const activeChapterLabel = document.getElementById('activeChapterLabel');
const pipTitle = document.getElementById('pipTitle');
const pipCard = document.getElementById('pipCard');
const pipHandle = document.getElementById('pipHandle');
const togglePipBtn = document.getElementById('togglePipBtn');
const pipStateText = document.getElementById('pipStateText');
const playPauseBtn = document.getElementById('playPauseBtn');
const pipPlayBtn = document.getElementById('pipPlayBtn');
const playIcon = document.getElementById('playIcon');
const cards = [...document.querySelectorAll('.chapter-card')];
const cornerBtns = [...document.querySelectorAll('.corner-btn')];
let playing = true;
let currentTime = 32;
const duration = 180;
let pipForcedVisible = true;
let pipCorner = 'br';
let dragging = false;
let dragOffsetX = 0, dragOffsetY = 0;
function fmt(sec) {
const s = Math.floor(sec);
const m = Math.floor(s / 60);
return String(m).padStart(2, '0') + ':' + String(s % 60).padStart(2, '0');
}
function updateChapterFromTime(t) {
let active = cards[0];
for (const c of cards) {
if (t >= Number(c.dataset.time)) active = c;
}
cards.forEach(c => c.classList.toggle('active', c === active));
activeChapterLabel.textContent = active.dataset.title;
pipTitle.textContent = active.dataset.title;
}
function syncUI() {
seekRange.value = Math.floor(currentTime);
const label = fmt(currentTime);
curTimeLabel.textContent = label;
pipTime.textContent = label;
pipProgressFill.style.width = ((currentTime / duration) * 100).toFixed(1) + '%';
updateChapterFromTime(currentTime);
}
function drawScene(ctx, w, h, t) {
const grad = ctx.createLinearGradient(0, 0, w, h);
const phase = (t / duration);
grad.addColorStop(0, '#091428');
grad.addColorStop(0.55, '#102542');
grad.addColorStop(1, '#07101E');
ctx.fillStyle = grad;
ctx.fillRect(0, 0, w, h);
// Volumetric key + cyan rim beams
const beamX = w * (0.28 + 0.14 * Math.sin(t * 0.4));
const keyGrad = ctx.createRadialGradient(beamX, h * 0.18, 6, beamX, h * 0.45, w * 0.55);
keyGrad.addColorStop(0, 'rgba(255, 214, 153, 0.34)');
keyGrad.addColorStop(1, 'rgba(255, 214, 153, 0)');
ctx.fillStyle = keyGrad;
ctx.fillRect(0, 0, w, h);
const rimGrad = ctx.createRadialGradient(w * 0.82, h * 0.25, 4, w * 0.72, h * 0.5, w * 0.48);
rimGrad.addColorStop(0, 'rgba(0, 173, 239, 0.46)');
rimGrad.addColorStop(1, 'rgba(0, 173, 239, 0)');
ctx.fillStyle = rimGrad;
ctx.fillRect(0, 0, w, h);
// Studio floor grid
ctx.strokeStyle = 'rgba(148, 163, 184, 0.14)';
ctx.lineWidth = 1;
for (let i = 1; i <= 5; i++) {
const y = h * 0.65 + i * (h * 0.07);
ctx.beginPath(); ctx.moveTo(0, y); ctx.lineTo(w, y); ctx.stroke();
}
// Subject silhouette + lighting rim arc
const cx = w * 0.5, cy = h * 0.56, r = h * 0.16;
ctx.fillStyle = '#0B1324';
ctx.beginPath(); ctx.arc(cx, cy - r * 0.85, r * 0.58, 0, Math.PI * 2); ctx.fill();
ctx.beginPath(); ctx.ellipse(cx, cy + r * 0.8, r * 1.15, r * 0.95, 0, Math.PI, Math.PI * 2); ctx.fill();
ctx.strokeStyle = '#38BDF8';
ctx.lineWidth = Math.max(2, w * 0.005);
ctx.beginPath();
ctx.arc(cx, cy - r * 0.85, r * 0.6, -Math.PI * 0.35, Math.PI * 0.32);
ctx.stroke();
// Live animated waveform strip
ctx.strokeStyle = 'rgba(0, 173, 239, 0.75)';
ctx.lineWidth = 1.6;
ctx.beginPath();
for (let x = 16; x < w - 16; x += 6) {
const y = h * 0.86 + Math.sin(x * 0.05 + t * 3.2) * (h * 0.03) * Math.cos(phase * 6 + x * 0.01);
if (x === 16) ctx.moveTo(x, y); else ctx.lineTo(x, y);
}
ctx.stroke();
// REC HUD
ctx.fillStyle = 'rgba(241, 245, 249, 0.85)';
ctx.font = `600 ${Math.round(h * 0.055)}px ui-monospace, monospace`;
ctx.fillText(`CAM A · 24FPS · ${fmt(t)}`, w * 0.04, h * 0.11);
}
let lastTs = performance.now();
function tick(now) {
const dt = (now - lastTs) / 1000;
lastTs = now;
if (playing) {
currentTime = (currentTime + dt) % duration;
syncUI();
}
drawScene(mainCtx, mainCanvas.width, mainCanvas.height, currentTime);
drawScene(pipCtx, pipCanvas.width, pipCanvas.height, currentTime);
requestAnimationFrame(tick);
}
function setPlayState(next) {
playing = next;
pipPlayBtn.textContent = playing ? '❚❚' : '▶';
playIcon.innerHTML = playing
? '<rect x="6" y="5" width="4" height="14" rx="1"/><rect x="14" y="5" width="4" height="14" rx="1"/>'
: '<polygon points="7,5 20,12 7,19"/>';
}
function snapToCorner(corner) {
pipCorner = corner;
const pad = 14;
const topSafe = 74;
const rect = pipCard.getBoundingClientRect();
const w = rect.width || 296;
const h = rect.height || 210;
const vw = window.innerWidth;
const vh = window.innerHeight;
const left = (corner === 'tl' || corner === 'bl') ? pad : Math.max(pad, vw - w - pad);
const top = (corner === 'tl' || corner === 'tr') ? topSafe : Math.max(topSafe, vh - h - pad);
pipCard.style.left = left + 'px';
pipCard.style.top = top + 'px';
cornerBtns.forEach(b => b.classList.toggle('active', b.dataset.corner === corner));
const names = { tl: 'Top Left', tr: 'Top Right', bl: 'Bottom Left', br: 'Bottom Right' };
pipStateText.textContent = (pipCard.classList.contains('visible') ? 'Floating' : 'Docked') + ' (' + names[corner] + ')';
}
playPauseBtn.addEventListener('click', () => setPlayState(!playing));
pipPlayBtn.addEventListener('click', () => setPlayState(!playing));
seekRange.addEventListener('input', () => { currentTime = Number(seekRange.value); syncUI(); });
cards.forEach(card => {
card.addEventListener('click', () => {
currentTime = Number(card.dataset.time);
syncUI();
});
});
document.getElementById('scrollNotesBtn').addEventListener('click', () => {
document.getElementById('notesSection').scrollIntoView({ behavior: 'smooth' });
});
togglePipBtn.addEventListener('click', () => {
pipForcedVisible = !pipForcedVisible;
pipCard.classList.toggle('visible', pipForcedVisible);
togglePipBtn.classList.toggle('active', pipForcedVisible);
togglePipBtn.setAttribute('aria-pressed', String(pipForcedVisible));
snapToCorner(pipCorner);
});
document.getElementById('pipCloseBtn').addEventListener('click', () => {
pipForcedVisible = false;
pipCard.classList.remove('visible');
togglePipBtn.classList.remove('active');
togglePipBtn.setAttribute('aria-pressed', 'false');
snapToCorner(pipCorner);
});
document.getElementById('pipMinBtn').addEventListener('click', (e) => {
pipCard.classList.toggle('minimized');
e.currentTarget.textContent = pipCard.classList.contains('minimized') ? '+' : '—';
requestAnimationFrame(() => snapToCorner(pipCorner));
});
document.getElementById('pipTopBtn').addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
cornerBtns.forEach(btn => btn.addEventListener('click', () => {
pipForcedVisible = true;
pipCard.classList.add('visible');
togglePipBtn.classList.add('active');
snapToCorner(btn.dataset.corner);
}));
// Auto-dock PiP when main stage scrolls out of view
const io = new IntersectionObserver((entries) => {
const mainInView = entries[0].isIntersecting;
if (!mainInView && !pipCard.classList.contains('visible')) {
pipForcedVisible = true;
pipCard.classList.add('visible');
togglePipBtn.classList.add('active');
snapToCorner(pipCorner);
}
}, { threshold: 0.25 });
io.observe(document.getElementById('heroStage'));
// Pointer drag + magnetic corner snap
pipHandle.addEventListener('pointerdown', (e) => {
if (e.target.closest('button')) return;
dragging = true;
pipCard.classList.add('dragging');
const r = pipCard.getBoundingClientRect();
dragOffsetX = e.clientX - r.left;
dragOffsetY = e.clientY - r.top;
pipHandle.setPointerCapture(e.pointerId);
});
pipHandle.addEventListener('pointermove', (e) => {
if (!dragging) return;
const x = Math.max(8, Math.min(window.innerWidth - pipCard.offsetWidth - 8, e.clientX - dragOffsetX));
const y = Math.max(66, Math.min(window.innerHeight - pipCard.offsetHeight - 8, e.clientY - dragOffsetY));
pipCard.style.left = x + 'px';
pipCard.style.top = y + 'px';
});
function finishDrag() {
if (!dragging) return;
dragging = false;
pipCard.classList.remove('dragging');
const r = pipCard.getBoundingClientRect();
const cx = r.left + r.width / 2;
const cy = r.top + r.height / 2;
const horiz = cx < window.innerWidth / 2 ? 'l' : 'r';
const vert = cy < window.innerHeight / 2 ? 't' : 'b';
snapToCorner(vert + horiz);
}
pipHandle.addEventListener('pointerup', finishDrag);
pipHandle.addEventListener('pointercancel', finishDrag);
window.addEventListener('resize', () => snapToCorner(pipCorner));
syncUI();
snapToCorner('br');
requestAnimationFrame(tick);
})();
</script>
</body>
</html>