.neighbor-glass {
  position: absolute;
  inset: 0;
  display: block;
  overflow: hidden;
  clip-path: var(--window-clip);
  opacity: var(--neighbor-light, 0);
  transition: opacity 1s linear;
  pointer-events: none;
}

.neighbor-picture {
  position: absolute;
  height: 100%;
  aspect-ratio: .88;
  left: 50%;
  transform-origin: 0 50%;
  transform: scaleX(var(--neighbor-facing, 1)) translateX(var(--neighbor-crop, -50%));
  background-image: url('/scene-art/prague-neighbors.webp');
  background-size: 300% 200%;
  background-position: var(--neighbor-tile);
  background-repeat: no-repeat;
  /* The plate is painted at interior exposure. Lift the midtones to read
     through glass at street scale, keeping the darkest silhouettes intact. */
  filter: brightness(1.53) saturate(1.08) blur(.022cqw);
}
[data-npc-id]:nth-child(even) { --neighbor-facing: -1; }

.neighbor-picture::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at var(--neighbor-lamp),
    rgb(255 185 103 / 32%), rgb(224 144 69 / 15%) 36%, transparent 76%);
  mix-blend-mode: soft-light;
}

[data-plane="side"] .neighbor-glass { filter: brightness(.88) saturate(.9); }

[data-activity="cooking"] { --neighbor-tile: 0% 0%; --neighbor-crop: -59%; --neighbor-lamp: 74% 40%; }
[data-activity="plants"] { --neighbor-tile: 50% 0%; --neighbor-crop: -48%; --neighbor-lamp: 53% 24%; }
[data-activity="conversation"] { --neighbor-tile: 100% 0%; --neighbor-crop: -42%; --neighbor-lamp: 23% 60%; }
[data-activity="cat"] { --neighbor-tile: 0% 100%; --neighbor-crop: -29%; --neighbor-lamp: 10% 27%; }
[data-activity="reading"] { --neighbor-tile: 50% 100%; --neighbor-crop: -45%; --neighbor-lamp: 55% 40%; }
[data-activity="desk"] { --neighbor-tile: 100% 100%; --neighbor-crop: -51%; --neighbor-lamp: 72% 48%; }

/* Local gestures move only a detail inside the room. Their clocks are
   independent of the lights, and furniture and walls stay still. */
.neighbor-picture::after {
  content: '';
  position: absolute;
  inset: 0;
  background: inherit;
  clip-path: var(--neighbor-detail);
  transform-origin: var(--neighbor-pivot);
  animation: neighbor-gesture var(--gesture-period) ease-in-out infinite;
  animation-delay: var(--neighbor-delay);
}
[data-activity="cooking"] {
  /* Steam rising directly above the copper pot. */
  --neighbor-detail: ellipse(4% 12% at 73% 48%);
  --neighbor-pivot: 71% 64%; --neighbor-gesture: translate(-1%, -2%) scaleY(1.05); --gesture-period: 8s;
}
[data-activity="plants"] {
  --neighbor-detail: ellipse(13% 11% at 45% 45%);
  --neighbor-pivot: 47% 38%; --neighbor-gesture: rotate(-4deg); --gesture-period: 17s;
}
[data-activity="conversation"] {
  --neighbor-detail: ellipse(11% 13% at 27% 44%);
  --neighbor-pivot: 27% 54%; --neighbor-gesture: rotate(4deg); --gesture-period: 19s;
}
[data-activity="cat"] {
  --neighbor-detail: ellipse(13% 6% at 53% 66%);
  --neighbor-pivot: 54% 71%; --neighbor-gesture: scaleY(1.06); --gesture-period: 5.2s;
}
[data-activity="reading"] {
  --neighbor-detail: ellipse(7% 9% at 55% 57%);
  --neighbor-pivot: 54% 65%; --neighbor-gesture: rotate(3deg); --gesture-period: 22s;
}
[data-activity="desk"] {
  --neighbor-detail: ellipse(6% 4% at 54% 64%);
  --neighbor-pivot: 51% 64%; --neighbor-gesture: rotate(-4deg); --gesture-period: 12s;
}
@keyframes neighbor-gesture {
  0%, 33%, 82%, 100% { transform: none; }
  51%, 58% { transform: var(--neighbor-gesture); }
}
@media (prefers-reduced-motion: reduce) {
  .neighbor-picture::after { animation: none; }
  .neighbor-glass { transition: none; }
}
