/* ============================================================
   REWIND — the story of AI, backwards
   Palette is driven by --t (0 = NOW/sepia … 1 = BEGINNING/cold),
   set from JS on <html> as a scroll-progress variable.
   ============================================================ */

:root {
  --t: 0; /* time position 0..1, updated by JS */

  /* warm "now" end */
  --warm-bg-0: 26, 20, 15;
  --warm-bg-1: 40, 30, 20;
  --warm-ink: 232, 213, 176;
  --warm-accent: 200, 150, 62;

  /* cold "beginning" end */
  --cold-bg-0: 8, 12, 20;
  --cold-bg-1: 14, 22, 34;
  --cold-ink: 186, 200, 214;
  --cold-accent: 96, 150, 190;

  /* interpolated live values (computed in JS via color-mix fallback below) */
  --ink: rgb(232, 213, 176);
  --accent: rgb(200, 150, 62);
  --bg-0: rgb(26, 20, 15);
  --bg-1: rgb(40, 30, 20);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: auto; /* JS drives the cinematic rewind */
}

body {
  font-family: "Fraunces", Georgia, serif;
  color: var(--ink);
  background: #0c0a08;
  overflow-x: hidden;
}
/* native cursor is hidden ONLY once JS is live and paints the clock cursor;
   if the script never runs, the pointer stays visible (no dead-cursor trap) */
body.cursor-hidden,
body.cursor-hidden .was,
body.cursor-hidden .restart {
  cursor: none;
}

/* the moving background wash: warm at top, cold at the "beginning" */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background: radial-gradient(
    120% 90% at 50% 0%,
    var(--bg-1) 0%,
    var(--bg-0) 60%,
    #050607 100%
  );
  transition: background 200ms linear;
}
/* film grain / vignette */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(
    140% 120% at 50% 50%,
    transparent 55%,
    rgba(0, 0, 0, 0.55) 100%
  );
  mix-blend-mode: multiply;
}

/* ─────────────── HUD: the down-counting year ─────────────── */
.hud {
  position: fixed;
  top: clamp(14px, 3vw, 34px);
  right: clamp(14px, 3vw, 40px);
  z-index: 40;
  text-align: right;
  mix-blend-mode: difference;
  color: #fff;
  user-select: none;
}
.hud__year {
  font-family: "Space Mono", monospace;
  font-weight: 700;
  font-size: clamp(2.4rem, 7vw, 5rem);
  line-height: 0.9;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.hud__label {
  font-family: "Space Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.7;
  margin-top: 0.4rem;
}

/* progress rail down the left edge */
.rail {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  z-index: 40;
  background: rgba(255, 255, 255, 0.06);
}
.rail__fill {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 0%;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent);
}

/* ─────────────── the counter-clockwise clock cursor ─────────────── */
.clock {
  position: fixed;
  top: 0;
  left: 0;
  width: 46px;
  height: 46px;
  z-index: 60;
  pointer-events: none;
  transform: translate3d(-100px, -100px, 0);
  will-change: transform;
  mix-blend-mode: difference;
}
.clock__face {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
  border: 1.5px solid #fff;
  background: rgba(255, 255, 255, 0.04);
}
.clock__tick {
  position: absolute;
  top: 2px;
  left: 50%;
  width: 1.5px;
  height: 5px;
  background: #fff;
  transform-origin: 50% 21px;
  opacity: 0.8;
}
.clock__tick:nth-child(2) {
  transform: translateX(-50%) rotate(90deg);
}
.clock__tick:nth-child(3) {
  transform: translateX(-50%) rotate(180deg);
}
.clock__tick:nth-child(4) {
  transform: translateX(-50%) rotate(270deg);
}
.clock__hand {
  position: absolute;
  left: 50%;
  bottom: 50%;
  background: #fff;
  transform-origin: 50% 100%;
  border-radius: 2px;
}
.clock__hand--hour {
  width: 2px;
  height: 11px;
  margin-left: -1px;
}
.clock__hand--min {
  width: 1.5px;
  height: 16px;
  margin-left: -0.75px;
  opacity: 0.85;
}
.clock__pin {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #fff;
}
.clock--hidden {
  opacity: 0;
}

/* ─────────────── chapters ─────────────── */
.chapter {
  position: relative;
  min-height: 100vh;
  display: grid;
  align-items: center;
  padding: clamp(4rem, 10vh, 9rem) clamp(1.5rem, 8vw, 10rem);
  overflow: hidden;
}
.chapter__inner {
  position: relative;
  z-index: 3;
  max-width: 760px;
}
.chapter__inner--center {
  margin: 0 auto;
  text-align: center;
}

.eyebrow {
  font-family: "Space Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1.4rem;
}

h1 {
  font-size: clamp(2.6rem, 8vw, 6.4rem);
  font-weight: 300;
  line-height: 1.02;
  letter-spacing: -0.02em;
  margin-bottom: 1.6rem;
}
h2 {
  font-size: clamp(2rem, 5.4vw, 4rem);
  font-weight: 300;
  line-height: 1.06;
  letter-spacing: -0.015em;
  margin-bottom: 1.4rem;
}
.lede {
  font-size: clamp(1.1rem, 2vw, 1.5rem);
  line-height: 1.5;
  max-width: 44ch;
  opacity: 0.85;
}
.body {
  font-size: clamp(1rem, 1.6vw, 1.25rem);
  line-height: 1.6;
  max-width: 48ch;
  opacity: 0.82;
}
em {
  font-style: italic;
  color: #fff;
}
.scrolltip {
  margin-top: 2.6rem;
  font-family: "Space Mono", monospace;
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  opacity: 0.55;
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  50% {
    transform: translateY(6px);
    opacity: 0.7;
  }
}

/* ─────────────── background video ─────────────── */
.chapter__media {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
}
.chapter__media--inset {
  position: absolute;
  z-index: 1;
  inset: auto clamp(1.5rem, 6vw, 8rem) 50% auto;
  right: clamp(1.5rem, 6vw, 8rem);
  top: 50%;
  transform: translateY(-50%);
  width: min(42vw, 460px);
  height: min(42vw, 460px);
  border-radius: 6px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.chapter--media-right .chapter__inner {
  max-width: 46%;
}
.bgvid {
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* "de-developed" until revealed; JS/observer removes the veil */
  filter: saturate(0.6) contrast(1.05) sepia(calc(0.5 * (1 - var(--t))));
  opacity: 0.9;
}
.chapter__scrim {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: linear-gradient(
    90deg,
    rgba(5, 6, 8, 0.92) 0%,
    rgba(5, 6, 8, 0.7) 40%,
    rgba(5, 6, 8, 0.35) 100%
  );
}
.chapter__scrim--dark {
  background: radial-gradient(
    120% 120% at 50% 60%,
    rgba(2, 4, 8, 0.4) 0%,
    rgba(2, 4, 8, 0.92) 100%
  );
}

/* ─────────────── reveal / un-reveal ─────────────────
   .reveal starts hidden. .is-in => assembled (typed in).
   .is-out => the section you are LEAVING un-types / de-develops. */
.reveal {
  opacity: 0;
  transform: translateY(26px);
  filter: blur(6px);
  transition:
    opacity 0.7s cubic-bezier(0.2, 0.7, 0.2, 1),
    transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1),
    filter 0.7s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.reveal--slow {
  transition-duration: 1.5s;
}
.is-in .reveal {
  opacity: 1;
  transform: none;
  filter: blur(0);
}
/* leaving downward: play the entrance in reverse (un-develop) */
.is-out .reveal {
  opacity: 0;
  transform: translateY(-22px) scale(0.99);
  filter: blur(10px);
}
/* stagger children */
.is-in .reveal:nth-child(2) {
  transition-delay: 0.06s;
}
.is-in .reveal:nth-child(3) {
  transition-delay: 0.14s;
}
.is-in .reveal:nth-child(4) {
  transition-delay: 0.22s;
}

.chapter.is-in .bgvid {
  animation: develop 1.2s ease forwards;
}
@keyframes develop {
  from {
    filter: saturate(0) contrast(1.4) brightness(0.4) blur(8px);
    opacity: 0;
  }
  to {
    filter: saturate(0.6) contrast(1.05);
    opacity: 0.9;
  }
}

/* ─────────────── noun hover: "what it used to be" ─────────────── */
.was {
  position: relative;
  color: var(--accent);
  white-space: nowrap;
  transition: color 0.3s ease;
  border-radius: 3px;
}
.was:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.was::after {
  content: attr(data-was);
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  color: var(--ink);
  opacity: 0;
  transform: translateY(0.12em);
  filter: blur(4px);
  transition:
    opacity 0.45s ease,
    transform 0.45s ease,
    filter 0.45s ease;
  pointer-events: none;
}
.was:hover,
.was:focus-visible,
.was.show-was {
  color: transparent;
}
.was:hover::after,
.was:focus-visible::after,
.was.show-was::after {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}

/* ─────────────── the beginning ─────────────── */
.chapter--beginning {
  min-height: 110vh;
  background: #030507;
}
.chapter--beginning h2 {
  font-size: clamp(1.4rem, 3.4vw, 2.4rem);
  font-weight: 300;
  max-width: 22ch;
  margin-inline: auto;
  opacity: 0.94;
}
.restart {
  margin-top: 3rem;
  font-family: "Space Mono", monospace;
  font-size: 0.8rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: #060606;
  background: var(--cold-ink);
  border: 0;
  padding: 1rem 2.2rem;
  border-radius: 100px;
  cursor: pointer;
  transition:
    transform 0.3s ease,
    box-shadow 0.3s ease,
    background 0.3s ease;
  box-shadow: 0 0 0 rgba(120, 170, 210, 0);
}
.restart:hover,
.restart:focus-visible {
  transform: scale(1.06);
  background: #fff;
  box-shadow: 0 0 44px rgba(140, 190, 230, 0.55);
}
.restart:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 4px;
}

/* while the cinematic rewind is playing, dim interactions */
body.is-rewinding {
  pointer-events: none;
}
body.is-rewinding .hud__label::after {
  content: " · rewinding";
}

.chapter--media-full .chapter__inner {
  max-width: 620px;
}

/* ─────────────── responsive ─────────────── */
@media (max-width: 760px) {
  .chapter--media-right .chapter__inner {
    max-width: 100%;
  }
  .chapter__media--inset {
    position: absolute;
    inset: 0;
    width: auto;
    height: auto;
    transform: none;
    border-radius: 0;
    opacity: 0.5;
  }
  .chapter--media-right .chapter__media--inset + .chapter__inner {
    background: linear-gradient(rgba(5, 6, 8, 0.6), rgba(5, 6, 8, 0.6));
  }
  body {
    cursor: auto;
  }
  .clock {
    display: none;
  }
  .was {
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  .reveal,
  .reveal--slow {
    transition-duration: 0.001s;
  }
  .scrolltip {
    animation: none;
  }
  /* no "developing" film effect and no bobbing; videos stay on their poster
     frame (JS also skips autoplay), and the clock hands are frozen in JS */
  .chapter.is-in .bgvid {
    animation: none;
  }
}
