/* ==========================================================================
   INFINITE CASTLE — Keyframes, fallback CSS 3D, dan mode reduce motion
   ========================================================================== */

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes shine {
  0% { transform: translateX(-120%); }
  35%, 100% { transform: translateX(120%); }
}

@keyframes eq {
  0%, 100% { transform: scaleY(0.3); }
  50% { transform: scaleY(1); }
}

@keyframes scrollLine {
  0% { transform: scaleY(0); opacity: 1; }
  60% { transform: scaleY(1); opacity: 1; }
  100% { transform: scaleY(1); opacity: 0; }
}

@keyframes grainShift {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-3%, 2%); }
  50% { transform: translate(2%, -3%); }
  75% { transform: translate(-1%, 3%); }
}
.grain { animation: grainShift 1.2s steps(4) infinite; }

/* Partikel cahaya penutup: naik perlahan lalu memudar */
@keyframes riseFade {
  0% { transform: translate3d(0, 0, 0) scale(0.6); opacity: 0; }
  15% { opacity: 0.9; }
  100% { transform: translate3d(var(--drift, 20px), -70vh, 0) scale(1.1); opacity: 0; }
}
.closing__lights i {
  position: absolute;
  bottom: -10px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c-lantern);
  box-shadow: 0 0 12px 4px rgba(255, 191, 105, 0.55);
  opacity: 0;
  animation: riseFade 11s linear infinite;
}
.closing__lights i:nth-child(1) { left: 6%; animation-delay: 0s; --drift: 30px; }
.closing__lights i:nth-child(2) { left: 14%; animation-delay: 3.4s; --drift: -20px; width: 4px; height: 4px; }
.closing__lights i:nth-child(3) { left: 23%; animation-delay: 6.1s; --drift: 40px; }
.closing__lights i:nth-child(4) { left: 31%; animation-delay: 1.8s; --drift: -35px; width: 3px; height: 3px; }
.closing__lights i:nth-child(5) { left: 42%; animation-delay: 8.2s; --drift: 25px; }
.closing__lights i:nth-child(6) { left: 50%; animation-delay: 4.6s; --drift: -15px; width: 4px; height: 4px; }
.closing__lights i:nth-child(7) { left: 58%; animation-delay: 2.5s; --drift: 30px; }
.closing__lights i:nth-child(8) { left: 66%; animation-delay: 7.3s; --drift: -40px; width: 3px; height: 3px; }
.closing__lights i:nth-child(9) { left: 74%; animation-delay: 0.9s; --drift: 20px; }
.closing__lights i:nth-child(10) { left: 82%; animation-delay: 5.5s; --drift: -25px; width: 4px; height: 4px; }
.closing__lights i:nth-child(11) { left: 90%; animation-delay: 9.4s; --drift: 15px; }
.closing__lights i:nth-child(12) { left: 96%; animation-delay: 3s; --drift: -30px; width: 3px; height: 3px; }

/* ==========================================================================
   Fallback tanpa WebGL — lorong CSS 3D ringan
   Kamera virtual di z=0 menatap -z; dinding = bidang yang diputar 90°.
   ========================================================================== */

.fallback-stage {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 45%, #3a1f2c 0%, #1a0f15 45%, var(--c-obsidian) 80%);
}
.no-webgl .fallback-stage { display: block; }

.fallback-corridor {
  position: absolute;
  inset: 0;
  perspective: 520px;
  perspective-origin: 50% 46%;
  transform-style: preserve-3d;
}
.fc-plane {
  position: absolute;
  left: 50%;
  top: 46%;
  backface-visibility: hidden;
}
.fc-wall {
  width: 1800px;
  height: 440px;
  margin: -220px 0 0 -900px;
  overflow: hidden;
}
/* Pola shoji digeser dengan transform (compositor saja, tanpa repaint) */
.fc-pattern {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -200px;
  right: -200px;
  background: repeating-linear-gradient(90deg,
    #2a1219 0 22px,
    rgba(255, 214, 160, 0.62) 22px 104px,
    #2a1219 104px 110px,
    rgba(255, 214, 160, 0.55) 110px 192px,
    #2a1219 192px 200px);
  animation: corridorFlow 7s linear infinite;
  will-change: transform;
}
/* Ujung jauh dinding digelapkan (lapisan statis) */
.fc-wall::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(17, 17, 22, 0) 0%, rgba(17, 17, 22, 0.95) 100%);
}
.fc-wall--left { transform: translate3d(-280px, 0, -900px) rotateY(90deg); }
/* Pada dinding kanan, ujung jauh ada di sisi kiri bidang → arah gradien & arus dibalik */
.fc-wall--right { transform: translate3d(280px, 0, -900px) rotateY(-90deg); }
.fc-wall--right::after { background: linear-gradient(270deg, rgba(17, 17, 22, 0) 0%, rgba(17, 17, 22, 0.95) 100%); }
.fc-wall--right .fc-pattern { animation-name: corridorFlowReverse; }
.fc-floor,
.fc-ceiling {
  width: 560px;
  height: 1800px;
  margin: -900px 0 0 -280px;
  background:
    linear-gradient(0deg, rgba(17, 17, 22, 0) 0%, rgba(17, 17, 22, 0.95) 100%),
    repeating-linear-gradient(90deg, #3d2023 0 68px, #2a1518 68px 70px);
}
.fc-floor { transform: translate3d(0, 220px, -900px) rotateX(90deg); }
.fc-ceiling {
  transform: translate3d(0, -220px, -900px) rotateX(-90deg);
  background:
    linear-gradient(180deg, rgba(17, 17, 22, 0.2) 0%, rgba(17, 17, 22, 0.95) 100%),
    repeating-linear-gradient(0deg, #1c1014 0 180px, #2d171d 180px 200px);
}
.fallback-glow {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 240px;
  height: 240px;
  margin: -120px 0 0 -120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 191, 105, 0.55), rgba(183, 124, 131, 0.15) 50%, transparent 70%);
  animation: glowPulse 5s ease-in-out infinite;
}
.fallback-lanterns span {
  position: absolute;
  top: 30%;
  width: 18px;
  height: 24px;
  border-radius: 45%;
  background: radial-gradient(circle at 50% 45%, #fff2d6, var(--c-lantern) 60%, #b5562e);
  box-shadow: 0 0 30px 10px rgba(255, 191, 105, 0.35);
  animation: lanternSway 6s ease-in-out infinite;
}
.fallback-lanterns span:nth-child(1) { left: 12%; top: 22%; transform: scale(1.6); }
.fallback-lanterns span:nth-child(2) { left: 84%; top: 24%; transform: scale(1.5); animation-delay: -2s; }
.fallback-lanterns span:nth-child(3) { left: 30%; top: 34%; transform: scale(0.9); animation-delay: -1s; }
.fallback-lanterns span:nth-child(4) { left: 68%; top: 35%; transform: scale(0.85); animation-delay: -3s; }
.fallback-lanterns span:nth-child(5) { left: 42%; top: 40%; transform: scale(0.5); animation-delay: -4s; }
.fallback-lanterns span:nth-child(6) { left: 57%; top: 40%; transform: scale(0.45); animation-delay: -5s; }

@keyframes corridorFlow { to { transform: translateX(-200px); } }
@keyframes corridorFlowReverse { to { transform: translateX(200px); } }
@keyframes glowPulse { 0%, 100% { opacity: 0.75; } 50% { opacity: 1; } }
@keyframes lanternSway { 0%, 100% { translate: 0 0; } 50% { translate: 0 6px; } }

/* Saat "masuk" di mode fallback: lorong maju cepat lalu memudar */
.fallback-entering .fallback-corridor { animation: fallbackEnter 2.6s cubic-bezier(0.55, 0, 0.3, 1) forwards; }
.fallback-entering .fc-pattern { animation-duration: 1.4s; }
/* Pindah ruangan di mode fallback: lorong berdenyut maju lalu kembali */
.fallback-traveling .fallback-corridor { animation: fallbackTravel 0.95s cubic-bezier(0.55, 0, 0.3, 1); }
@keyframes fallbackTravel {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.45; }
}
@keyframes fallbackEnter {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(2.4); opacity: 0.35; }
}

/* ==========================================================================
   Reduce motion (preferensi sistem diterapkan via class oleh JS,
   sehingga pengguna dapat menimpanya dengan tombol di UI)
   ========================================================================== */

.reduce-motion *,
.reduce-motion *::before,
.reduce-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  animation-delay: 0s !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}
.reduce-motion .closing__lights,
.reduce-motion .grain { display: none; }
.reduce-motion .loader__ring { animation: none; }
