kitbash Sign in Connect agent
Components

Film player

A project page: index, client and deliverables, a 4px progress bar you can seek, and control pairs (play/pause, mute/unmute, minimize/fullscreen, time) where the live word is big. Shots slide sideways and widen; Project details fades the film for the brief and a full-width wordmark.

Part of the style

Heat Reel

6 parts that belong together, with their tokens, type and rules.

Preview

Code
<style>
/* Goes after the pack's base.css */
@import url("https://fonts.googleapis.com/css2?family=Archivo:wdth,wght@125,800;125,900&family=Inter+Tight:wght@400;500&family=IBM+Plex+Mono:wght@400;500&display=swap");
:root {
  --font-text: "Inter Tight", "Helvetica Neue", Arial, sans-serif;
  --font-mark: "Archivo", "Helvetica Neue", Arial, sans-serif;
}
</style>

<section class="player" aria-label="Vell Foundry, Bell Night">
  <header class="player__head">
    <p class="player__index"><span class="player__shot-no">01</span> / <span class="player__shot-of">04</span></p>
    <div class="player__titles">
      <span class="player__label">Client</span>
      <h2 class="player__title">Vell Foundry</h2>
      <span class="player__label player__label--second">Deliverables</span>
      <p class="player__title player__title--work">Creative + Production + Post</p>
    </div>
  </header>

  <div class="player__bar" role="slider" tabindex="0" aria-label="Seek" aria-valuemin="0" aria-valuemax="48" aria-valuenow="0" aria-valuetext="00:00 of 00:48">
    <div class="player__fill"><span class="player__handle"></span></div>
  </div>

  <div class="player__controls">
    <button class="player__pair player__pair--play" type="button" aria-label="Pause"><span class="player__word player__word--off">Play</span><span class="player__word player__word--on">Pause</span></button>
    <button class="player__pair player__pair--sound" type="button" aria-label="Unmute"><span class="player__word player__word--off">Mute</span><span class="player__word player__word--on">Unmute</span></button>
    <button class="player__pair player__pair--size" type="button" aria-label="Fullscreen"><span class="player__word player__word--off">Minimize</span><span class="player__word player__word--on">Fullscreen</span></button>
    <p class="player__clock"><span class="player__now">00:00</span>&nbsp;/ <span class="player__total">00:48</span></p>
  </div>

  <div class="player__stage">
    <div class="player__aside">
      <button class="player__details" type="button" aria-expanded="false">
        <svg class="player__sign" viewBox="0 0 10 10" aria-hidden="true"><path class="player__sign-h" d="M1 4.25h8v1.5H1z"/><path class="player__sign-v" d="M4.25 1h1.5v8h-1.5z"/></svg>
        <span class="player__details-text"><span class="player__details-open">Project details</span><span class="player__details-close">Hide details</span></span>
      </button>
      <button class="player__return" type="button">Return</button>
    </div>

    <div class="player__info" inert>
      <p class="player__info-label">Info</p>
      <p class="player__info-text">Bell Night follows one casting at a family bell foundry, from the furnace lit at dusk to the last mould knocked out at dawn. Shot over a single night with two cameras and no added light, then cut to the toll of the finished bell.</p>
      <p class="player__info-label">Credits</p>
      <p class="player__info-text">Direction and camera: Ines Talor. Sound: Okke Brand. Grade: in house. Foundry: the Vell family, fourth generation.</p>
    </div>
    <p class="player__mark" aria-hidden="true">HOTWORK</p>

    <div class="player__strip">
      <div class="player__track"></div>
    </div>
  </div>
</section>

<style>
  .player {
    --player-col: calc((100cqw - 2 * var(--edge) - 11 * var(--gutter)) / 12);
    --player-span4: calc(var(--player-col) * 4 + var(--gutter) * 3);
    --player-span8: calc(var(--player-col) * 8 + var(--gutter) * 7);
    --player-full: calc(100cqw - 2 * var(--edge));
    container-type: inline-size;
    display: flex;
    flex-direction: column;
    height: var(--stage);
    padding: var(--edge);
    overflow: hidden;
    background: var(--paper);
    color: var(--ink);
  }
  .player p, .player h2 { margin: 0; }

  .player__head {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    column-gap: var(--gutter);
    align-items: start;
  }
  .player__index { grid-column: 1 / 3; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
  .player__titles {
    grid-column: 3 / -1;
    display: grid;
    grid-template-columns: max-content max-content minmax(0, 1fr);
    column-gap: var(--space-s);
    row-gap: 8px;
    align-items: start;
  }
  .player__label { color: var(--ink-soft); line-height: 1; padding-top: 0.1em; }
  .player__label--second { grid-column: 2; }
  .player__title {
    grid-column: 2 / -1;
    font: inherit;
    font-stretch: inherit;
    font-size: var(--text-title);
    line-height: 0.7;
    letter-spacing: var(--tracking-title);
    padding-top: 0.03em;
  }
  .player__title--work { grid-column: 3; }

  /* Seek bar: grey rail, ink fill, a small handle that shows on hover. */
  .player__bar {
    position: relative;
    margin-top: clamp(32px, 4.4vw, 64px);
    height: var(--tap);
    margin-bottom: calc((var(--tap) - var(--bar)) / -2);
    translate: 0 calc((var(--tap) - var(--bar)) / -2);
    cursor: pointer;
    outline: none;
  }
  .player__bar::before,
  .player__fill {
    position: absolute;
    left: 0;
    top: 50%;
    height: var(--bar);
    translate: 0 -50%;
  }
  .player__bar::before { content: ""; right: 0; background: var(--ink-soft); }
  .player__fill { width: calc(var(--progress, 0) * 100%); background: var(--ink); }
  .player__handle {
    position: absolute;
    right: 0;
    top: 50%;
    width: 4px;
    height: 8px;
    translate: 0 -50%;
    background: var(--ink);
    opacity: 0;
    transition: opacity 0.25s var(--ease-glide);
  }
  .player__bar:hover .player__handle,
  .player__bar.is-dragging .player__handle,
  .player__bar:focus-visible .player__handle { opacity: 1; }
  .player__bar:focus-visible::before { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink); }

  /* Control pairs: the action you can take is big and ink, the other word small and grey. */
  .player__controls {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    column-gap: var(--gutter);
    align-items: start;
    margin-top: var(--gutter);
  }
  .player__pair {
    display: flex;
    align-items: flex-start;
    gap: var(--space-s);
    min-height: var(--tap);
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    font-stretch: inherit;
    text-transform: inherit;
    cursor: pointer;
    white-space: nowrap;
  }
  .player__pair--play { grid-column: 1 / 4; justify-self: start; }
  .player__pair--sound { grid-column: 4 / 7; justify-self: start; }
  .player__pair--size { grid-column: 7 / 10; justify-self: end; }
  .player__clock { grid-column: 10 / 13; justify-self: end; display: flex; align-items: flex-start; color: var(--ink-soft); font-variant-numeric: tabular-nums; line-height: 1; }
  .player__total { margin-left: 4px; color: var(--ink); font-size: var(--text-control); line-height: var(--leading-control); }
  .player__word {
    color: var(--ink-soft);
    font-size: var(--text);
    line-height: 1;
    transition: color var(--time-hover) var(--ease-glide), font-size var(--time-hover) var(--ease-glide), line-height var(--time-hover) var(--ease-glide);
  }
  .player__pair:not(.is-alt) .player__word--on,
  .player__pair.is-alt .player__word--off { color: var(--ink); font-size: var(--text-control); line-height: var(--leading-control); }
  @media (hover: hover) {
    .player__pair:hover .player__word { color: var(--ink); }
  }
  .player__pair:focus-visible,
  .player__shot:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
  .player__details:focus-visible,
  .player__return:focus-visible {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
    outline: none;
  }

  /* Stage: shots slide in from the right and the current one widens; details fade over them. */
  .player__stage {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
  }
  .player__aside {
    position: absolute;
    top: clamp(24px, 5vw, 72px);
    right: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }
  .player__details,
  .player__return {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--ink);
    font: inherit;
    font-stretch: inherit;
    text-transform: inherit;
    line-height: var(--leading-list);
    cursor: pointer;
    transition: color var(--time-hover) var(--ease-glide);
  }
  .player__sign { width: 9px; height: 9px; flex: none; }
  .player__sign path { fill: currentColor; transition: fill var(--time-hover) var(--ease-glide), opacity var(--time-hover) var(--ease-glide); }
  .player__details-text { position: relative; display: grid; justify-items: end; }
  .player__details-open,
  .player__details-close { grid-area: 1 / 1; transition: opacity var(--time-hover) var(--ease-glide); }
  .player__details-close { opacity: 0; color: var(--ink-soft); }
  .player.is-details .player__details-open { opacity: 0; }
  .player.is-details .player__details-close { opacity: 1; }
  .player.is-details .player__sign-v { opacity: 0; }
  @media (hover: hover) {
    .player__details:hover .player__sign path { fill: var(--ink-soft); }
    .player.is-details .player__details:hover .player__details-close { color: var(--ink); }
    .player__return:hover { color: var(--ink-soft); }
  }

  .player__info {
    position: absolute;
    top: clamp(24px, 5vw, 72px);
    left: calc(var(--player-col) * 4 + var(--gutter) * 4);
    width: var(--player-span4);
    display: grid;
    gap: var(--space-s);
    opacity: 0;
    transition: opacity var(--time-hover) var(--ease-glide) 0s;
  }
  .player__info-label { color: var(--ink-soft); line-height: var(--leading-list); }
  .player__info-text { line-height: var(--leading-list); margin-bottom: var(--space-m) !important; text-wrap: pretty; }
  .player__mark {
    position: absolute;
    left: -0.05em;
    bottom: -0.03em;
    font-family: var(--font-mark);
    font-weight: var(--weight-mark);
    font-stretch: var(--stretch-mark);
    font-size: calc(var(--player-full) / 6.3);
    line-height: 0.74;
    letter-spacing: var(--tracking-mark);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--time-hover) var(--ease-glide) 0s;
  }
  .player.is-details .player__info,
  .player.is-details .player__mark { opacity: 1; transition-delay: 0.15s; }

  .player__strip { position: relative; }
  .player__track {
    display: flex;
    align-items: flex-end;
    gap: var(--gutter);
    transform: translate3d(calc(var(--shot, 0) * -1 * (var(--player-span4) + var(--gutter))), 0, 0);
    transition: transform var(--time-track) var(--ease-snap), opacity var(--time-hover) var(--ease-glide) 0.15s;
    will-change: transform;
  }
  .player.is-details .player__track { opacity: 0; transition: transform var(--time-track) var(--ease-snap), opacity var(--time-hover) var(--ease-glide) 0s; }
  .player__shot {
    position: relative;
    flex: 0 0 auto;
    width: var(--player-span4);
    aspect-ratio: 16 / 9;
    padding: 0;
    border: 0;
    background: var(--film);
    cursor: pointer;
    transition: width var(--time-track) var(--ease-snap);
    will-change: width;
  }
  .player__shot.is-current { width: min(var(--player-span8), var(--player-room, 100cqw) * 16 / 9); cursor: default; }
  .player.is-full .player__shot.is-current { width: min(var(--player-full), var(--player-room, 100cqw) * 16 / 9); }
  .player.is-full .player__track { transform: translate3d(calc(var(--shot, 0) * -1 * (var(--player-span4) + var(--gutter))), 0, 0); }
  .player__shot canvas { width: 100%; height: 100%; }
  .player__veil {
    position: absolute;
    inset: 0;
    background: var(--ink-soft);
    pointer-events: none;
    transition: opacity var(--time-hover) var(--ease-glide) var(--time-swap);
  }
  .player__shot.is-loaded .player__veil { opacity: 0; }
  .player__cap {
    position: absolute;
    left: 0;
    bottom: calc(100% + 6px);
    color: var(--ink-soft);
    white-space: nowrap;
    line-height: 1;
    opacity: 0;
    transition: opacity var(--time-hover) var(--ease-glide);
  }
  @media (hover: hover) {
    .player__shot:not(.is-current):hover .player__cap { opacity: 1; }
  }

  @media (max-width: 54.6rem) {
    .player { height: auto; padding: var(--space-s); }
    .player__index { display: none; }
    .player__title--work { font-size: var(--text); line-height: var(--leading-list); letter-spacing: 0; padding-top: 0; }
    .player__titles { grid-column: 1 / -1; }
    .player__controls { grid-template-columns: 1fr 1fr; row-gap: var(--space-s); }
    .player__pair--play, .player__pair--sound, .player__pair--size, .player__clock { grid-column: auto; justify-self: start; }
    .player__clock { justify-self: end; }
    .player__pair--sound { justify-self: end; }
    .player__stage { margin-top: var(--space-l); }
    .player__aside { position: static; margin-bottom: var(--space-s); }
    .player__info { position: static; width: auto; display: none; }
    .player.is-details .player__info { display: grid; }
    .player__mark { display: none; }
    .player__strip { overflow: hidden; margin-inline: calc(var(--space-s) * -1); padding-inline: var(--space-s); }
    .player__shot, .player__shot.is-current, .player.is-full .player__shot.is-current { width: calc(100cqw - 2 * var(--space-s)); }
    .player__track, .player.is-full .player__track { transform: translate3d(calc(var(--shot, 0) * -1 * (100cqw - 2 * var(--space-s) + var(--gutter))), 0, 0); }
    .player.is-details .player__track { display: none; }
  }
  /* Touch: the stacked details and return lines grow to a finger's height. */
  @media (pointer: coarse), (max-width: 54.6rem) {
    .player__details, .player__return { min-height: var(--tap); min-width: var(--tap); }
  }
</style>

<script>
(() => {
  const SHOTS = [
    { scene: 'pour', name: 'The pour', length: 12 },
    { scene: 'crucible', name: 'Crucible', length: 12 },
    { scene: 'ingots', name: 'Cooling', length: 12 },
    { scene: 'yard', name: 'Dawn yard', length: 12 },
  ];
  const TOTAL = SHOTS.reduce((sum, shot) => sum + shot.length, 0);
  const FPS = 24;
  const still = matchMedia('(prefers-reduced-motion: reduce)');
  const pad = (n) => String(n).padStart(2, '0');
  const clock = (s) => `${pad(Math.floor(s / 60))}:${pad(Math.floor(s % 60))}`;
  const hash = (n) => { const x = Math.sin(n * 127.1 + 311.7) * 43758.5453; return x - Math.floor(x); };

  /* ---------- drawn footage ---------- */

  const GRAIN = (() => {
    const tile = document.createElement('canvas');
    tile.width = tile.height = 128;
    const g = tile.getContext('2d');
    const img = g.createImageData(128, 128);
    for (let i = 0; i < img.data.length; i += 4) {
      const v = Math.random() * 255;
      img.data[i] = img.data[i + 1] = img.data[i + 2] = v;
      img.data[i + 3] = 255;
    }
    g.putImageData(img, 0, 0);
    return tile;
  })();

  function glow(c, x, y, r, stops) {
    const g = c.createRadialGradient(x, y, 0, x, y, r);
    stops.forEach(([at, color]) => g.addColorStop(at, color));
    c.fillStyle = g;
    c.fillRect(x - r, y - r, r * 2, r * 2);
  }

  function finish(c, w, h, t, warmth) {
    const v = c.createRadialGradient(w / 2, h / 2, Math.min(w, h) * 0.25, w / 2, h / 2, Math.hypot(w, h) * 0.62);
    v.addColorStop(0, 'rgba(0,0,0,0)');
    v.addColorStop(1, 'rgba(0,0,0,0.55)');
    c.fillStyle = v;
    c.fillRect(0, 0, w, h);
    c.save();
    c.globalCompositeOperation = 'soft-light';
    c.fillStyle = warmth;
    c.fillRect(0, 0, w, h);
    c.globalCompositeOperation = 'overlay';
    c.globalAlpha = 0.13;
    const frame = Math.floor(t * FPS);
    c.translate(-hash(frame) * 128, -hash(frame + 9) * 128);
    c.fillStyle = c.createPattern(GRAIN, 'repeat');
    c.fillRect(0, 0, w + 128, h + 128);
    c.restore();
  }

  const SCENES = {
    pour(c, w, h, t) {
      c.fillStyle = '#0d0b0a'; c.fillRect(0, 0, w, h);
      glow(c, w * 0.6, h * 0.95, w * 0.5, [[0, 'rgba(255,110,30,0.4)'], [1, 'rgba(255,110,30,0)']]);
      c.fillStyle = '#1c1512';
      c.beginPath(); c.moveTo(w * 0.18, -h * 0.1); c.lineTo(w * 0.47, h * 0.06); c.lineTo(w * 0.44, h * 0.26); c.lineTo(w * 0.12, h * 0.16); c.fill();
      c.strokeStyle = 'rgba(255,150,70,0.55)'; c.lineWidth = 2;
      c.beginPath(); c.moveTo(w * 0.47, h * 0.06); c.lineTo(w * 0.44, h * 0.26); c.stroke();
      c.globalCompositeOperation = 'lighter';
      const sway = Math.sin(t * 2.7) * w * 0.004;
      const stream = (width, color) => {
        c.strokeStyle = color; c.lineWidth = width; c.lineCap = 'round';
        c.beginPath(); c.moveTo(w * 0.455, h * 0.2);
        c.bezierCurveTo(w * 0.52, h * 0.26, w * 0.6 + sway, h * 0.45, w * 0.605 + sway, h * 0.86); c.stroke();
      };
      stream(h * 0.08, 'rgba(255,90,20,0.22)');
      stream(h * 0.045, 'rgba(255,140,50,0.6)');
      stream(h * 0.018, 'rgba(255,232,176,0.95)');
      glow(c, w * 0.605, h * 0.88, h * 0.3, [[0, 'rgba(255,240,200,0.95)'], [0.3, 'rgba(255,140,40,0.6)'], [1, 'rgba(255,80,20,0)']]);
      for (let i = 0; i < 90; i++) {
        const life = 0.6 + hash(i) * 0.9, p = ((t / life) + hash(i + 40)) % 1;
        const vx = (hash(i + 80) - 0.5) * w * 0.7, vy = -(0.4 + hash(i + 120)) * h * 1.2;
        const x = w * 0.605 + vx * p, y = h * 0.86 + vy * p + h * 1.5 * p * p;
        const dx = vx * 0.03, dy = (vy + h * 3 * p) * 0.03;
        c.strokeStyle = `rgba(255,${190 + hash(i + 3) * 60},120,${(1 - p) * 0.9})`;
        c.lineWidth = 1 + hash(i + 5) * 1.2;
        c.beginPath(); c.moveTo(x, y); c.lineTo(x - dx, y - dy); c.stroke();
      }
      c.globalCompositeOperation = 'source-over';
      c.fillStyle = '#120d0b';
      c.beginPath(); c.ellipse(w * 0.605, h * 1.02, w * 0.24, h * 0.13, 0, 0, Math.PI * 2); c.fill();
      c.strokeStyle = 'rgba(255,150,70,0.6)'; c.lineWidth = 1.5;
      c.beginPath(); c.ellipse(w * 0.605, h * 1.02, w * 0.24, h * 0.13, 0, Math.PI * 1.08, Math.PI * 1.92); c.stroke();
      finish(c, w, h, t, 'rgba(255,120,40,0.18)');
    },

    crucible(c, w, h, t) {
      c.fillStyle = '#100c0a'; c.fillRect(0, 0, w, h);
      const cx = w * 0.5, cy = h * 0.52, R = h * 0.44;
      glow(c, cx, cy, R * 1.9, [[0, 'rgba(255,100,30,0.35)'], [1, 'rgba(255,100,30,0)']]);
      const ring = c.createRadialGradient(cx - R * 0.3, cy - R * 0.4, R * 0.2, cx, cy, R * 1.25);
      ring.addColorStop(0, '#4a3d35'); ring.addColorStop(1, '#1d1714');
      c.fillStyle = ring; c.beginPath(); c.arc(cx, cy, R * 1.22, 0, Math.PI * 2); c.fill();
      const melt = c.createRadialGradient(cx - R * 0.15, cy - R * 0.2, 0, cx, cy, R);
      melt.addColorStop(0, '#fff3cf'); melt.addColorStop(0.45, '#ffb04a'); melt.addColorStop(0.85, '#e8561a'); melt.addColorStop(1, '#7a1e08');
      c.fillStyle = melt; c.beginPath(); c.arc(cx, cy, R, 0, Math.PI * 2); c.fill();
      c.save(); c.beginPath(); c.arc(cx, cy, R * 0.98, 0, Math.PI * 2); c.clip();
      for (let i = 0; i < 14; i++) {
        const a = hash(i) * 6.283 + t * (0.1 + hash(i + 4) * 0.08), r = R * (0.35 + hash(i + 8) * 0.6);
        const x = cx + Math.cos(a) * r, y = cy + Math.sin(a) * r, size = R * (0.12 + hash(i + 6) * 0.2);
        glow(c, x, y, size, [[0, `rgba(90,30,10,${0.35 + hash(i + 2) * 0.3})`], [0.6, 'rgba(120,40,12,0.18)'], [1, 'rgba(120,40,12,0)']]);
      }
      const crust = c.createRadialGradient(cx, cy, R * 0.8, cx, cy, R);
      crust.addColorStop(0, 'rgba(110,32,10,0)'); crust.addColorStop(1, 'rgba(70,20,8,0.75)');
      c.fillStyle = crust; c.fillRect(cx - R, cy - R, R * 2, R * 2);
      c.restore();
      c.strokeStyle = 'rgba(255,240,210,0.6)'; c.lineWidth = h * 0.008;
      c.beginPath(); c.arc(cx, cy, R * 1.01, 3.5, 4.4); c.stroke();
      c.globalCompositeOperation = 'lighter';
      for (let k = 0; k < 3; k++) {
        const p = ((t * 0.12) + k / 3) % 1;
        glow(c, cx + Math.sin(t * 0.4 + k) * w * 0.1, cy - p * h * 0.9, h * (0.2 + p * 0.25), [[0, `rgba(255,160,90,${0.07 * (1 - p)})`], [1, 'rgba(255,160,90,0)']]);
      }
      c.globalCompositeOperation = 'source-over';
      finish(c, w, h, t, 'rgba(255,120,40,0.2)');
    },

    ingots(c, w, h, t) {
      const floor = c.createLinearGradient(0, 0, 0, h);
      floor.addColorStop(0, '#120f0d'); floor.addColorStop(0.55, '#1f1915'); floor.addColorStop(1, '#2e2520');
      c.fillStyle = floor; c.fillRect(0, 0, w, h);
      const count = 5, gap = w * 0.03, iw = (w * 0.9 - gap * (count - 1)) / count, ih = h * 0.22, y = h * 0.5, lip = ih * 0.35;
      for (let i = 0; i < count; i++) {
        const x = w * 0.05 + i * (iw + gap);
        const cool = Math.min(1, Math.max(0, t * 0.06 + i * 0.16 - 0.08));
        const r = Math.round(255 - cool * 175), g = Math.round(150 - cool * 100), b = Math.round(60 - cool * 18);
        c.fillStyle = '#0b0907';
        c.beginPath(); c.moveTo(x - iw * 0.05, y + ih * 1.12); c.lineTo(x + iw * 1.05, y + ih * 1.12); c.lineTo(x + iw * 0.97, y - lip * 0.2); c.lineTo(x + iw * 0.03, y - lip * 0.2); c.fill();
        const top = c.createLinearGradient(x, y - lip, x, y + lip);
        top.addColorStop(0, `rgb(${Math.min(255, r + 40)},${Math.min(255, g + 70)},${b + 70})`);
        top.addColorStop(1, `rgb(${r},${g},${b})`);
        c.fillStyle = top;
        c.beginPath(); c.moveTo(x + iw * 0.06, y - lip); c.lineTo(x + iw * 0.94, y - lip); c.lineTo(x + iw, y); c.lineTo(x, y); c.fill();
        const face = c.createLinearGradient(x, y, x, y + ih);
        face.addColorStop(0, `rgb(${r - 30},${Math.max(24, g - 50)},${Math.max(18, b - 20)})`);
        face.addColorStop(1, `rgb(${Math.max(30, r - 120)},${Math.max(22, g - 90)},${Math.max(18, b - 30)})`);
        c.fillStyle = face; c.fillRect(x, y, iw, ih);
        c.strokeStyle = `rgba(255,230,190,${0.5 * (1 - cool) + 0.08})`; c.lineWidth = 1;
        c.beginPath(); c.moveTo(x + iw * 0.06, y - lip); c.lineTo(x + iw * 0.94, y - lip); c.stroke();
        if (cool < 0.85) {
          c.globalCompositeOperation = 'lighter';
          glow(c, x + iw / 2, y, iw * 1.2, [[0, `rgba(255,120,40,${0.32 * (1 - cool)})`], [1, 'rgba(255,120,40,0)']]);
          glow(c, x + iw / 2, y + ih * 1.6, iw * 0.9, [[0, `rgba(255,110,40,${0.18 * (1 - cool)})`], [1, 'rgba(255,110,40,0)']]);
          c.globalCompositeOperation = 'source-over';
        }
        for (let k = 0; k < 2; k++) {
          const p = ((t * 0.18) + hash(i * 3 + k)) % 1;
          glow(c, x + iw * (0.3 + k * 0.4) + Math.sin(t + i) * iw * 0.1, y - lip - p * h * 0.42, iw * (0.3 + p * 0.45),
            [[0, `rgba(210,200,190,${0.14 * (1 - p) * (1 - cool * 0.6)})`], [1, 'rgba(210,200,190,0)']]);
        }
      }
      glow(c, w * 0.35, -h * 0.25, w * 0.7, [[0, 'rgba(150,175,205,0.16)'], [1, 'rgba(150,175,205,0)']]);
      finish(c, w, h, t, 'rgba(255,140,60,0.15)');
    },

    yard(c, w, h, t) {
      const sky = c.createLinearGradient(0, 0, 0, h * 0.75);
      sky.addColorStop(0, '#1a2333'); sky.addColorStop(0.6, '#5a4a52'); sky.addColorStop(1, '#d3804a');
      c.fillStyle = sky; c.fillRect(0, 0, w, h);
      glow(c, w * 0.78, h * 0.74, w * 0.45, [[0, 'rgba(255,190,120,0.55)'], [1, 'rgba(255,190,120,0)']]);
      for (let k = 0; k < 6; k++) {
        const p = ((t * 0.05) + k / 6) % 1;
        glow(c, w * 0.31 + p * w * 0.35 + Math.sin(t * 0.3 + k) * w * 0.02, h * 0.18 - p * h * 0.25, h * (0.12 + p * 0.3),
          [[0, `rgba(120,110,120,${0.35 * (1 - p)})`], [1, 'rgba(120,110,120,0)']]);
      }
      c.fillStyle = '#0e0d10';
      c.beginPath();
      c.moveTo(0, h * 0.72); c.lineTo(w * 0.12, h * 0.72); c.lineTo(w * 0.12, h * 0.5); c.lineTo(w * 0.3, h * 0.38); c.lineTo(w * 0.3, h * 0.12);
      c.lineTo(w * 0.33, h * 0.12); c.lineTo(w * 0.33, h * 0.38); c.lineTo(w * 0.48, h * 0.5); c.lineTo(w * 0.48, h * 0.58); c.lineTo(w * 0.66, h * 0.58);
      c.lineTo(w * 0.66, h * 0.72); c.lineTo(w, h * 0.72); c.lineTo(w, h); c.lineTo(0, h); c.closePath(); c.fill();
      const lamp = 0.85 + Math.sin(t * 9) * 0.04;
      c.fillStyle = `rgba(255,170,90,${lamp})`;
      for (let i = 0; i < 4; i++) c.fillRect(w * (0.15 + i * 0.07), h * 0.56, w * 0.028, h * 0.05);
      c.fillStyle = `rgba(255,140,60,${lamp})`; c.fillRect(w * 0.53, h * 0.62, w * 0.08, h * 0.1);
      c.globalCompositeOperation = 'lighter';
      glow(c, w * 0.57, h * 0.72, w * 0.18, [[0, `rgba(255,140,60,${0.45 * lamp})`], [1, 'rgba(255,140,60,0)']]);
      c.globalCompositeOperation = 'source-over';
      c.fillStyle = '#08080a'; c.fillRect(0, h * 0.86, w, h * 0.14);
      finish(c, w, h, t, 'rgba(255,170,110,0.18)');
    },
  };

  /* ---------- the player ---------- */

  function setUp(root) {
    const track = root.querySelector('.player__track');
    const shots = SHOTS.map((shot, i) => {
      const button = document.createElement('button');
      button.type = 'button';
      button.className = 'player__shot';
      button.setAttribute('aria-label', `Shot ${i + 1}, ${shot.name}`);
      button.innerHTML = '<canvas aria-hidden="true"></canvas><span class="player__veil"></span><span class="player__cap"></span>';
      button.querySelector('.player__cap').textContent = `${pad(i + 1)} ${shot.name}`;
      track.append(button);
      return button;
    });
    const starts = SHOTS.map((_, i) => SHOTS.slice(0, i).reduce((sum, shot) => sum + shot.length, 0));
    const bar = root.querySelector('.player__bar');
    const now = root.querySelector('.player__now');
    const shotNo = root.querySelector('.player__shot-no');
    const play = root.querySelector('.player__pair--play');
    const sound = root.querySelector('.player__pair--sound');
    const size = root.querySelector('.player__pair--size');
    const details = root.querySelector('.player__details');
    const info = root.querySelector('.player__info');
    root.querySelector('.player__shot-of').textContent = pad(SHOTS.length);
    const stage = root.querySelector('.player__stage');
    new ResizeObserver(() => root.style.setProperty('--player-room', `${stage.clientHeight}px`)).observe(stage);
    root.querySelector('.player__total').textContent = clock(TOTAL);

    let time = 0;
    let playing = !still.matches;
    let onScreen = false;
    let current = -1;

    const shotAt = (s) => starts.reduce((found, start, i) => (s >= start ? i : found), 0);

    function show() {
      const i = shotAt(time);
      if (i !== current) {
        current = i;
        root.style.setProperty('--shot', i);
        shots.forEach((shot, k) => shot.classList.toggle('is-current', k === i));
        shotNo.textContent = pad(i + 1);
      }
      bar.style.setProperty('--progress', time / TOTAL);
      bar.setAttribute('aria-valuenow', Math.floor(time));
      bar.setAttribute('aria-valuetext', `${clock(time)} of ${clock(TOTAL)}`);
      now.textContent = clock(time);
    }

    /* A pair shows its second word big by default; is-alt makes the first word the big one. */
    function setPair(pair, alt, labelAlt, labelDefault) {
      pair.classList.toggle('is-alt', alt);
      pair.setAttribute('aria-label', alt ? labelAlt : labelDefault);
    }

    play.addEventListener('click', () => { playing = !playing; setPair(play, !playing, 'Play', 'Pause'); last = 0; });
    sound.addEventListener('click', () => setPair(sound, !sound.classList.contains('is-alt'), 'Mute', 'Unmute'));
    size.addEventListener('click', () => {
      const full = !root.classList.contains('is-full');
      root.classList.toggle('is-full', full);
      setPair(size, full, 'Minimize', 'Fullscreen');
    });
    function setDetails(open) {
      root.classList.toggle('is-details', open);
      details.setAttribute('aria-expanded', String(open));
      info.inert = !open;
      track.inert = open;
    }
    details.addEventListener('click', () => setDetails(!root.classList.contains('is-details')));
    root.querySelector('.player__return').addEventListener('click', () => { setDetails(false); time = 0; show(); paintAll(); });
    shots.forEach((shot, i) => shot.addEventListener('click', () => { if (i !== current) { time = starts[i]; show(); paintAll(); } }));

    function seekTo(clientX) {
      const box = bar.getBoundingClientRect();
      time = Math.min(TOTAL - 0.01, Math.max(0, (clientX - box.left) / box.width * TOTAL));
      show();
      paintAll();
    }
    bar.addEventListener('pointerdown', (event) => {
      bar.setPointerCapture(event.pointerId);
      bar.classList.add('is-dragging');
      seekTo(event.clientX);
    });
    bar.addEventListener('pointermove', (event) => { if (bar.classList.contains('is-dragging')) seekTo(event.clientX); });
    bar.addEventListener('pointerup', () => bar.classList.remove('is-dragging'));
    bar.addEventListener('keydown', (event) => {
      const step = { ArrowRight: 2, ArrowLeft: -2, Home: -TOTAL, End: TOTAL }[event.key];
      if (step === undefined) return;
      event.preventDefault();
      time = Math.min(TOTAL - 0.01, Math.max(0, time + step));
      show();
      paintAll();
    });

    /* footage */
    const sizes = new Map();
    function fit(canvas) {
      const density = Math.min(2, devicePixelRatio || 1);
      canvas.width = Math.round(canvas.clientWidth * density);
      canvas.height = Math.round(canvas.clientHeight * density);
      sizes.set(canvas, { w: canvas.clientWidth, h: canvas.clientHeight, density });
    }
    function paint(i) {
      const canvas = shots[i].firstChild;
      if (!sizes.has(canvas)) fit(canvas);
      const { w, h, density } = sizes.get(canvas);
      if (!w || !h) return;
      const c = canvas.getContext('2d');
      const local = i === current ? time - starts[i] + 3 : 3 + i;
      c.setTransform(density, 0, 0, density, 0, 0);
      c.save();
      const frame = Math.floor(local * FPS);
      if (playing && i === current) c.translate((hash(frame) - 0.5) * 0.6, (hash(frame + 3) - 0.5) * 0.6);
      SCENES[SHOTS[i].scene](c, w, h, local);
      c.restore();
    }
    function paintAll() { shots.forEach((_, i) => paint(i)); }
    new ResizeObserver((entries) => {
      for (const entry of entries) { fit(entry.target); }
      paintAll();
    }).observe(track);
    shots.forEach((shot) => new ResizeObserver(() => { fit(shot.firstChild); paint(shots.indexOf(shot)); }).observe(shot.firstChild));

    let frame = 0, last = 0;
    function tick(ms) {
      frame = requestAnimationFrame(tick);
      if (ms - last < 1000 / FPS) return;
      const elapsed = last ? (ms - last) / 1000 : 0;
      last = ms;
      if (playing) {
        time = (time + elapsed) % TOTAL;
        show();
        paint(current);
      }
    }
    function run() {
      cancelAnimationFrame(frame);
      last = 0;
      if (onScreen && !still.matches) frame = requestAnimationFrame(tick);
    }
    new IntersectionObserver(([entry]) => { onScreen = entry.isIntersecting; run(); }).observe(root);

    if (!playing) setPair(play, true, 'Play', 'Pause');
    show();
    requestAnimationFrame(paintAll);
    shots.forEach((shot, i) => setTimeout(() => shot.classList.add('is-loaded'), still.matches ? 0 : 520 + i * 130));
  }

  document.querySelectorAll('.player').forEach(setUp);
})();
</script>

Similar components

Orbit rings

Orbit rings

Plate

Plate

Showcase with progress tabs

Showcase with progress tabs

Theme flood

Theme flood

Instrument panel

Instrument panel

Word-by-word testimonial

Word-by-word testimonial

Flavour picker

Flavour picker

Ledger

Ledger