/* Registered so per-clip tuning values can fade smoothly between videos. */
@property --shake { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --grime { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --blotches { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --grain { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --stripes { syntax: "<number>"; inherits: true; initial-value: 1; }
@property --cuts { syntax: "<number>"; inherits: true; initial-value: 1; }

:root {
  --logo-size: clamp(73px, 20.8vh, 169px);
  --transition-duration: 1200ms;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #050505;
}

.stage {
  /* Per-clip values are written by script.js; these are the defaults. */
  --shake: 1;
  --cuts: 1;
  --grime: 1;
  --blotches: 1;
  --grain: 1;
  --stripes: 1;
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #050505;
  isolation: isolate;
  transition:
    --shake 1.2s ease,
    --cuts 1.2s ease,
    --grime 1.2s ease,
    --blotches 1.2s ease,
    --grain 1.2s ease,
    --stripes 1.2s ease;
}

/* Slow push-in and drift, sitting above the per-clip crossfade transform. */
.camera {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
  animation: cameraPush 17s ease-in-out infinite alternate;
  will-change: transform;
}

/* Small, irregular handheld jitter on top of the slow camera move. */
.video-stack {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #050505;
  animation: cameraJitter 1.6s steps(1, end) infinite;
  will-change: transform;
}

/*
 * --bright is set per video from its measured luminance (see script.js),
 * so bright clips and dark clips land at a similar, deliberately dim level.
 */
.bg-video {
  --bright: 0.7;
  --con: 1.3;
  --sat: 0.62;
  --gray: 0.18;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #050505;
  opacity: 0;
  transform: scale(1.05);
  filter: brightness(var(--bright)) contrast(var(--con)) saturate(var(--sat)) grayscale(var(--gray));
  transition:
    opacity var(--transition-duration) ease-in-out,
    transform var(--transition-duration) ease-in-out,
    filter 400ms linear;
  will-change: opacity, transform, filter;
}

.bg-video.is-active {
  opacity: 1;
  transform: scale(1.015);
}

.bg-video.is-leaving {
  opacity: 0;
  transform: scale(1.075);
}

/* A synced copy of the active clip, briefly revealed as a displaced tear. */
.slice-video {
  --bright: 0.8;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #050505;
  opacity: 0;
  z-index: 1;
  clip-path: inset(var(--rip-top, 30%) 0 var(--rip-bottom, 60%) 0);
  filter: brightness(calc(var(--bright) * 1.55)) contrast(1.9) saturate(0.25) grayscale(0.4);
  transform: scale(1.015) translateX(0);
  pointer-events: none;
}

.slice-video.is-ripping {
  animation: ripBand 560ms steps(1, end) 1;
}

.grade {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(16, 13, 11, 0.3), rgba(6, 6, 9, 0.34));
  mix-blend-mode: multiply;
  animation: flicker 7s steps(1, end) infinite;
}

/* Fine, sparse, fast-moving grain drawn in script.js (no blocky pixels). */
.grain {
  position: absolute;
  top: -4%;
  left: -4%;
  width: 108%;
  height: 108%;
  z-index: 2;
  pointer-events: none;
  opacity: calc(0.85 * var(--grain));
  mix-blend-mode: overlay;
}

/* Dust, hair and dirt dragged sideways with the motion of the footage. */
.grime {
  position: absolute;
  inset: -12%;
  z-index: 3;
  pointer-events: none;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300' viewBox='0 0 300 300'%3E%3Cfilter id='d'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.42' numOctaves='1' seed='11' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 7 -4 0 0 -2.6'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23d)'/%3E%3C/svg%3E"),
    repeating-linear-gradient(90deg, transparent 0 173px, rgba(255, 255, 255, 0.18) 174px, transparent 176px),
    repeating-linear-gradient(90deg, transparent 0 397px, rgba(255, 255, 255, 0.12) 398px, transparent 401px);
  background-size: 300px 300px, 100% 100%, 100% 100%;
  mix-blend-mode: screen;
  opacity: calc(0.42 * var(--grime));
  animation: grimeRush 1.9s steps(7, end) infinite;
}

/* Organic dirt and smoke-like blotches that crawl across the frame. */
.blotches {
  position: absolute;
  inset: -25%;
  z-index: 3;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='420' height='420' viewBox='0 0 420 420'%3E%3Cfilter id='b'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.018' numOctaves='2' seed='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3.2 0 0 0 -1.5'/%3E%3C/filter%3E%3Crect width='420' height='420' filter='url(%23b)'/%3E%3C/svg%3E");
  background-size: 420px 420px;
  mix-blend-mode: multiply;
  opacity: calc(0.38 * var(--blotches));
  animation: blotchCrawl 11s steps(6, end) infinite;
}

/* Fast horizontal streaks and banding that sell speed. */
.stripes {
  position: absolute;
  inset: -14%;
  z-index: 4;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.07) 0px,
      rgba(255, 255, 255, 0.07) 1px,
      transparent 1px,
      transparent 7px
    ),
    repeating-linear-gradient(
      100deg,
      rgba(0, 0, 0, 0.32) 0px,
      rgba(0, 0, 0, 0.32) 4px,
      transparent 4px,
      transparent 26px
    ),
    repeating-linear-gradient(
      90deg,
      transparent 0 61px,
      rgba(255, 255, 255, 0.09) 62px,
      transparent 65px
    );
  mix-blend-mode: overlay;
  opacity: calc(0.9 * var(--stripes));
  animation: stripePan 1.1s linear infinite, stripeJerk 3.2s steps(1, end) infinite;
}

.stripes::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    100deg,
    transparent 0 71px,
    rgba(255, 255, 255, 0.08) 72px,
    rgba(0, 0, 0, 0.16) 75px,
    transparent 77px
  );
  animation: stripeSlide 620ms steps(4, end) infinite;
}

/* Occasional torn slices that jump sideways like damaged film. */
.tears {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  opacity: clamp(0, calc(var(--cuts) * 0.7), 1);
}

.tear {
  position: absolute;
  left: -12%;
  width: 124%;
  display: block;
  opacity: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.55) 12%,
    rgba(0, 0, 0, 0.7) 42%,
    rgba(255, 255, 255, 0.35) 68%,
    transparent 100%
  );
  mix-blend-mode: screen;
  animation: tearFlash 7.5s steps(1, end) infinite;
}

.tear-a {
  top: 19%;
  height: 5px;
  animation-delay: 0s;
}

.tear-b {
  top: 58%;
  height: 2px;
  animation-delay: 2.6s;
  animation-duration: 5.9s;
}

.tear-c {
  top: 76%;
  height: 9px;
  animation-delay: 4.9s;
  animation-duration: 9.3s;
}

.vignette {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 48%, transparent 34%, rgba(0, 0, 0, 0.14) 62%, rgba(0, 0, 0, 0.62) 100%),
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.13) 0px,
      rgba(0, 0, 0, 0.13) 1px,
      transparent 1px,
      transparent 4px
    );
  mix-blend-mode: multiply;
}

.logo-link {
  position: absolute;
  right: clamp(12px, 2vw, 28px);
  bottom: clamp(12px, 2vw, 28px);
  width: var(--logo-size);
  z-index: 7;
  display: block;
  line-height: 0;
  cursor: pointer;
  opacity: 0.9;
  transition: opacity 200ms ease;
}

.logo-link:hover,
.logo-link:focus-visible {
  opacity: 1;
}

.logo {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 3px 14px rgba(0, 0, 0, 0.9));
  user-select: none;
  -webkit-user-drag: none;
}

@keyframes cameraPush {
  0% { transform: scale(1.05) translate3d(0, 0, 0); }
  28% { transform: scale(1.115) translate3d(-0.5%, 0.35%, 0); }
  54% { transform: scale(1.08) translate3d(0.45%, -0.3%, 0); }
  78% { transform: scale(1.14) translate3d(-0.25%, 0.5%, 0); }
  100% { transform: scale(1.1) translate3d(0, 0, 0); }
}

@keyframes cameraJitter {
  0%, 100% { transform: translate3d(0, 0, 0); }
  10% { transform: translate3d(calc(0.22% * var(--shake)), calc(-0.14% * var(--shake)), 0); }
  20% { transform: translate3d(calc(-0.18% * var(--shake)), calc(0.2% * var(--shake)), 0); }
  30% { transform: translate3d(calc(0.12% * var(--shake)), calc(0.1% * var(--shake)), 0); }
  40% { transform: translate3d(calc(-0.25% * var(--shake)), calc(-0.18% * var(--shake)), 0); }
  50% { transform: translate3d(calc(0.16% * var(--shake)), calc(0.22% * var(--shake)), 0); }
  60% { transform: translate3d(calc(-0.1% * var(--shake)), calc(-0.1% * var(--shake)), 0); }
  70% { transform: translate3d(calc(0.24% * var(--shake)), calc(0.12% * var(--shake)), 0); }
  80% { transform: translate3d(calc(-0.2% * var(--shake)), calc(0.16% * var(--shake)), 0); }
  90% { transform: translate3d(calc(0.1% * var(--shake)), calc(-0.2% * var(--shake)), 0); }
}

@keyframes grimeRush {
  0% { transform: translate3d(0, 0, 0); background-position: 0 0, 0 0, 0 0; }
  100% { transform: translate3d(-3%, 0.6%, 0); background-position: -240px 0, -60px 0, -120px 0; }
}

@keyframes stripePan {
  0% { background-position: 0 0, 0 0, 0 0; }
  100% { background-position: 0 90px, -120px 0, 180px 0; }
}

@keyframes stripeJerk {
  0%, 76%, 100% { transform: translate3d(0, 0, 0); opacity: 0.75; }
  78% { transform: translate3d(-1.4%, 0, 0); opacity: 0.95; }
  80% { transform: translate3d(1.1%, 0, 0); opacity: 0.6; }
  82% { transform: translate3d(0, 0, 0); opacity: 0.75; }
}

@keyframes tearFlash {
  0%, 70%, 100% { opacity: 0; transform: translate3d(0, 0, 0) scaleY(1); }
  71% { opacity: 0.75; transform: translate3d(-3.5%, 0, 0) scaleY(2); }
  73% { opacity: 0.3; transform: translate3d(4%, 0, 0) scaleY(0.7); }
  75% { opacity: 0.6; transform: translate3d(-2%, 0, 0) scaleY(1.5); }
  77% { opacity: 0.2; transform: translate3d(2.5%, 0, 0) scaleY(0.9); }
  79% { opacity: 0; transform: translate3d(0, 0, 0) scaleY(1); }
}

@keyframes ripBand {
  0% { opacity: 0; transform: scale(1.015) translateX(0); }
  12% { opacity: 0.9; transform: scale(1.015) translateX(-3.5%); }
  30% { opacity: 0.75; transform: scale(1.015) translateX(2.8%); }
  48% { opacity: 0.85; transform: scale(1.015) translateX(-1.8%); }
  66% { opacity: 0.5; transform: scale(1.015) translateX(3.2%); }
  82%, 100% { opacity: 0; transform: scale(1.015) translateX(0); }
}

@keyframes stripeSlide {
  0% { transform: translate3d(0, 0, 0); }
  100% { transform: translate3d(-9%, 0, 0); }
}

@keyframes blotchCrawl {
  0% { transform: translate3d(0, 0, 0) scale(1); background-position: 0 0; }
  50% { transform: translate3d(-4%, 2%, 0) scale(1.12); background-position: -120px 60px; }
  100% { transform: translate3d(3%, -2%, 0) scale(1.05); background-position: 90px -70px; }
}

@keyframes flicker {
  0%, 92%, 100% { opacity: 1; }
  93% { opacity: 0.9; }
  94% { opacity: 1; }
  96% { opacity: 0.94; }
}

@media (prefers-reduced-motion: reduce) {
  .camera,
  .video-stack,
  .grade,
  .grime,
  .blotches,
  .stripes,
  .stripes::after,
  .tear,
  .slice-video {
    animation: none;
  }
  .bg-video {
    transition: opacity 300ms ease;
  }
}
