/* Troy landing: scene motion. Day to night, problem lines, Troy in the hero and footer, chips, stars.
   Only opacity and transform are animated. */

/* ---------- Day to night ---------- */

#sky img { will-change: opacity; }

/* Reduced motion: the paintings swap with a simple fade instead of following the scroll. */
@media (prefers-reduced-motion: reduce) {
  #sky img { transition: opacity 0.8s linear; }
}

/* Stars over the night painting. The layer's opacity follows the night painting's opacity (set by scene.js). */
#sky-stars {
  position: absolute;
  inset: 0;
  opacity: 0;
  will-change: opacity;
}
#sky-stars i {
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: var(--white);
  animation: star-twinkle 3.6s ease-in-out infinite alternate;
}
@keyframes star-twinkle {
  from { opacity: 0.15; }
  to { opacity: 1; }
}

/* ---------- Problem section: the line Troy completes ---------- */

/* scene.js sets --line-p (0 to 1) from the scroll position, so the line draws and un-draws with the scroll. */
.pair-line-fill {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 2px;
  border-radius: 2px;
  background: var(--gold);
  transform: scaleX(var(--line-p, 0));
  transform-origin: 0 50%;
}
.pair-line::before,
.pair-line::after { transition: opacity 0.2s linear; }
.pair-line.is-connected::before,
.pair-line.is-connected::after { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .pair-line-fill {
    transform: none;
    opacity: 0;
    transition: opacity 0.3s linear;
  }
  .pair-line.is-connected .pair-line-fill { opacity: 1; }
}

/* ---------- Connection chips ---------- */

@media (prefers-reduced-motion: no-preference) {
  .chip { transition: opacity 0.5s linear; }
}

/* ---------- Troy: eyes ---------- */

.troy-eye {
  transform-box: fill-box;
  transform-origin: 50% 50%;
}

/* ---------- Troy, the traveling mascot (built and moved by scene.js) ---------- */

#troy-traveler {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  z-index: 3;
  pointer-events: none;
  will-change: transform;
}
/* The root is a point at the bottom center of his box, so only the scaled mascot takes up room. */
#troy-traveler .troy-pose {
  position: absolute;
  left: -70px;
  top: -140px;
  width: 140px;
  height: 140px;
  transform-origin: 50% 94%;
  will-change: transform;
}
#troy-traveler svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
#troy-traveler .troy-helmet { transform-origin: 160px 200px; }

/* With motion allowed, the two still mascots are only anchors for the traveling one. */
@media (prefers-reduced-motion: no-preference) {
  html:not(.troy-static) #troy-hero svg,
  html:not(.troy-static) #troy-sleep svg { opacity: 0; }
}

/* Mouse depth: the painting is a touch oversized so its edges never show when it shifts. */
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  #sky { will-change: transform; }
}

/* ---------- Troy in the footer: asleep on the chat bubble ---------- */

/* The pose: the whole mascot leans to one side, the helmet slips a little further, the eyes are closed. */
#troy-sleep svg {
  transform: rotate(-12deg);
  transform-origin: 50% 94%;
}
#troy-sleep .troy-helmet {
  transform: rotate(-3deg) translateY(4px);
  transform-origin: 160px 200px;
}
#troy-sleep .troy-eye { transform: scaleY(0.14); }

/* The floating z's (added by scene.js when motion is allowed) */
.sleep-z {
  position: absolute;
  left: 142px;
  top: 6px;
  font-family: var(--font-sans);
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
  color: var(--white);
  opacity: 0;
}
/* They only rise once he is actually asleep. */
#footer.is-asleep .sleep-z { animation: sleep-z 4.5s linear infinite; }
#footer.is-asleep .sleep-z:nth-of-type(2) { animation-delay: 1.5s; }
#footer.is-asleep .sleep-z:nth-of-type(3) { animation-delay: 3s; }
@keyframes sleep-z {
  0%   { transform: translate(0, 0) scale(0.6); opacity: 0; }
  20%  { opacity: 0.9; }
  70%  { opacity: 0.6; }
  100% { transform: translate(26px, -64px) scale(1.15); opacity: 0; }
}
