.viewport {
  position: absolute;
  inset: 0;
  perspective: 720px;
  perspective-origin: 50% 46%;
  overflow: hidden;
  background: var(--ink);
}

.viewport::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(ellipse 70% 55% at 50% 40%, transparent 35%, rgba(7, 9, 13, 0.55) 100%),
    linear-gradient(to bottom, rgba(7, 9, 13, 0.35), transparent 18%, transparent 72%, rgba(7, 9, 13, 0.7));
}

.viewport::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0.08;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

.scene {
  position: absolute;
  inset: -10%;
  transform-style: preserve-3d;
  will-change: transform;
  transform-origin: 50% 50%;
}

.room {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 160vmax;
  height: 100vmax;
  transform: translate(-50%, -50%) translateZ(-520px);
  transform-style: preserve-3d;
}

.face {
  position: absolute;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

.face-back {
  inset: 0;
  background:
    radial-gradient(ellipse 40% 30% at 50% 42%, rgba(157, 255, 87, 0.09), transparent 70%),
    linear-gradient(180deg, #151b26 0%, #0a0e14 50%, #06080c 100%);
  border: 1px solid var(--line);
  box-shadow: inset 0 0 160px rgba(0, 0, 0, 0.75);
  overflow: hidden;
}

.face-back::before {
  content: "";
  position: absolute;
  inset: 18% 22%;
  border: 1px solid var(--line-strong);
  background:
    linear-gradient(90deg, transparent 0 49%, rgba(157, 255, 87, 0.35) 49.5% 50.5%, transparent 51%),
    linear-gradient(0deg, transparent 0 49%, rgba(242, 240, 234, 0.08) 49.5% 50.5%, transparent 51%),
    rgba(255, 255, 255, 0.025);
  box-shadow:
    0 0 60px rgba(157, 255, 87, 0.1),
    inset 0 0 40px rgba(0, 0, 0, 0.35);
}

.face-back::after {
  content: "STUDIO // VIEWPORT";
  position: absolute;
  left: 24%;
  top: 21%;
  font-family: var(--font-mono);
  font-size: clamp(0.55rem, 1.1vmin, 0.8rem);
  letter-spacing: 0.18em;
  color: rgba(157, 255, 87, 0.55);
}

.face-left,
.face-right {
  top: 0;
  width: 85vmax;
  height: 100%;
  background:
    linear-gradient(90deg, rgba(14, 18, 24, 0.05), rgba(8, 11, 16, 0.98)),
    repeating-linear-gradient(
      to bottom,
      transparent 0 56px,
      rgba(157, 255, 87, 0.07) 56px 57px
    ),
    repeating-linear-gradient(
      to right,
      transparent 0 90px,
      rgba(242, 240, 234, 0.04) 90px 91px
    ),
    #0c1016;
}

.face-left {
  left: 0;
  transform-origin: left center;
  transform: rotateY(84deg);
  border-right: 1px solid var(--line-strong);
}

.face-right {
  right: 0;
  transform-origin: right center;
  transform: rotateY(-84deg);
  border-left: 1px solid var(--line-strong);
  background:
    linear-gradient(270deg, rgba(14, 18, 24, 0.05), rgba(8, 11, 16, 0.98)),
    repeating-linear-gradient(
      to bottom,
      transparent 0 56px,
      rgba(157, 255, 87, 0.07) 56px 57px
    ),
    repeating-linear-gradient(
      to left,
      transparent 0 90px,
      rgba(242, 240, 234, 0.04) 90px 91px
    ),
    #0c1016;
}

.face-floor {
  left: 0;
  right: 0;
  bottom: 0;
  height: 90vmax;
  transform-origin: center bottom;
  transform: rotateX(86deg);
  background:
    linear-gradient(180deg, rgba(157, 255, 87, 0.05), transparent 18%, rgba(7, 9, 13, 0.9) 90%),
    repeating-linear-gradient(
      90deg,
      transparent 0 72px,
      rgba(242, 240, 234, 0.08) 72px 73px
    ),
    repeating-linear-gradient(
      0deg,
      transparent 0 72px,
      rgba(242, 240, 234, 0.08) 72px 73px
    ),
    linear-gradient(180deg, #121820, #07090d);
  border-top: 1px solid var(--line-strong);
}

.face-ceiling {
  left: 0;
  right: 0;
  top: 0;
  height: 70vmax;
  transform-origin: center top;
  transform: rotateX(-84deg);
  background:
    linear-gradient(0deg, transparent, rgba(7, 9, 13, 0.92)),
    repeating-linear-gradient(
      90deg,
      transparent 0 100px,
      rgba(157, 255, 87, 0.12) 100px 101px
    ),
    #0b0f15;
  border-bottom: 1px solid var(--line);
}

.rail {
  position: absolute;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--signal), transparent);
  opacity: 0.55;
  box-shadow: 0 0 18px var(--glow);
  animation: rail-pulse 4.5s ease-in-out infinite;
}

.rail-1 {
  top: 28%;
  left: 8%;
  right: 8%;
}

.rail-2 {
  top: 62%;
  left: 15%;
  right: 15%;
  animation-delay: 1.2s;
  opacity: 0.35;
}

.panel {
  position: absolute;
  border: 1px solid var(--line-strong);
  background: rgba(14, 18, 24, 0.55);
  backdrop-filter: blur(2px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(157, 255, 87, 0.08), transparent 40%),
    repeating-linear-gradient(
      0deg,
      transparent 0 10px,
      rgba(242, 240, 234, 0.03) 10px 11px
    );
}

.panel-a {
  width: 18vmax;
  height: 12vmax;
  left: 18%;
  top: 34%;
  transform: translateZ(90px) rotateY(8deg);
  animation: float-a 7s ease-in-out infinite;
}

.panel-b {
  width: 14vmax;
  height: 18vmax;
  right: 16%;
  top: 26%;
  transform: translateZ(140px) rotateY(-12deg);
  animation: float-b 8.5s ease-in-out infinite;
}

.panel-c {
  width: 22vmax;
  height: 9vmax;
  left: 36%;
  bottom: 28%;
  transform: translateZ(60px) rotateX(6deg);
  animation: float-c 6.5s ease-in-out infinite;
}

.panel-label {
  position: absolute;
  left: 0.7rem;
  top: 0.55rem;
  z-index: 1;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(242, 240, 234, 0.45);
}

.cursor-ghost {
  position: absolute;
  width: 0.7rem;
  height: 0.7rem;
  border: 1px solid var(--signal);
  border-radius: 50%;
  box-shadow: 0 0 12px var(--glow);
  animation: blink 1.6s steps(1) infinite;
}

.panel-a .cursor-ghost {
  left: 35%;
  top: 48%;
}

.panel-b .cursor-ghost {
  left: 55%;
  top: 30%;
  animation-delay: 0.4s;
}

.ambient {
  position: absolute;
  width: 40vmax;
  height: 40vmax;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%) translateZ(20px);
  background: radial-gradient(circle, rgba(157, 255, 87, 0.12), transparent 62%);
  filter: blur(8px);
  pointer-events: none;
  animation: ambient-breathe 5.5s ease-in-out infinite;
}

@keyframes rail-pulse {
  0%,
  100% {
    opacity: 0.25;
  }
  50% {
    opacity: 0.7;
  }
}

@keyframes float-a {
  0%,
  100% {
    transform: translateZ(90px) rotateY(8deg) translateY(0);
  }
  50% {
    transform: translateZ(90px) rotateY(8deg) translateY(-10px);
  }
}

@keyframes float-b {
  0%,
  100% {
    transform: translateZ(140px) rotateY(-12deg) translateY(0);
  }
  50% {
    transform: translateZ(140px) rotateY(-12deg) translateY(12px);
  }
}

@keyframes float-c {
  0%,
  100% {
    transform: translateZ(60px) rotateX(6deg) translateY(0);
  }
  50% {
    transform: translateZ(60px) rotateX(6deg) translateY(-8px);
  }
}

@keyframes ambient-breathe {
  0%,
  100% {
    opacity: 0.55;
    transform: translate(-50%, -50%) translateZ(20px) scale(1);
  }
  50% {
    opacity: 0.9;
    transform: translate(-50%, -50%) translateZ(20px) scale(1.08);
  }
}

@keyframes blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0.15;
  }
}

@media (max-width: 640px) {
  .room {
    width: 180vmax;
    height: 120vmax;
    transform: translate(-50%, -50%) translateZ(-320px);
  }

  .panel-a,
  .panel-b,
  .panel-c {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rail,
  .panel,
  .ambient,
  .cursor-ghost {
    animation: none !important;
  }

  .scene {
    transition: none;
  }
}
