:root {
  --scene-size: min(82vw, 720px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  margin: 0;
}

body {
  background: #ffffff;
  color: #000000;
  font-family: Arial, Helvetica, sans-serif;
  overflow-x: hidden;
}

button,
a {
  font: inherit;
}

.scroll-space {
  height: 450vh;
}

.sticky-stage {
  position: sticky;
  top: 0;

  display: grid;
  place-items: center;

  width: 100%;
  height: 100vh;
  height: 100dvh;

  overflow: hidden;
  background: #ffffff;
}

.intro-text {
  position: absolute;
  z-index: 20;

  width: min(90vw, 620px);
  margin: 0;

  font-size: clamp(16px, 2vw, 24px);
  font-weight: 600;
  text-align: center;
  text-transform: lowercase;

  will-change: opacity, transform;
}

.scene {
  position: relative;
  z-index: 4;

  width: var(--scene-size);
  aspect-ratio: 1 / 1;

  overflow: hidden;
  opacity: 0;
  transform: scale(0.08);
  transform-origin: center;

  will-change: opacity, transform, filter;
}

.vent {
  position: absolute;
  inset: 0;
  z-index: 1;

  width: 100%;
  height: 100%;

  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.horse {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;

  width: 48%;
  height: auto;

  opacity: 0;
  transform: translate(-50%, -50%) scale(0);
  transform-origin: center center;

  pointer-events: none;
  user-select: none;

  will-change: opacity, transform, top, filter;
}

.navbar {
  position: fixed;
  top: 22px;
  left: 50%;
  z-index: 100;

  display: flex;
  align-items: center;
  gap: 22px;

  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(-12px);

  transition:
    opacity 180ms linear,
    transform 180ms linear;
}

.navbar.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.navbar a,
.navbar button {
  padding: 0;
  border: 0;
  background: transparent;
  color: #000000;

  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  text-transform: lowercase;

  cursor: pointer;
}

.navbar a:hover,
.navbar button:hover {
  text-decoration: underline;
  transform: skewX(-10deg);
}

.flying-horses {
  position: fixed;
  inset: 0;
  z-index: 6;

  overflow: hidden;
  pointer-events: none;
}

.flying-horse {
  position: absolute;

  width: var(--size);
  height: auto;

  opacity: 0;
  filter:
    contrast(1.35)
    saturate(1.2)
    drop-shadow(4px 4px 0 #000000);

  animation:
    fly-across var(--duration) linear infinite,
    horse-spin var(--spin-duration) linear infinite;

  animation-delay: var(--delay);
  will-change: transform, opacity;
}

@keyframes fly-across {
  0% {
    opacity: 0;
    translate: -25vw var(--start-y);
  }

  8% {
    opacity: var(--opacity);
  }

  50% {
    translate: 50vw var(--mid-y);
  }

  92% {
    opacity: var(--opacity);
  }

  100% {
    opacity: 0;
    translate: 125vw var(--end-y);
  }
}

@keyframes horse-spin {
  from {
    rotate: var(--start-rotation);
  }

  to {
    rotate: calc(var(--start-rotation) + 360deg);
  }
}

.noise,
.scanlines {
  position: fixed;
  inset: 0;
  z-index: 80;

  pointer-events: none;
}

.noise {
  opacity: 0;
  background-image:
    repeating-radial-gradient(
      circle at 10% 20%,
      rgba(0, 0, 0, 0.18) 0 1px,
      transparent 1px 3px
    );

  background-size: 7px 7px;
  mix-blend-mode: multiply;
}

body.active .noise {
  opacity: 0.06;
  animation: noise-jump 90ms steps(2) infinite;
}

.scanlines {
  opacity: 0;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0 3px,
      rgba(0, 0, 0, 0.055) 3px 4px
    );
}

body.active .scanlines {
  opacity: 1;
}

body.schizo .scene {
  animation: scene-jitter 110ms steps(2) infinite;
}

body.schizo .horse {
  filter:
    contrast(1.35)
    saturate(1.35)
}

@keyframes scene-jitter {
  0% {
    translate: 0 0;
  }

  25% {
    translate: -6px 4px;
  }

  50% {
    translate: 7px -5px;
  }

  75% {
    translate: -5px -7px;
  }

  100% {
    translate: 6px 5px;
  }
}

@keyframes noise-jump {
  from {
    transform: translate(0, 0);
  }

  to {
    transform: translate(3px, -3px);
  }
}

@media (max-width: 600px) {
  :root {
    --scene-size: min(96vw, 680px);
  }

  .scroll-space {
    height: 420vh;
  }

  .navbar {
    top: 18px;
    gap: 16px;
  }

  .navbar a,
  .navbar button {
    font-size: 12px;
  }

  .flying-horse {
    width: calc(var(--size) * 0.75);
  }
}

@media (prefers-reduced-motion: reduce) {
  .flying-horse,
  body.schizo .scene,
  body.active .noise {
    animation: none;
  }
}
