/*
  The reel: a small motion-graphics player for abhnv.in.

  Every film on the site is drawn live on a canvas by reel.js, so it stays
  sharp at any size, weighs a few kilobytes, reacts to the reader and can
  be scrubbed like video. This file is only the player furniture.
*/

.reel-section {
  position: relative;
  width: 100vw;
  margin: clamp(3rem, 7vw, 6rem) 0 0 calc(50% - 50vw);
  padding: clamp(2.6rem, 6vw, 5rem) clamp(0.75rem, 4vw, 4rem) clamp(2.6rem, 6vw, 4.5rem);
  color: var(--paper-light);
  background:
    radial-gradient(circle at 20% 0%, rgba(209, 90, 53, 0.16), transparent 40%),
    #12110f;
}

.reel-section::before,
.reel-section::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 14px;
  background: var(--paper);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='14' viewBox='0 0 60 14'%3E%3Cpath d='M0 0h60v6l-4 3-5-4-6 6-4-5-7 7-5-6-4 3-6-5-5 6-5-4-5 5-4-4V0z'/%3E%3C/svg%3E") 0 0 / 60px 14px repeat-x;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='14' viewBox='0 0 60 14'%3E%3Cpath d='M0 0h60v6l-4 3-5-4-6 6-4-5-7 7-5-6-4 3-6-5-5 6-5-4-5 5-4-4V0z'/%3E%3C/svg%3E") 0 0 / 60px 14px repeat-x;
}

.reel-section::before { top: -1px; }
.reel-section::after { bottom: -1px; transform: scaleY(-1); }

.reel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 1rem 2rem;
  max-width: 88rem;
  margin: 0 auto clamp(1.2rem, 3vw, 2rem);
}

.reel-kicker {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0 0.7rem;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--red-hot);
}

.reel-kicker i {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--red-hot);
  animation: reelBlink 1.1s steps(1) infinite;
}

@keyframes reelBlink {
  50% { opacity: 0.2; }
}

.reel-title {
  margin: 0;
  max-width: 16ch;
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(2.3rem, 6.4vw, 5.6rem);
  line-height: 0.9;
  letter-spacing: -0.015em;
  text-transform: uppercase;
  color: var(--paper-light);
}

.reel-title em {
  font-weight: 400;
  color: var(--red-hot);
}

.reel-note {
  max-width: 22rem;
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.45;
  color: rgba(234, 223, 206, 0.7);
}

/* The player */
.reel {
  position: relative;
  max-width: min(88rem, calc(76vh * 16 / 9));
  max-width: min(88rem, calc(76svh * 16 / 9));
  margin: 0 auto;
  color: var(--paper-light);
}

.reel-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #171612;
  border: 1px solid rgba(234, 223, 206, 0.18);
  box-shadow: 0 2rem 4rem rgba(0, 0, 0, 0.45);
  cursor: pointer;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
  isolation: isolate;
}

.reel-frame:focus-visible {
  outline: 2px solid var(--red-hot);
  outline-offset: 3px;
}

@media (max-width: 760px) {
  .reel-frame {
    aspect-ratio: 4 / 5;
  }

  .reel {
    max-width: min(100%, calc(72svh * 4 / 5));
  }
}

.reel-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.reel-grain {
  position: absolute;
  inset: -20%;
  z-index: 1;
  pointer-events: none;
  opacity: 0.1;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 160px 160px;
}

.reel.is-playing .reel-grain {
  animation: reelGrain 0.6s steps(6) infinite;
}

@keyframes reelGrain {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-4%, 3%); }
  40% { transform: translate(3%, -5%); }
  60% { transform: translate(-6%, -2%); }
  80% { transform: translate(5%, 4%); }
  100% { transform: translate(0, 0); }
}

.reel-vignette {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 50%, transparent 58%, rgba(0, 0, 0, 0.38) 100%);
}

.reel-hud {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: clamp(0.55rem, 1.4vw, 0.9rem) clamp(0.65rem, 1.6vw, 1rem);
  font-family: var(--mono);
  font-size: clamp(0.52rem, 1vw, 0.64rem);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  pointer-events: none;
  mix-blend-mode: difference;
  color: #eadfce;
}

.reel-hud span:first-child::before {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  margin-right: 0.55em;
  border-radius: 50%;
  background: #ff5a36;
  vertical-align: 0.05em;
}

.reel.is-paused .reel-hud span:first-child::before {
  background: transparent;
  box-shadow: inset 0 0 0 1px currentColor;
}

.reel-chapter {
  position: absolute;
  left: clamp(0.65rem, 1.6vw, 1rem);
  bottom: clamp(0.55rem, 1.4vw, 0.9rem);
  z-index: 2;
  padding: 0.3rem 0.5rem;
  font-family: var(--mono);
  font-size: clamp(0.52rem, 1vw, 0.64rem);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #171612;
  background: #eadfce;
  pointer-events: none;
}

.reel-chapter.is-swapping {
  animation: reelChapter 460ms cubic-bezier(0.19, 1, 0.22, 1);
}

@keyframes reelChapter {
  0% { clip-path: inset(0 100% 0 0); }
  100% { clip-path: inset(0 0 0 0); }
}

.reel-big-play {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  display: grid;
  place-items: center;
  width: clamp(4.2rem, 10vw, 6rem);
  aspect-ratio: 1;
  padding: 0;
  border: 1.5px solid rgba(234, 223, 206, 0.8);
  border-radius: 50%;
  color: #eadfce;
  background: rgba(23, 22, 18, 0.55);
  translate: -50% -50%;
  opacity: 0;
  scale: 0.8;
  pointer-events: none;
  transition: opacity 260ms ease, scale 360ms var(--ease);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.reel-big-play svg {
  width: 38%;
  height: 38%;
  margin-left: 8%;
}

.reel.is-paused .reel-big-play {
  opacity: 1;
  scale: 1;
  pointer-events: auto;
}

/* Transport bar */
.reel-bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(0.6rem, 1.6vw, 1rem);
  margin-top: 0.7rem;
}

.reel-btn {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 1px solid rgba(234, 223, 206, 0.35);
  border-radius: 50%;
  color: #eadfce;
  background: transparent;
  cursor: pointer;
  transition: background 200ms ease, border-color 200ms ease;
}

.reel-btn:hover,
.reel-btn:focus-visible {
  border-color: #eadfce;
  background: rgba(234, 223, 206, 0.08);
}

.reel-btn:focus-visible,
.reel-scrub:focus-visible {
  outline: 2px solid var(--red-hot);
  outline-offset: 2px;
}

.reel-btn svg {
  width: 1rem;
  height: 1rem;
}

.reel-btn .i-play { display: none; }
.reel.is-paused .reel-btn .i-play { display: block; }
.reel.is-paused .reel-btn .i-pause { display: none; }

.reel-scrub {
  position: relative;
  height: 2.75rem;
  cursor: pointer;
  touch-action: none;
}

.reel-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 3px;
  translate: 0 -50%;
  background: rgba(234, 223, 206, 0.18);
}

.reel-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #eadfce, var(--red-hot));
  transform-origin: 0 50%;
  transform: scaleX(var(--p, 0));
}

.reel-mark {
  position: absolute;
  top: 50%;
  width: 1px;
  height: 0.8rem;
  translate: 0 -50%;
  background: rgba(234, 223, 206, 0.5);
}

.reel-knob {
  position: absolute;
  top: 50%;
  left: calc(var(--p, 0) * 100%);
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: var(--red-hot);
  box-shadow: 0 0 0 4px rgba(209, 90, 53, 0.25);
  translate: -50% -50%;
  transition: scale 200ms ease;
}

.reel-scrub:hover .reel-knob,
.reel.is-scrubbing .reel-knob {
  scale: 1.3;
}

.reel-time {
  min-width: 6.6rem;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-align: right;
  color: rgba(234, 223, 206, 0.7);
  font-variant-numeric: tabular-nums;
}

.reel-chips {
  display: flex;
  gap: 0.4rem;
  margin: 0.6rem 0 0;
  padding: 0 0 0.2rem;
  overflow-x: auto;
  list-style: none;
  scrollbar-width: none;
}

.reel-chips::-webkit-scrollbar {
  display: none;
}

.reel-chips button {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  min-height: 2.4rem;
  padding: 0 0.8rem;
  border: 1px solid rgba(234, 223, 206, 0.22);
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(234, 223, 206, 0.7);
  background: transparent;
  cursor: pointer;
  transition: color 200ms ease, background 200ms ease, border-color 200ms ease;
}

.reel-chips button b {
  font-weight: 400;
  color: var(--red-hot);
}

.reel-chips button[aria-current="true"] {
  color: #171612;
  border-color: #eadfce;
  background: #eadfce;
}

.reel-chips button[aria-current="true"] b {
  color: var(--red);
}

.reel-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* In a case study the film sits on paper, in its own dark frame. */
.case-reel {
  margin: clamp(2rem, 5vw, 3.5rem) 0;
  padding: clamp(1rem, 3vw, 1.8rem);
  color: var(--paper-light);
  background: #12110f;
  box-shadow: 0.35rem 0.35rem 0 rgba(26, 25, 22, 0.25);
}

.case-reel .reel-head {
  margin-bottom: 1rem;
}

.case-reel .reel-title {
  font-size: clamp(1.8rem, 4.6vw, 3.4rem);
  max-width: 20ch;
}

@media (max-width: 760px) {
  .reel-head {
    grid-template-columns: 1fr;
  }

  .reel-time {
    min-width: 0;
    font-size: 0.6rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .reel-grain,
  .reel.is-playing .reel-grain,
  .reel-kicker i {
    animation: none;
  }
}
