/* The lab, third run: motion with no clock in it.
   Everything else in the lab animates against time. This one animates against
   the reader's own scroll position, which means the reader drives it: there is
   no playhead, no cycle, and nowhere for it to be at the end. Wrapped in
   @supports so a browser without scroll-driven animations gets the finished
   arrangement instead of a frozen start frame. */

.hall {
  position: relative;
  height: 340vh;
  scroll-timeline-name: --hall;
  scroll-timeline-axis: block;
}

.hall-stage {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 45%, var(--panel) 0%, var(--surface) 70%);
  border: 1px solid var(--rule);
  border-radius: 3px;
}

/* Three doors in a corridor, each arriving as the last one leaves. They share
   one grid cell, so only the one the reader is between is at full size. */

.hall-doors {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.hall-door {
  position: absolute;
  width: min(74%, 300px);
  aspect-ratio: 3 / 4;
  border: 1px solid var(--link);
  background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--rule), 0 0 24px rgba(0,0,0,0.12);
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.hall-doors .hall-door:nth-of-type(2) { border-style: dashed; }
.hall-doors .hall-door:nth-of-type(3) { border-color: var(--gold); }

/* Words that arrive out of focus. Blur is a length, so it interpolates, and
   the scroll position decides how far along it is. */

.hall-words {
  position: relative;
  text-align: center;
  font-size: clamp(1.3rem, 5vw, 2rem);
  letter-spacing: 0.14em;
  color: var(--text-strong);
}

.hall-words span {
  display: block;
}

/* A dial the reader turns by scrolling. The wedges are a conic gradient; the
   rotation is the scroll position; the pointer is a rule. */

.hall-dial {
  position: absolute;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  border: 1px solid var(--link);
  background:
    repeating-conic-gradient(from 0deg, var(--rule) 0deg 0.5deg, transparent 0.5deg 10deg),
    radial-gradient(circle, var(--panel) 0 62%, transparent 63%);
}

.hall-dial::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 12%;
  width: 1px;
  height: 38%;
  background: var(--gold);
  transform-origin: 50% 100%;
}

/* A ledger line that fills as you read down the page. */

.hall-rule {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 7%;
  height: 2px;
  background: var(--rule);
}

.hall-rule::after {
  content: "";
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: 0 50%;
  background: var(--gold);
}

@supports (animation-timeline: scroll()) {
  .hall-door {
    animation: hall-near linear both;
    animation-timeline: --hall;
    animation-range: 0% 34%;
  }

  .hall-doors .hall-door:nth-of-type(2) { animation-range: 33% 67%; }
  .hall-doors .hall-door:nth-of-type(3) { animation-range: 66% 100%; }

  .hall-words span:nth-child(1) {
    animation: hall-focus linear both;
    animation-timeline: --hall;
    animation-range: 8% 34%;
  }

  .hall-words span:nth-child(2) {
    animation: hall-focus linear both;
    animation-timeline: --hall;
    animation-range: 40% 66%;
  }

  .hall-words span:nth-child(3) {
    animation: hall-focus linear both;
    animation-timeline: --hall;
    animation-range: 72% 98%;
  }

  .hall-dial::after {
    animation: hall-turn linear both;
    animation-timeline: --hall;
    animation-range: 0% 100%;
  }

  .hall-rule::after {
    animation: hall-fill linear both;
    animation-timeline: --hall;
    animation-range: 0% 100%;
  }
}

@keyframes hall-near {
  from { transform: scale(0.22) translateZ(0); opacity: 0; filter: blur(3px); }
  40%  { opacity: 1; }
  to   { transform: scale(1); opacity: 1; filter: blur(0); }
}

@keyframes hall-focus {
  from { opacity: 0; filter: blur(9px); transform: translateY(14px); }
  to   { opacity: 1; filter: blur(0); transform: translateY(0); }
}

@keyframes hall-turn {
  from { transform: rotate(-140deg); }
  to   { transform: rotate(220deg); }
}

@keyframes hall-fill {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

/* Without the feature there is nothing to hold still, but the dial should not
   sit at the un-turned angle for ever, so give it a resting pose. */

@supports not (animation-timeline: scroll()) {
  .hall-dial::after { transform: rotate(40deg); }
  .hall-rule::after { transform: scaleX(0.4); }
}

html:has(#lab-still:checked) .hall-door,
html:has(#lab-still:checked) .hall-words span,
html:has(#lab-still:checked) .hall-dial::after,
html:has(#lab-still:checked) .hall-rule::after {
  animation-play-state: paused !important;
}

@media (prefers-reduced-motion: reduce) {
  .hall-door, .hall-words span { animation: none !important; }
  .hall-words span { opacity: 1; filter: none; transform: none; }
  .hall-door { opacity: 1; filter: none; }
  .hall-doors .hall-door:nth-of-type(1) { transform: scale(0.6); }
  .hall-doors .hall-door:nth-of-type(3) { transform: scale(0.85); }
}