:root {
  --scene-scale: 1;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: #050302;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #f5e6c8;
}

button {
  font: inherit;
}

#app,
.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.scene {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 520ms ease,
    visibility 0s linear 520ms;
}

.scene.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition:
    opacity 520ms ease,
    visibility 0s linear 0s;
}

.stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1672px;
  height: 941px;
  transform: translate3d(-50%, -50%, 0) scale(var(--scene-scale));
  transform-origin: center center;
}

.stage-content {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #050302;
  transform-origin: center center;
  will-change: transform, opacity, filter;
}

.scene-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  pointer-events: none;
}

.full-click {
  position: absolute;
  inset: 0;
  z-index: 40;
  border: 0;
  background: transparent;
  cursor: pointer;
}



.room-under-door {
  z-index: 0;
  opacity: 1;
  filter: brightness(0.72) contrast(1.04) blur(0.35px);
  transform: scale(1.035);
  transform-origin: center center;
  transition:
    filter 1650ms ease,
    transform 1650ms cubic-bezier(0.16, 0.84, 0.18, 1);
}

#doorScene.opening .room-under-door {
  filter: brightness(0.96) contrast(1) blur(0);
  transform: scale(1);
}

.door-frame {
  z-index: 16;
}

.door-leaves {
  position: absolute;
  inset: 0;
  z-index: 18;
  perspective: 1900px;
  perspective-origin: 50% 48%;
  transform-style: preserve-3d;
  pointer-events: none;
}

.door-leaf {
  position: absolute;
  top: 90px;
  height: 838px;
  display: block;
  max-width: none;
  user-select: none;
  pointer-events: none;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  transform: translate3d(0, 0, 0) rotateY(0deg);
  filter: brightness(1) contrast(1);
  will-change: transform, filter, box-shadow;
  transition:
    transform 1650ms cubic-bezier(0.12, 0.78, 0.13, 1),
    filter 1650ms ease,
    box-shadow 1650ms ease;
}

.door-leaf-left {
  left: 440px;
  width: 385px;
  transform-origin: 0% 50%;
  box-shadow: 10px 0 18px rgba(0, 0, 0, 0.18);
}

.door-leaf-right {
  left: 825px;
  width: 390px;
  transform-origin: 100% 50%;
  box-shadow: -10px 0 18px rgba(0, 0, 0, 0.18);
}

#doorScene.opening .door-leaf-left {
  transform: translate3d(10px, 0, -46px) rotateY(86deg) skewY(0.2deg);
  filter: brightness(0.68) contrast(1.08);
  box-shadow: 18px 0 34px rgba(0, 0, 0, 0.28);
}

#doorScene.opening .door-leaf-right {
  transform: translate3d(-10px, 0, -46px) rotateY(-86deg) skewY(-0.2deg);
  filter: brightness(0.68) contrast(1.08);
  box-shadow: -18px 0 34px rgba(0, 0, 0, 0.28);
}

#doorScene.opening .full-click {
  opacity: 0;
  pointer-events: none;
}

#doorScene.opening .door-frame {
  animation: doorFrameSettle 1650ms cubic-bezier(0.12, 0.78, 0.13, 1) both;
}

@keyframes doorFrameSettle {
  0% {
    filter: brightness(1);
  }

  55% {
    filter: brightness(0.92);
  }

  100% {
    filter: brightness(0.98);
  }
}



.forward-arrow {
  position: absolute;
  left: 50%;
  bottom: 6.5%;
  z-index: 20;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 232, 177, 0.46);
  border-radius: 999px;
  background: rgba(7, 4, 2, 0.38);
  color: #ffe8b8;
  font-size: 26px;
  cursor: pointer;
  opacity: 0;
  transform: translate3d(-50%, 14px, 0) rotate(-90deg);
  box-shadow: 0 0 22px rgba(226, 172, 86, 0.18);
  backdrop-filter: blur(4px);
  transition:
    opacity 350ms ease,
    transform 350ms ease,
    background 220ms ease,
    box-shadow 220ms ease;
}

#roomScene.active .forward-arrow {
  opacity: 1;
  transform: translate3d(-50%, 0, 0) rotate(-90deg);
  animation: arrowFloat 1.65s ease-in-out 350ms infinite;
}

.forward-arrow:hover,
.forward-arrow:focus-visible {
  background: rgba(40, 22, 8, 0.64);
  box-shadow: 0 0 30px rgba(255, 208, 124, 0.32);
  outline: none;
}

@keyframes arrowFloat {
  0%,
  100% {
    transform: translate3d(-50%, 0, 0) rotate(-90deg);
  }

  50% {
    transform: translate3d(-50%, -8px, 0) rotate(-90deg);
  }
}



#roomScene.moving-forward .stage-content {
  animation: moveForward 780ms cubic-bezier(0.2, 0.85, 0.24, 1) forwards;
}

@keyframes moveForward {
  from {
    transform: scale(1);
    opacity: 1;
    filter: blur(0);
  }

  to {
    transform: scale(1.085);
    opacity: 0;
    filter: blur(2px);
  }
}

#closeRoomScene.entering .stage-content {
  animation: arriveClose 680ms cubic-bezier(0.2, 0.85, 0.24, 1) both;
}

@keyframes arriveClose {
  from {
    transform: scale(1.055);
    opacity: 0;
    filter: blur(1.5px);
  }

  to {
    transform: scale(1);
    opacity: 1;
    filter: blur(0);
  }
}



.image-popup-overlay {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
}

.image-popup-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.image-popup {
  position: relative;
  width: min(1000px, 90vw);
  max-width: 1000px;
  transform: translateY(18px) scale(0.96);
  transition: transform 260ms ease;
}

.image-popup-overlay.visible .image-popup {
  transform: translateY(0) scale(1);
}

.letter-popup {
  position: relative;
  width: min(500px, 80vw);
}

.popup-bg {
  display: block;
  width: 100%;
  height: auto;
}

.popup-close {
    position: absolute;
    top: 12px;
    right: 12px;

    width: 42px;
    height: 42px;

    display: flex;
    justify-content: center;
    align-items: center;

    padding: 0;
    border: none;
    border-radius: 50%;

    background: rgba(116, 96, 58, 0.45);
    color: #fff6df;
    cursor: pointer;

    z-index: 9999;
}

.popup-close span {
    font-size: 22px;
    line-height: 1;
    transform: translateY(-1px);
}

.popup-close:hover {
    background: rgba(116, 96, 58, 0.65);
}

.popup-close:hover {
  background: rgba(40, 20, 8, 0.55);
}

.letter-text {
  position: absolute;
  left: 16%;
  top: 18%;
  width: 68%;
  height: 64%;
  color: #050302;
}

.letter-text h2 {
  font-size: 28px;
}

.letter-text p {
  font-size: 18px;
  line-height: 1.5;
}




.book-popup {
  width: min(1100px, 90vw);
}


.book-page {
  position: absolute;
  inset: 0;
  color: #1b1208;
  font-family: Georgia, "Times New Roman", serif;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.book-page.active {
  opacity: 1;
  pointer-events: auto;
}


.book-left {
  position: absolute;
  left: 14%;
  top: 14%;
  width: 34%;
  height: 62%;
  text-align: center;
}


.book-right {
  position: absolute;
  left: 52%;
  top: 14%;
  width: 34%;
  height: 62%;
  text-align: center;
}


.book-left h2,
.book-right h2 {
  margin: 0 0 1rem;
  font-size: 34px;
  color: #1b1208;
}


.book-left p,
.book-right p {
  margin: 0 0 1rem;
  font-size: 22px;
  line-height: 1.55;
  color: #1b1208;
}


.book-popup .book-page,
.book-popup .book-page * {
  color: #1b1208;
}

.book-controls {
  position: absolute;
  left: 50%;
  bottom: 5%;
  z-index: 8;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: #ffe8bb;
}

.book-controls button {
  border: 1px solid rgba(255, 225, 160, 0.4);
  border-radius: 999px;
  padding: 0.5rem 0.85rem;
  background: rgba(8, 4, 2, 0.55);
  color: #ffe8bb;
  cursor: pointer;
}

.book-controls button:hover,
.book-controls button:focus-visible {
  background: rgba(47, 25, 9, 0.75);
  outline: none;
}

.book-controls button:disabled {
  opacity: 0.35;
  cursor: default;
}

@media (prefers-reduced-motion: reduce) {
  .scene,
  .stage-content,
  .door-leaf,
  .room-under-door,
  .door-frame,
  .forward-arrow,
  .image-popup-overlay,
  .image-popup,
  .book-page {
    animation: none !important;
    transition: none !important;
  }
}