.dream-loop {
  padding: 0;
  background: #071b17;
  scroll-margin-top: 62px;
}

.loop-stage {
  position: relative;
  width: 100%;
  height: max(700px, calc(100svh - 62px));
  min-height: 0;
  margin: 0;
  overflow: hidden;
  border: 0;
  isolation: isolate;
  background: #203f31;
  transform: none;
  filter: none;
}

.loop-stage::before { display: none; }
.loop-stage.is-distorted { animation: none; filter: none; }
.loop-stage.is-broken { transform: none; filter: none; }

.loop-world,
.loop-shade,
.loop-rewind,
.dream-cracks { position: absolute; inset: 0; pointer-events: none; }

.loop-world {
  z-index: 0;
  inset: -2%;
  background: url("../assets/images/sumeru-festival-bazaar.png") center center / cover no-repeat;
  transform: scale(1.035) translate(var(--loop-look-x, 0px), var(--loop-look-y, 0px));
  transition: transform 1.1s ease, filter 1.2s ease;
  will-change: transform;
}

.loop-stage[data-loop="1"] .loop-world { filter: saturate(.93) brightness(.96); }
.loop-stage[data-loop="2"] .loop-world { filter: saturate(.8) brightness(.89); }
.loop-stage[data-loop="3"] .loop-world { filter: saturate(.66) brightness(.83); }
.loop-stage.is-broken .loop-world { filter: saturate(1.08) brightness(1.04); transform: scale(1.08); }

.loop-shade {
  z-index: 1;
  background: linear-gradient(180deg, rgba(2, 23, 18, .55), transparent 28%, transparent 43%, rgba(2, 20, 17, .45) 64%, rgba(2, 16, 13, .96) 100%),
    linear-gradient(90deg, rgba(2, 21, 15, .27), transparent 43%, rgba(2, 17, 13, .12));
  transition: background 1s ease;
}

.loop-stage.is-broken .loop-shade {
  background: radial-gradient(circle at 50% 42%, rgba(238, 255, 191, .22), transparent 38%),
    linear-gradient(180deg, rgba(2, 28, 20, .45), transparent 28%, transparent 46%, rgba(2, 22, 16, .42) 67%, rgba(2, 18, 14, .96) 100%);
}

.loop-topline {
  position: absolute;
  z-index: 5;
  top: 106px;
  left: 5.5%;
  right: 5.5%;
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 24px;
  color: #fff8e6;
  font-size: 13px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .75);
}

.loop-topline > span { display: inline-flex; align-items: center; gap: 13px; }
.loop-topline > span i { display: block; width: 18px; height: 1px; background: #efddab; }
.loop-counter { position: static; display: flex; align-items: baseline; gap: 8px; text-align: right; }
.loop-counter span { display: inline; color: rgba(255, 248, 230, .75); font-size: 11px; }
.loop-counter strong { display: inline; color: #f8e3a4; font: 42px Georgia, serif; line-height: 1; }

.loop-point {
  position: absolute;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 76px;
  min-height: 78px;
  padding: 7px;
  transform: translate(-50%, -50%);
  border: 0;
  color: #fff8e3;
  background: transparent;
  text-shadow: 0 2px 7px rgba(0, 0, 0, .8);
  transition: opacity .35s ease;
}

.loop-point-glow {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 245, 210, .8);
  border-radius: 50%;
  background: rgba(6, 43, 33, .78);
  box-shadow: 0 0 0 5px rgba(3, 42, 33, .24), 0 3px 18px rgba(0, 0, 0, .45);
  font: 22px Georgia, serif;
  transition: transform .25s ease, background .25s ease, box-shadow .25s ease;
}

.loop-point-label { font-size: 12px; font-weight: 700; }
.loop-point:hover .loop-point-glow,
.loop-point:focus-visible .loop-point-glow { transform: scale(1.13); background: #125844; box-shadow: 0 0 0 7px rgba(204, 252, 167, .22), 0 0 30px #bbed83; }
.loop-point:focus-visible { outline: 2px solid #eaffbd; outline-offset: 4px; }
.loop-point.is-current .loop-point-glow { border-color: #ddffac; box-shadow: 0 0 0 8px rgba(186, 246, 138, .18), 0 0 28px rgba(180, 255, 143, .75); animation: loopPointPulse 2.4s ease-in-out infinite; }
.loop-point.is-found .loop-point-glow { color: #072c21; background: #d9ffa8; border-color: #f5ffd9; }
.loop-stage.is-broken .loop-point { opacity: .24; pointer-events: none; }
.loop-point-flower { left: 18%; top: 53%; }
.loop-point-stage { left: 51%; top: 48%; }
.loop-point-lantern { left: 83%; top: 42%; }

.loop-scene-change { position: absolute; z-index: 3; opacity: 0; pointer-events: none; color: #d7ff9d; text-shadow: 0 0 14px #74e78d, 0 0 36px #74e78d; transition: opacity .8s ease, transform .8s ease; }
.loop-scene-flower { top: 58%; left: 12%; transform: translateY(20px) rotate(-15deg); font: 40px Georgia, serif; }
.loop-scene-flower span { display: inline-block; font-size: 23px; transform: translateY(-22px); }
.loop-scene-stage { top: 55%; left: 49%; transform: scale(.3); font: 100px Georgia, serif; }
.loop-scene-lantern { top: 27%; left: 82%; transform: translateY(20px); font: 72px Georgia, serif; }
.loop-stage[data-loop="1"] .loop-scene-flower,
.loop-stage[data-loop="2"] .loop-scene-flower,
.loop-stage[data-loop="3"] .loop-scene-flower,
.loop-stage[data-loop="2"] .loop-scene-stage,
.loop-stage[data-loop="3"] .loop-scene-stage,
.loop-stage[data-loop="3"] .loop-scene-lantern { opacity: .86; transform: none; }
.loop-stage.is-broken .loop-scene-change { opacity: 0; }

.loop-falling-petals { position: absolute; z-index: 2; inset: 0; overflow: hidden; pointer-events: none; }
.loop-falling-petals i { position: absolute; top: -30px; width: 9px; height: 15px; border-radius: 100% 0 100% 0; background: #f9dfc6; box-shadow: 0 0 14px rgba(255, 236, 199, .5); animation: festivalPetal 12s linear infinite; }
.loop-falling-petals i:nth-child(1) { left: 16%; animation-delay: -2s; }
.loop-falling-petals i:nth-child(2) { left: 36%; animation-delay: -9s; animation-duration: 15s; }
.loop-falling-petals i:nth-child(3) { left: 54%; animation-delay: -5s; animation-duration: 11s; }
.loop-falling-petals i:nth-child(4) { left: 73%; animation-delay: -12s; animation-duration: 16s; }
.loop-falling-petals i:nth-child(5) { left: 86%; animation-delay: -6s; animation-duration: 13s; }
.loop-falling-petals i:nth-child(6) { left: 43%; animation-delay: -1s; animation-duration: 18s; }
.loop-stage.is-broken .loop-falling-petals i { animation-play-state: paused; }

.loop-copy { position: absolute; z-index: 5; left: 5.5%; bottom: 140px; width: min(650px, 58%); }
.loop-copy > p { margin: 0 0 8px; color: #eed992; font-size: 12px; font-weight: 700; letter-spacing: 0; }
.loop-copy :is(h1, h2) { margin: 0 0 7px; font-family: var(--display); font-size: 44px; font-weight: 400; line-height: 1.2; text-wrap: balance; }
.loop-copy > span { display: block; color: rgba(255, 250, 228, .82); font-size: 15px; }
.loop-observation { position: absolute; z-index: 5; right: 5.5%; bottom: 146px; width: min(345px, 28%); padding-left: 18px; border-left: 2px solid #d4eda2; color: #f2f5de; font-size: 13px; line-height: 1.8; text-shadow: 0 2px 8px rgba(0, 0, 0, .8); }

.loop-controls { position: absolute; z-index: 7; left: 5.5%; right: 5.5%; bottom: 35px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-top: 16px; border-top: 1px solid rgba(247, 231, 191, .42); }
.loop-evidence { display: flex; align-items: center; gap: 14px; color: rgba(255, 249, 224, .86); font-size: 12px; }
.loop-evidence strong { color: #d9ffa8; font-size: 13px; }
.loop-evidence-marks { display: flex; gap: 6px; }
.loop-evidence-marks i { display: block; width: 24px; height: 4px; background: rgba(255, 255, 255, .35); }
.loop-evidence-marks i.is-lit { background: #d2fa99; box-shadow: 0 0 12px #aee37c; }
.loop-next,
.loop-exit { position: static; display: inline-flex; align-items: center; justify-content: center; gap: 22px; min-height: 48px; padding: 8px 21px; border: 1px solid #d8eaae; color: #102f24; background: #e9f3d3; font-size: 13px; font-weight: 700; white-space: nowrap; transition: background .2s ease, transform .2s ease; }
.loop-next:hover,
.loop-exit:hover { transform: translateY(-2px); background: #fff9db; }
.loop-next:disabled { opacity: .65; cursor: wait; }
.loop-next span,
.loop-exit span { font-size: 19px; line-height: 1; }

.loop-anomaly { position: absolute; z-index: 8; left: 50%; top: 41%; right: auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; width: 130px; height: 130px; transform: translate(-50%, -50%); border: 1px solid rgba(220, 255, 176, .8); border-radius: 50%; color: #f3ffe3; background: radial-gradient(circle, rgba(132, 226, 122, .7), rgba(12, 85, 61, .5) 42%, rgba(7, 45, 34, .1) 70%); box-shadow: 0 0 45px #93e984, 0 0 120px rgba(131, 243, 109, .55); animation: anomalyPulse 2.3s ease-in-out infinite; }
.loop-anomaly > span { font: 42px Georgia, serif; line-height: 1; }
.loop-anomaly small { font-size: 11px; font-weight: 700; }
.loop-anomaly:hover { background: #8acb73; }

.dream-cracks { z-index: 9; opacity: 0; background: linear-gradient(23deg, transparent 49.6%, rgba(246, 255, 219, .85) 50%, transparent 50.4%), linear-gradient(149deg, transparent 49.7%, rgba(230, 255, 200, .65) 50%, transparent 50.3%); transition: opacity .7s ease; }
.is-broken .dream-cracks { opacity: .68; }
.loop-rewind { z-index: 12; display: grid; place-items: center; opacity: 0; color: #edfabf; background: #041712; transition: opacity .42s ease; }
.loop-rewind span { font-family: var(--display); font-size: 25px; }
.loop-stage.is-rewinding .loop-rewind { opacity: 1; }
.loop-hint { margin: 0; padding: 17px 22px; color: rgba(255, 251, 225, .7); background: #081b17; text-align: center; font-size: 12px; letter-spacing: 0; }

.dream-loop [hidden] { display: none !important; }

@keyframes festivalPetal { to { transform: translate(115px, 110vh) rotate(480deg); } }
@keyframes loopPointPulse { 50% { box-shadow: 0 0 0 13px rgba(186, 246, 138, .08), 0 0 36px rgba(180, 255, 143, .9); } }

@media (max-width: 900px) {
  .loop-copy { bottom: 164px; width: 52%; }
  .loop-copy :is(h1, h2) { font-size: 35px; }
  .loop-observation { bottom: 169px; width: 36%; }
}

@media (max-width: 720px) {
  .dream-loop { padding: 0; }
  .loop-stage { height: max(680px, calc(100svh - 62px)); min-height: 0; }
  .loop-world { background-image: url("../assets/images/sumeru-festival-bazaar-mobile.png"); background-position: center; }
  .loop-shade { background: linear-gradient(180deg, rgba(2, 21, 17, .55), transparent 30%, rgba(2, 17, 14, .22) 48%, rgba(2, 14, 12, .96) 83%); }
  .loop-topline { top: 88px; left: 22px; right: 22px; gap: 10px; font-size: 11px; }
  .loop-topline > span { display: block; max-width: 130px; line-height: 1.5; }
  .loop-topline > span i { display: none; }
  .loop-counter { display: block; }
  .loop-counter span { display: inline; font-size: 10px; }
  .loop-counter strong { display: block; font-size: 36px; }
  .loop-point-flower { left: 20%; top: 54%; }
  .loop-point-stage { left: 50%; top: 47%; }
  .loop-point-lantern { left: 80%; top: 38%; }
  .loop-point { min-width: 67px; }
  .loop-point-glow { width: 38px; height: 38px; }
  .loop-scene-flower { top: 57%; left: 10%; font-size: 32px; }
  .loop-scene-stage { top: 51%; left: 46%; font-size: 70px; }
  .loop-scene-lantern { top: 30%; left: 76%; font-size: 51px; }
  .loop-copy { left: 22px; right: 22px; bottom: 205px; width: auto; }
  .loop-copy :is(h1, h2) { font-size: 31px; }
  .loop-copy > span { font-size: 13px; }
  .loop-observation { left: 22px; right: 22px; bottom: 128px; width: auto; min-height: 44px; font-size: 12px; }
  .loop-controls { left: 22px; right: 22px; bottom: 20px; gap: 9px; }
  .loop-evidence { display: block; font-size: 10px; }
  .loop-evidence strong { display: inline-block; margin-left: 6px; }
  .loop-evidence-marks { margin-top: 7px; }
  .loop-evidence-marks i { width: 18px; }
  .loop-next, .loop-exit { min-height: 44px; gap: 10px; padding: 8px 11px; font-size: 11px; }
  .loop-anomaly { top: 37%; width: 103px; height: 103px; }
  .loop-anomaly > span { font-size: 31px; }
  .loop-anomaly small { font-size: 10px; }
}

@media (max-width: 720px) and (max-height: 720px) {
  .loop-point-flower { top: 42%; }
  .loop-point-stage { top: 39%; }
  .loop-point-lantern { top: 30%; }
  .loop-scene-flower { top: 46%; }
  .loop-scene-stage { top: 43%; }
  .loop-scene-lantern { top: 25%; }
}

@media (prefers-reduced-motion: reduce) {
  .loop-world, .loop-stage, .loop-scene-change, .loop-rewind { transition: none; }
  .loop-falling-petals i, .loop-point.is-current .loop-point-glow, .loop-anomaly { animation: none; }
}
