/* Standalone homepage overlay. All page styling stays in styles.css. */
html.has-opening {
  overflow: hidden;
  overscroll-behavior: none;
  scrollbar-gutter: stable;
}

.opening {
  --opening-version: 20261029-mobile4;
  --opening-ready: 1;
  --opening-pause: .5s;
  --opening-duration: 2s;
  --opening-fade: .8s;
  --opening-material: url("assets/opening/ornate-doors-v2-desktop.webp");
  position: fixed;
  inset: 0;
  z-index: 1000;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: transparent;
  color: #f4ebdd;
  touch-action: none;
}

.opening:not([open]) { display: none; }
/* The tiny head script gates this state before first paint. */
html.has-opening .opening:not([open]) { display: block; }
.opening::backdrop { background: transparent; }

.opening__scene {
  position: absolute;
  inset: 0;
  perspective: clamp(900px, 130vw, 2200px);
  perspective-origin: 50% 50%;
  pointer-events: none;
}

.opening__shade {
  position: absolute;
  inset: 0;
  background: rgba(20, 12, 5, .22);
}

.opening__light {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: radial-gradient(ellipse 20% 84% at 50% 51%, rgba(249, 192, 100, .2), rgba(217, 149, 60, .055) 44%, transparent 76%);
}

.opening__light::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(50% - 1.5px);
  width: 3px;
  background: #fff1cb;
  box-shadow: 0 0 14px 5px rgba(255, 222, 161, .95), 0 0 44px 15px rgba(244, 181, 82, .54), 0 0 105px 32px rgba(230, 159, 65, .2);
}

.opening__light::after {
  content: "";
  position: absolute;
  bottom: -15%;
  left: 8%;
  width: 84%;
  height: 40%;
  background: radial-gradient(ellipse at center, rgba(246, 194, 107, .26), transparent 68%);
  filter: blur(18px);
}

.opening__door {
  --opening-position: 0%;
  position: absolute;
  top: 0;
  bottom: 0;
  width: calc(50% - 1px);
  border-top: 1px solid rgba(231, 189, 124, .12);
  border-bottom: 1px solid rgba(7, 4, 2, .7);
  background-color: #562b17;
  box-shadow: 0 12px 42px rgba(0, 0, 0, .55);
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

.opening__door::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(90deg, rgba(17, 7, 2, .1), transparent 18%, transparent 82%, rgba(17, 7, 2, .12)), var(--opening-material);
  /* One complete pair, split exactly at its center; retain all carved detail. */
  background-size: 100% 100%, 200% 100%;
  background-position: center, var(--opening-position) center;
  box-shadow: inset 0 0 28px rgba(16, 6, 1, .13);
}

.opening__door::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: clamp(8px, .9vw, 15px);
  background: linear-gradient(90deg, #2c1209, #8b4826 38%, #4b2211);
  backface-visibility: hidden;
}

.opening__door--left {
  left: 0;
  transform-origin: left center;
  border-right: 1px solid rgba(198, 133, 66, .5);
}

.opening__door--right {
  right: 0;
  transform-origin: right center;
  --opening-position: 100%;
  border-left: 1px solid rgba(198, 133, 66, .5);
}

.opening__door--left::after {
  right: 0;
  transform-origin: right center;
  transform: rotateY(-90deg);
}
.opening__door--right::after {
  left: 0;
  transform-origin: left center;
  transform: rotateY(90deg);
}

.opening__skip {
  position: absolute;
  top: max(22px, env(safe-area-inset-top));
  right: max(26px, env(safe-area-inset-right));
  z-index: 2;
  min-width: 76px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid rgba(227, 202, 159, .48);
  border-radius: 2px;
  background: rgba(24, 16, 10, .94);
  color: #f4ebdd;
  font: 12px/1.4 Inter, "Helvetica Neue", Arial, sans-serif;
  letter-spacing: .12em;
  touch-action: manipulation;
  transition: background-color .15s, border-color .15s;
}

.opening__skip:hover { background: rgba(24, 16, 10, .9); border-color: #d6b77e; }
.opening__skip:focus-visible { outline: 2px solid #f0cf91; outline-offset: 5px; }

.opening--running {
  animation: opening-overlay-fade var(--opening-fade) calc(var(--opening-pause) + var(--opening-duration)) ease-in-out both;
}
.opening--running .opening__door { will-change: transform; }
.opening--running .opening__door--left {
  animation: opening-left var(--opening-duration) var(--opening-pause) cubic-bezier(.32, .06, .16, 1) both;
}
.opening--running .opening__door--right {
  animation: opening-right var(--opening-duration) var(--opening-pause) cubic-bezier(.32, .06, .16, 1) both;
}
.opening--running .opening__light {
  animation: opening-light var(--opening-duration) var(--opening-pause) ease-out both;
}
.opening--running .opening__light::before {
  animation: opening-seam .65s var(--opening-pause) ease-out both;
}

@keyframes opening-left { from { transform: rotateY(0); } to { transform: rotateY(-106deg); } }
@keyframes opening-right { from { transform: rotateY(0); } to { transform: rotateY(106deg); } }
@keyframes opening-light { 0% { opacity: 1; } 42% { opacity: .8; } 100% { opacity: 0; } }
@keyframes opening-seam { from { opacity: 1; } to { opacity: 0; } }
@keyframes opening-overlay-fade { from { opacity: 1; } to { opacity: 0; } }

@media (max-width: 600px) {
  .opening { --opening-material: url("assets/opening/ornate-doors-v2-mobile.webp"); }
  .opening__skip { top: max(18px, env(safe-area-inset-top)); right: max(18px, env(safe-area-inset-right)); }
  .opening__door { box-shadow: 0 12px 24px rgba(0, 0, 0, .45); }
  .opening__door::before { box-shadow: inset 0 0 20px rgba(16, 6, 1, .1); }
}

@media (prefers-reduced-motion: reduce) {
  html.has-opening { overflow: revert; overscroll-behavior: revert; scrollbar-gutter: auto; }
  .opening, html.has-opening .opening:not([open]) { display: none !important; animation: none !important; }
  .opening * { animation: none !important; transition: none !important; }
}

/* Opt-in diagnostics only; never rendered during a normal visit. */
.opening-check {
  position: fixed;
  z-index: 2000;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 12px;
  right: 12px;
  max-width: 520px;
  max-height: 75vh;
  max-height: 75dvh;
  overflow: auto;
  padding: 20px;
  border: 1px solid #bd9a62;
  background: #201b17;
  color: #f4ebdd;
  font: 14px/1.65 Arial, sans-serif;
  box-shadow: 0 8px 40px #000a;
}
.opening-check h2 { margin: 0 0 10px; font-size: 17px; color: #e2c28f; }
.opening-check pre { margin: 0 0 12px; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }
.opening-check p { margin: 10px 0; }
.opening-check__actions { display: flex; flex-wrap: wrap; gap: 10px; }
.opening-check button { min-height: 44px; padding: 8px 14px; border: 1px solid #bd9a62; background: #30271e; color: #f4ebdd; font: inherit; cursor: pointer; }
.opening-check button:focus-visible { outline: 2px solid #f0cf91; outline-offset: 3px; }
