/* intro.css — the tap-to-open TEMPLE-GATE INTRO, and the hold on the cover scene
 * behind it.
 *
 * WHAT THIS IS
 * vansh-ishika's opening temple gate on the Kashi ghat (client 2026-11-19; it replaced
 * the curtain clip). The closed gate paints first, the guest taps, the bell rings, the
 * leaves swing inward, the camera pushes through the doorway into a golden bloom, and
 * the bloom dissolves onto scene 1. js/intro.js drives the lifecycle (its header
 * documents the full choreography); this file only paints. Ported from
 * vansh-ishika/css/intro.css with three deliberate differences, all for this engine:
 *   - the gate sits INSIDE .stage__device (absolute, not fixed), so it inherits the
 *     exact box (and the 28px corner clip on desktop) of the scenes it hands off to;
 *   - the pill is a decorative aria-hidden <div>, not a <button>: the whole gate is the
 *     focusable role=button (as the curtain was), and the copy is data/template.json
 *     `hints.intro`, so the pill stays hidden until that copy has landed (.has-label);
 *   - the html.intro-active hold below, which the cover scene reads.
 *
 * LAYOUT: .gate > .gate__frame (the device box; a size container) > .gate__cam (the
 * camera push: transform only) > .gate__stage (the 1520x2688 painting, "cover"-fitted
 * to the frame, a little above centre so the bell and the doors are never cropped) >
 * .gate__art (every sprite, shown together once they have decoded: .is-ready) + the pill.
 *
 * STATES (classes on .gate, set by js/intro.js)
 *   .is-ready    base + leaves + toran + bell decoded: art fades in over the poster,
 *                the pill rises
 *   .has-pill    safety: the pill shows after 10 s even if decoding stalled
 *   .has-label   the pill's copy has arrived from data/template.json
 *   .is-opening  tapped: the pill retires (WAAPI in js/intro.js plays the opening)
 *   .is-leaving  the dissolve: opacity only, --gate-fade; js/intro.js removes the node
 *                on transitionend with a fallback that MUST outlast --gate-fade
 *
 * iOS: transform / opacity only; no filter / backdrop-filter / mix-blend-mode /
 * will-change anywhere here. The biggest nodes (base, bloom) are frame / stage sized
 * and only ever change opacity or ride the camera's transform.
 */

/* ---------------------------------------------------------------- overlay */

.gate {
  --gate-fade: 900ms; /* js/intro.js FADE_MS — keep in step */
  position: absolute;
  inset: 0;
  z-index: 1000; /* above .nav-layer (900) and every scene layer (<= 500) */
  overflow: hidden;
  background: #e6b68c; /* the painting's mid tone, under the inlined poster */
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  transition: opacity var(--gate-fade) cubic-bezier(0.45, 0.05, 0.25, 1);
}
.gate.is-leaving { opacity: 0; pointer-events: none; }
.gate.is-opening { cursor: default; }

/* keyboard focus: an inset frame — a full-bleed outline round the stage reads badly */
.gate:focus-visible {
  outline: 2px solid var(--gold-hi, #e8d2a2);
  outline-offset: -8px;
}

.gate__frame {
  position: absolute;
  inset: 0;
  overflow: hidden;
  container-type: size;
}
.gate__cam {
  position: absolute;
  inset: 0;
  /* the painting, cover-fitted to the frame (resolved against .gate__frame) */
  --sw: max(100cqw, calc(100cqh * 1520 / 2688));
  --sh: calc(var(--sw) * 2688 / 1520);
}
.gate__stage {
  position: absolute;
  width: var(--sw);
  height: var(--sh);
  left: calc((100cqw - var(--sw)) / 2);
  top: calc((100cqh - var(--sh)) * 0.45);
  background-color: #e6b68c;
  background-size: 100% 100%;
  background-repeat: no-repeat;
}

.gate__art {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 450ms ease;
}
.gate.is-ready .gate__art { opacity: 1; }
.gate__art img, .gate__art i, .gate__art span, .gate__portal, .gate__sanctum, .gate__seam, .gate__bell-sway {
  position: absolute;
  display: block;
  max-width: none;
  pointer-events: none;
  -webkit-user-drag: none;
}
.gate__art [hidden] { display: none; }
.gate__base { inset: 0; width: 100%; height: 100%; }

/* ------------------------------------------------------------ the doorway */
/* the sanctum's own light, clipped to the doorway, behind the leaves */
.gate__sanctum { overflow: hidden; }
.gate__sanctum-glow { left: -35%; top: 10%; width: 170%; height: 110%; opacity: 0; }

.gate__portal {
  /* a small perspective box: the leaves swing INWARD (away from the guest) about
     their outer hinges */
  perspective: calc(var(--sw) * 0.8);
  perspective-origin: 50% 55%;
}
.gate__leaf { position: absolute; top: 0; height: 100%; backface-visibility: hidden; }
.gate__leaf--l { left: 0; transform-origin: 0 50%; }
.gate__leaf--r { right: 0; transform-origin: 100% 50%; }
.gate__leaf > img { left: 0; top: 0; width: 100%; height: 100%; }
/* darker toward the hinge as the leaf turns from the light, lit at its free edge */
.gate__leaf > i { inset: 0; opacity: 0; }
.gate__leaf--l > i { background: linear-gradient(90deg, rgba(34, 16, 4, 0.62) 0%, rgba(34, 16, 4, 0.25) 72%, rgba(255, 222, 160, 0.4) 100%); }
.gate__leaf--r > i { background: linear-gradient(270deg, rgba(34, 16, 4, 0.62) 0%, rgba(34, 16, 4, 0.25) 72%, rgba(255, 222, 160, 0.4) 100%); }

/* the golden line between the closed leaves + its soft halo */
.gate__seam > img { left: 0; top: 0; width: 100%; height: 100%; }
.gate__seam > i {
  left: -260%;
  right: -260%;
  top: 0;
  bottom: 0;
  opacity: 0.5;
  background: linear-gradient(90deg,
    rgba(255, 200, 110, 0) 0%, rgba(255, 206, 120, 0.2) 36%, rgba(255, 232, 170, 0.55) 48%,
    rgba(255, 244, 210, 0.7) 50%, rgba(255, 232, 170, 0.55) 52%, rgba(255, 206, 120, 0.2) 64%, rgba(255, 200, 110, 0) 100%);
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 14%, #000 90%, transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0%, #000 14%, #000 90%, transparent 100%);
}
/* light leaking under the closed doors onto the threshold */
.gate__underglow {
  opacity: 0.45;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 236, 190, 0.95), rgba(255, 214, 140, 0.4) 55%, rgba(255, 200, 120, 0) 100%);
}
.gate__bell { left: 0; top: 0; width: 100%; height: 100%; }

/* ------------------------------------------------------------ ambient sprites */
.gate__flame { opacity: 0.75; }
.gate__glint { opacity: 0; }
.gate__mote { opacity: 0; }
.gate__spill, .gate__halo { opacity: 0; }
.gate__petals { position: absolute; inset: 0; pointer-events: none; }
.gate__petal { height: auto; opacity: 0; }

/* ------------------------------------------------------------ the pill */
/* Ivory pill in vansh-ishika's slide-hint style, px-sized here: the gate has no
   1080-px stage unit. Low on the steps, between the diyas. Decorative (aria-hidden,
   pointer-events none): the tap anywhere lands on .gate itself. Cormorant Garamond
   600 is this invitation's own preloaded face; "Tap to open" is inside its subset. */
.gate__open {
  position: absolute;
  left: 50%;
  top: 90.8%;
  z-index: 5;
  translate: -50% -50%;
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  min-height: 44px;
  box-sizing: border-box;
  margin: 0;
  padding: 0.5em 1.45em 0.5em 0.8em;
  border-radius: 999px;
  background: rgba(255, 251, 241, 0.9);
  box-shadow: inset 0 0 0 1.5px rgba(184, 134, 43, 0.6), 0 6px 22px rgba(60, 34, 12, 0.32);
  color: #6a3416;
  font: 600 clamp(16px, 4.6cqw, 20px)/1.15 "Cormorant Garamond", Georgia, "Times New Roman", serif;
  letter-spacing: 0.035em;
  white-space: nowrap;
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 600ms ease, transform 900ms cubic-bezier(0.22, 1, 0.36, 1), visibility 0s linear 900ms;
}
/* an empty pill is worse than none: it waits for the copy (.has-label) as well */
.gate.has-label.is-ready .gate__open, .gate.has-label.has-pill .gate__open {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition: opacity 600ms ease, transform 900ms cubic-bezier(0.22, 1, 0.36, 1), visibility 0s;
}
.gate.is-opening .gate__open,
.gate.has-label.is-ready.is-opening .gate__open,
.gate.has-label.has-pill.is-opening .gate__open {
  opacity: 0;
  visibility: hidden;
  animation: none;
  transition: opacity 240ms ease, visibility 0s linear 240ms;
}
/* the tap gesture in miniature */
.gate__tap {
  position: relative;
  flex: none;
  width: 1.45em;
  height: 1.45em;
  color: #b8862b;
}
.gate__tap::before {
  content: "";
  position: absolute;
  inset: 16%;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  opacity: 0.45;
}
.gate__tap > span {
  position: absolute;
  inset: 0;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  opacity: 0;
}
.gate__tap > i {
  position: absolute;
  left: 33%;
  top: 33%;
  width: 34%;
  height: 34%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, #fffdf7 0%, #f6e3b8 52%, rgba(184, 134, 43, 0.85) 100%);
  box-shadow: 0 0 4px rgba(214, 160, 70, 0.7);
}

/* the warm golden bloom the camera pushes into (frame-sized, opacity only) */
.gate__bloom {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at var(--ox, 50%) var(--oy, 55%),
    #fffaf0 0%, rgba(255, 238, 200, 0.98) 30%, rgba(252, 214, 150, 0.95) 65%, rgba(240, 190, 120, 0.92) 100%);
}

/* ------------------------------------------------------------ waiting ambient */
/* Visible but gentle; motion only. Reduced motion = the still painting. */
@media (prefers-reduced-motion: no-preference) {
  .gate__bell-sway { animation: gate-sway 5.2s ease-in-out infinite; }
  .gate__seam > img { animation: gate-seam 3.8s ease-in-out infinite; }
  .gate__seam > i { animation: gate-halo 3.8s ease-in-out infinite; }
  .gate__underglow { animation: gate-under 3.8s ease-in-out 0.4s infinite; }
  .gate__flame { animation: gate-flicker var(--t, 1.6s) linear var(--d, 0s) infinite; }
  .gate__glint { animation: gate-glint var(--t, 3.4s) ease-in-out var(--d, 0s) infinite; }
  .gate__mote { animation: gate-mote var(--t, 9s) linear var(--d, 0s) infinite; }
  .gate.has-label.is-ready .gate__open, .gate.has-label.has-pill .gate__open { animation: gate-float 2.8s ease-in-out 0.9s infinite; }
  .gate.is-ready .gate__tap > span, .gate.has-pill .gate__tap > span { animation: gate-ring-out 2.2s cubic-bezier(0.33, 1, 0.68, 1) infinite; }
  .gate.is-ready .gate__tap > span + span, .gate.has-pill .gate__tap > span + span { animation-delay: 300ms; }
  .gate.is-ready .gate__tap > i, .gate.has-pill .gate__tap > i { animation: gate-core-beat 2.2s cubic-bezier(0.33, 1, 0.68, 1) infinite; }
}
@keyframes gate-sway { 0%, 100% { transform: rotate(-1.6deg); } 50% { transform: rotate(1.6deg); } }
@keyframes gate-seam { 0%, 100% { opacity: 0.82; } 50% { opacity: 1; } }
@keyframes gate-halo { 0%, 100% { opacity: 0.32; transform: scaleX(0.85); } 50% { opacity: 0.75; transform: scaleX(1.12); } }
@keyframes gate-under { 0%, 100% { opacity: 0.3; } 50% { opacity: 0.62; } }
@keyframes gate-flicker {
  0% { opacity: 0.72; transform: scale(1, 1); }
  13% { opacity: 0.9; transform: scale(1.06, 1.1); }
  21% { opacity: 0.62; transform: scale(0.96, 0.94); }
  38% { opacity: 0.85; transform: scale(1.02, 1.06); }
  52% { opacity: 0.7; transform: scale(0.98, 0.97); }
  66% { opacity: 0.95; transform: scale(1.07, 1.12); }
  81% { opacity: 0.66; transform: scale(0.97, 0.95); }
  100% { opacity: 0.72; transform: scale(1, 1); }
}
@keyframes gate-glint {
  0%, 62%, 100% { opacity: 0; transform: scale(0.4, 0.3); }
  76% { opacity: 0.95; transform: scale(1.6, 0.7); }
}
@keyframes gate-mote {          /* rises through the seam light, swaying (frame units) */
  0% { opacity: 0; transform: translate(0, 0); }
  15% { opacity: 0.85; }
  50% { transform: translate(calc(var(--dx, 1) * 1.6cqw), -5cqh); }
  85% { opacity: 0.6; }
  100% { opacity: 0; transform: translate(calc(var(--dx, 1) * -1cqw), -10cqh); }
}
@keyframes gate-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes gate-ring-out {
  0% { opacity: 0; transform: scale(0.3); }
  6% { opacity: 1; }
  32%, 100% { opacity: 0; transform: scale(1.16); }
}
@keyframes gate-core-beat {
  0% { transform: scale(1); }
  4% { transform: scale(1.26); }
  11% { transform: scale(1); }
  18% { transform: scale(1.22); }
  26%, 100% { transform: scale(1); }
}

/* ------------------------------------------------------------------ hold */
/* Held while the gate owns the screen. js/stage.js is not ours to edit, so the
   engine's entry cascade is nulled out here instead: the cover would otherwise spend
   its one arrival animation behind an opaque overlay and be settled by the time the
   guest saw it. js/scenes/cover.js plays the arrival itself on `intro:done`, which
   js/intro.js fires at the START of the dissolve, so the two crossfade.
   The class is only ever set by the inline <head> script, so a no-JS visitor (who
   never sees the overlay either — see the <noscript> in index.html) is never gated. */
html.intro-active .scene.is-entering .layer,
html.intro-active .scene.is-entering .scene-text {
  animation-name: none;
}

/* Nothing behind the gate is reachable. js/intro.js also sets `inert` on the two
   mounts, which is what actually takes them out of the tab order; this is the CSS half
   for engines without inert support. */
html.intro-active .stage__viewport,
html.intro-active .nav-layer {
  pointer-events: none;
}

/* --------------------------------------------------------- reduced motion */
/* The still painting: no ambient (the no-preference block above), the art appears
   without its fade, and css/base.css collapses every remaining transition — the
   dissolve included — to 0.01ms, so the tap lands straight on the cover. */
@media (prefers-reduced-motion: reduce) {
  .gate { --gate-fade: 250ms; }
  .gate__art { transition: none; }
}
