* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #2a0e04;
  -webkit-tap-highlight-color: transparent;
}

img { user-select: none; -webkit-user-drag: none; }

/* ---------- Scene ---------- */
.scene {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  outline: none;
  overflow: hidden;
  background: #3a1405;
}
/* Page-filling backdrop made from the door photo itself (blurred),
   so the page is always fully covered on any screen shape */
.scene::before {
  content: "";
  position: absolute; inset: -10%;
  background: url('images/backdrop.jpg') center / cover no-repeat;
  filter: blur(34px) brightness(.6) saturate(1.1);
}
.scene::after {              /* soft vignette */
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 45%, rgba(20,6,0,.55) 100%);
  pointer-events: none;
}

/* ---------- Stage ----------
   The door (image ratio 2:3) is scaled as large as the screen allows:
   it fits the height on tablets/PCs, and on tall phones it uses the full
   width (with a tiny trim at the edges). Leftover space is filled by the backdrop. */
.door-stage {
  --w: min(112vw, calc(100vh * 2 / 3));
  position: relative;
  z-index: 1;
  flex: none;
  width: var(--w);
  height: calc(var(--w) * 1.5);   /* 2:3 ratio – explicit height also works in older browsers */
  perspective: calc(var(--w) * 1.6);
  perspective-origin: 50% 56%;
  isolation: isolate;
  font-size: calc(var(--w) / 100);      /* 1em = 1% of door width, used for blur sizes */
}
@supports (height: 100dvh) {
  .door-stage { --w: min(112vw, calc(100dvh * 2 / 3)); }
}

/* ---------- Frame (static, top layer) ---------- */
.frame {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  z-index: 10;
  pointer-events: none;
}

/* ---------- Door leaves ---------- */
.leaf {
  position: absolute;
  top: 14.648%;               /* 225 / 1536  */
  width: 34.18%;              /* 350 / 1024  */
  height: 82.161%;            /* 1262 / 1536 */
  z-index: 2;
  backface-visibility: hidden;
  transition: transform 1.5s cubic-bezier(.65, .02, .25, 1),
              filter 1.5s ease;
}
.leaf.left  { left: 15.918%; transform-origin: left center;  }   /* 163 / 1024 */
.leaf.right { left: 50.098%; transform-origin: right center; }   /* 513 / 1024 */

.scene.open .leaf.left  { transform: rotateY(72deg);  filter: brightness(.85); }
.scene.open .leaf.right { transform: rotateY(-72deg); filter: brightness(.85); }

/* ---------- Sunlight (only the door-opening rectangle) ---------- */
.sunlight {
  position: absolute;
  left: 15.918%;              /* 163 / 1024  */
  top: 14.648%;               /* 225 / 1536  */
  width: 68.36%;              /* 700 / 1024  */
  height: 82.161%;            /* 1262 / 1536 */
  z-index: 1;
  overflow: hidden;
  /* Clip the light to the exact door opening, so it can never show on the frame,
     on any screen size or browser (the frame hole is 165..861 x 227..1485 of 1024x1536) */
  clip-path: inset(0.127% 0.229% 0.127% 0.229%);
  opacity: 0;
  transition: opacity .8s ease .1s;
  pointer-events: none;
  background: linear-gradient(to bottom, #ffffff 0%, #fff6d0 50%, #ffe9a6 100%);
}
.scene.open .sunlight { opacity: 1; }

/* Soft light shafts – sized in % and blurred in em so they scale with the door */
.shaft {
  position: absolute; top: -10%; height: 120%;
  background: linear-gradient(to bottom, rgba(255,214,120,.55), rgba(255,214,120,0));
  filter: blur(2.5em);
  transform: skewX(-12deg);
  animation: shimmer 3.5s ease-in-out infinite alternate;
}
.s1 { left: 8%;  width: 22%; }
.s2 { left: 40%; width: 20%; animation-delay: -1.2s; }
.s3 { left: 70%; width: 22%; animation-delay: -2.4s; }
@keyframes shimmer { from { opacity: .45; } to { opacity: 1; } }

/* ---------- Hint ---------- */
.hint {
  position: absolute; left: 50%; bottom: max(3%, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 6;
  padding: .6em 1.4em;
  font: 600 clamp(12px, 2vw, 20px)/1 Georgia, serif;
  letter-spacing: .12em; text-transform: uppercase;
  white-space: nowrap;
  color: #fff3c4;
  background: rgba(40, 12, 2, .75);
  border: 1px solid rgba(255, 214, 120, .7);
  border-radius: 999px;
  animation: pulse 1.8s ease-in-out infinite;
  transition: opacity .4s;
}
.scene.open .hint { opacity: 0; animation: none; }

@keyframes pulse {
  0%, 100% { transform: translateX(-50%) scale(1);    opacity: .9; }
  50%      { transform: translateX(-50%) scale(1.07); opacity: 1;  }
}

@media (prefers-reduced-motion: reduce) {
  .leaf, .sunlight { transition-duration: .5s; }
  .shaft { animation: none; }
}

/* ---------- Soft golden glow + floating dust ---------- */
/* Warm glow that gently breathes; edges glow gold, center stays bright */
.sunlight::after {
  content: "";
  position: absolute; inset: 0;
  box-shadow: inset 0 0 9em 2em rgba(255, 190, 70, .75);
  animation: breathe 3.2s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes breathe { from { opacity: .55; } to { opacity: 1; } }

/* Golden dust specks (created by script.js); sizes in em so they scale with the door */
.dust {
  position: absolute;
  bottom: -3%;
  border-radius: 50%;
  background: radial-gradient(circle, #fffbe6 0%, #ffd873 55%, rgba(255, 200, 80, 0) 100%);
  box-shadow: 0 0 .8em rgba(255, 215, 120, .9);
  opacity: 0;
  animation: float var(--dur, 8s) linear var(--delay, 0s) infinite;
}
@keyframes float {
  0%   { transform: translate(0, 0) scale(.6); opacity: 0; }
  15%  { opacity: var(--o, .9); }
  85%  { opacity: var(--o, .9); }
  100% { transform: translate(var(--dx, 3em), -78em) scale(1); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .dust, .sunlight::after { animation: none; }
}

/* The frame casts a soft shadow on the light, so the light looks like it is behind the frame */
.sunlight::before {
  content: "";
  position: absolute; inset: 0;
  z-index: 2;
  box-shadow: inset 0 2.2em 2.6em -.6em rgba(70, 25, 5, .55),
              inset 1.8em 0 2.2em -.8em rgba(70, 25, 5, .4),
              inset -1.8em 0 2.2em -.8em rgba(70, 25, 5, .4);
  pointer-events: none;
}
