:root {
  color-scheme: dark;
  background: #080909;
  --door-width: clamp(112px, 12vw, 158px);
  --door-height: calc(var(--door-width) * 2.12);
  --pulse-duration: 6s;
}

* { box-sizing: border-box; }

html, body { width: 100%; min-height: 100%; margin: 0; }
body { overflow: hidden; }
button { -webkit-tap-highlight-color: transparent; }

.scene {
  position: relative;
  width: 100%;
  height: 100svh;
  min-height: 320px;
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(ellipse at 50% 43%, #16221f 0%, #0b1212 37%, #070909 75%);
}

.atmosphere {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 61%, #b9ac8110, transparent 44%),
    radial-gradient(ellipse at 37% 40%, #75bfa008, transparent 40%);
}

.energy-field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.awakening {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: radial-gradient(ellipse at 50% 49%, #e2d8a51c, #69ccb108 32%, transparent 65%);
  transition: opacity 2.4s ease;
  pointer-events: none;
}

.halo {
  position: absolute;
  left: 50%;
  top: 47%;
  width: min(90vw, 850px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, #d9c8970c 0%, #b5aa7e09 25%, #b0aa8004 45%, transparent 68%);
  transform: translate(-50%, -50%);
  animation: breathe var(--pulse-duration) ease-in-out infinite;
  pointer-events: none;
}

.halo--inner {
  width: calc(var(--door-width) * 4.6);
  background: radial-gradient(ellipse, #f2deaa18, #d7c58f08 40%, transparent 66%);
  animation-delay: -.2s;
}

.floor {
  position: absolute;
  inset: calc(47% + var(--door-height) / 2) 0 0;
  background: linear-gradient(#07090900, #080a0a80 60%);
  border-top: 1px solid #c2c3a303;
}

.threshold {
  position: absolute;
  top: 47%;
  left: 50%;
  width: var(--door-width);
  height: var(--door-height);
  transform: translate(calc(-50% + var(--drift-x, 0px)), calc(-50% + var(--drift-y, 0px)));
}

.doorway {
  appearance: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 1px 1px 0 0;
  background: #d5c5a4;
  cursor: pointer;
  outline: none;
  perspective: 850px;
  box-shadow: 0 0 3px #f3e3be66, 0 0 25px #c9b78920, 0 0 80px #d1bc831c;
}

.doorway:focus-visible { outline: 1px solid #f0dfb7; outline-offset: 12px; }

.door-light {
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, #727f61 5%, #c7bd8c 48%, #f1e4c8 90%, #fff4da);
  box-shadow: 3px 0 13px #e5d4a470, 5px 0 42px #d9c79830;
  animation: light-breathe var(--pulse-duration) ease-in-out infinite;
}

.door-frame {
  position: absolute;
  inset: -8px -8px -1px;
  border: 6px solid #1a1d1b;
  border-bottom: 0;
  border-radius: 2px 2px 0 0;
  box-shadow: -2px 0 1px #353a3138, 2px -1px 1px #ccb88840, 8px 0 28px #00000090;
}

.door {
  position: absolute;
  inset: 0;
  display: block;
  transform-origin: left center;
  transform: rotateY(-31deg);
  transform-style: preserve-3d;
  background: linear-gradient(100deg, #101917 0%, #1c2922 56%, #2b3026 100%);
  border: 1px solid #a095702c;
  border-right: 3px solid #5b5943;
  box-shadow: inset -1px 0 #c7b78455, inset 3px 0 8px #00000055, 3px 0 4px #685b3b90;
  transition: transform 1.8s cubic-bezier(.2, .65, .2, 1), filter 1.8s ease;
}

.door-panel {
  position: absolute;
  inset: 14px 12px;
  border: 1px solid #c0b8910c;
  box-shadow: inset 1px 1px 3px #00000030;
  background: linear-gradient(95deg, transparent, #aaa88603 50%, transparent);
}

.door-handle {
  position: absolute;
  top: 56%;
  right: 9px;
  width: 15px;
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(#d2c395, #6a654c 65%, #373a2e);
  box-shadow: 0 2px 3px #000000b3;
}

.door-handle::after {
  content: '';
  position: absolute;
  right: 1px;
  top: -3px;
  width: 3px;
  height: 9px;
  z-index: -1;
  background: #8a806055;
  border-radius: 2px;
}

.sill {
  position: absolute;
  bottom: -2px;
  left: -3px;
  right: -4px;
  height: 3px;
  background: linear-gradient(90deg, #827a5530, #e2cea3aa 80%, #efe1bd);
  box-shadow: 0 2px 6px #ead5a03b;
}

.light-spill {
  position: absolute;
  top: 100%;
  left: -93%;
  width: 430%;
  height: clamp(180px, 35vh, 380px);
  background: linear-gradient(180deg, #e3cf9e30 0%, #d4c18f11 35%, #c3b78f04 66%, transparent 100%);
  clip-path: polygon(22% 0, 45% 0, 100% 100%, 0 100%);
  filter: blur(4px);
  transform-origin: 35% 0;
  animation: light-breathe var(--pulse-duration) ease-in-out infinite;
  transition: opacity 1.8s ease, filter 2.4s ease;
  pointer-events: none;
}

.floor-bloom {
  position: absolute;
  top: calc(100% - 19px);
  left: -120%;
  width: 340%;
  height: 58px;
  border-radius: 50%;
  background: radial-gradient(ellipse, #cfbf9028, #c9bb8310 30%, transparent 68%);
  filter: blur(9px);
  animation: light-breathe var(--pulse-duration) ease-in-out infinite;
}

.door-shadow {
  position: absolute;
  top: 100%;
  left: -150%;
  width: 235%;
  height: 34vh;
  background: linear-gradient(#04060675, transparent 90%);
  clip-path: polygon(64% 0, 100% 0, 30% 100%, 0 100%);
  filter: blur(4px);
  pointer-events: none;
}

.dust { position: absolute; inset: -35% -100%; pointer-events: none; }
.dust i {
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: #e6d6b1;
  opacity: 0;
  animation: drift 14s ease-in-out infinite;
}
.dust i:nth-child(1) { left: 28%; top: 44%; animation-delay: -2s; }
.dust i:nth-child(2) { left: 65%; top: 21%; animation-delay: -7s; width: 1px; }
.dust i:nth-child(3) { left: 76%; top: 60%; animation-delay: -11s; }
.dust i:nth-child(4) { left: 36%; top: 76%; animation-delay: -5s; width: 1px; }
.dust i:nth-child(5) { left: 55%; top: 33%; animation-delay: -13s; width: 1px; }
.dust i:nth-child(6) { left: 18%; top: 65%; animation-delay: -8s; width: 1px; }
.dust i:nth-child(7) { left: 85%; top: 38%; animation-delay: -4s; width: 1px; }
.dust i:nth-child(8) { left: 69%; top: 85%; animation-delay: -10s; width: 1px; }

.grain {
  position: absolute;
  inset: 0;
  opacity: .045;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.92' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Cpath fill='%23fff' filter='url(%23n)' opacity='.7' d='M0 0h180v180H0z'/%3E%3C/svg%3E");
  pointer-events: none;
}

.vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 48%, transparent 25%, #00000035 76%, #00000090 100%);
  pointer-events: none;
}

.scene.is-open .door { transform: rotateY(-63deg); filter: brightness(1.16); }
.scene.is-open .halo--inner { background: radial-gradient(ellipse, #f2deaa24, #d7c58f0d 40%, transparent 66%); }
.scene.is-open .awakening { opacity: 1; }
.scene.is-open .light-spill { filter: blur(7px) brightness(1.7); }

@media (hover: hover) {
  .doorway:hover .door { transform: rotateY(-38deg); }
  .scene.is-open .doorway:hover .door { transform: rotateY(-66deg); }
}

@keyframes breathe {
  0%, 100% { opacity: .45; transform: translate(-50%, -50%) scale(.93); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
}

@keyframes light-breathe {
  0%, 100% { opacity: .62; }
  50% { opacity: 1; }
}

@keyframes drift {
  0%, 100% { opacity: 0; transform: translate(0, 10px); }
  40% { opacity: .23; }
  70% { opacity: .1; }
  95% { opacity: 0; transform: translate(13px, -35px); }
}

@media (max-height: 500px) and (orientation: landscape) {
  :root { --door-width: 90px; }
  .threshold, .halo { top: 43%; }
  .floor { top: calc(43% + var(--door-height) / 2); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .dust { display: none; }
}
