/* ==========================================================================
   Tsuroya entry gate: the "Impact Constellation" intro screen.
   Loaded by index.php only. Every rule below is scoped to html.is-intro,
   a class the inline script in index.php's <head> adds before first paint.
   Without JS the class is never added and this file is inert.
   ========================================================================== */

:root {
  /* Above the mission dock and WhatsApp FAB (1000), below the success modal (9999). */
  --z-intro: 2000;
}

.intro-gate {
  display: none;
}

html.is-intro,
html.is-intro body {
  overflow: hidden;
  overscroll-behavior: none;
}

html.is-intro body {
  height: 100%;
}

html.is-intro .intro-gate {
  position: fixed;
  z-index: var(--z-intro);
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  touch-action: none;
  overscroll-behavior: none;
  /* Byte for byte the .hero base gradient, so the handoff shifts no colour. */
  background: linear-gradient(135deg, #020a1d 0%, var(--navy-950) 36%, #082966 100%);
}

/* --------------------------------------------------------------------------
   Layers: nebula, then stars, then bloom, then the lockup.
   Absolute layers are painted in DOM order, so the lockup needs no z-index.
   -------------------------------------------------------------------------- */

.intro-gate-nebula {
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(closest-side, rgba(255, 195, 34, 0.13), transparent 70%) 62% 38% / 52vmax 52vmax no-repeat,
    radial-gradient(closest-side, rgba(21, 92, 245, 0.16), transparent 70%) 30% 68% / 64vmax 64vmax no-repeat;
  filter: blur(6px);
  pointer-events: none;
  will-change: transform;
  animation: introDrift 44s ease-in-out infinite alternate;
}

@keyframes introDrift {
  from {
    transform: translate3d(-1.5%, 1%, 0) scale(1);
  }
  to {
    transform: translate3d(1.5%, -1%, 0) scale(1.08);
  }
}

.intro-gate-sky {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.intro-gate-bloom {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 46vmax;
  height: 46vmax;
  margin: -23vmax 0 0 -23vmax;
  border-radius: 50%;
  background: radial-gradient(
    closest-side,
    rgba(255, 255, 255, 0.55),
    rgba(255, 195, 34, 0.42) 22%,
    rgba(119, 168, 255, 0.18) 46%,
    transparent 70%
  );
  opacity: 0;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   The lockup: eyebrow, logo, invitation, hint.
   -------------------------------------------------------------------------- */

.intro-gate-core {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  max-width: min(92vw, 560px);
  padding: 0 20px;
  text-align: center;
  pointer-events: none;
}

.intro-gate-kicker {
  margin: 0;
  color: var(--yellow-300);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  opacity: 0.82;
}

.intro-gate-logo-wrap {
  position: relative;
  display: grid;
  place-items: center;
}

/* Warm halo standing in for the hero canvas's golden core mark. */
.intro-gate-logo-wrap::before {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 132%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(
    closest-side,
    rgba(255, 195, 34, 0.22),
    rgba(255, 195, 34, 0.06) 55%,
    transparent 72%
  );
  transform: translate(-50%, -50%);
  content: "";
  pointer-events: none;
  animation: introCorePulse 3.8s ease-in-out infinite;
}

/* Matches the existing corePulse values in tsuroya-styles.css. */
@keyframes introCorePulse {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(0.9);
    opacity: 0.45;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.06);
    opacity: 0.85;
  }
}

.intro-gate-logo {
  display: block;
  width: min(58vw, 420px);
  height: auto;
  max-height: 34vh;
  object-fit: contain;
}

/* The invitation is drawn with the constellation's own line language rather
   than as a UI control: a spark flanked by hairlines that fade outward, using
   the exact gold-to-blue stops drawLinks uses on the canvas. Nothing is
   bordered, filled, blurred, or lifted on hover, so it never reads as a panel
   sitting on top of the star field. */
.intro-gate-enter {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  gap: 10px;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: 12px 8px;
  background: none;
  color: var(--yellow-300);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.06em;
  cursor: pointer;
  pointer-events: auto;
  text-shadow: 0 2px 14px rgba(2, 10, 29, 0.85);
  transition: color 220ms ease;
}

/* Borderless scrim so passing stars never collide with the glyphs. The radial
   falloff has no edge, which is the whole point: it darkens the row without
   drawing a box. The box is kept much larger than the visible reach so the
   alpha is already at zero where its bounds end. Contained by the isolation
   above. */
.intro-gate-enter::before {
  position: absolute;
  z-index: -1;
  inset: -54px -56px;
  background: radial-gradient(46% 62% at 50% 50%, rgba(2, 10, 29, 0.66), rgba(2, 10, 29, 0) 88%);
  content: "";
  pointer-events: none;
}

.intro-gate-enter-label {
  white-space: nowrap;
}

/* Same 8-point geometry as sparkPath on the canvas: outer 50%, inner 0.28 of
   that at each 45 degree step. Filled with the exact spark colour drawNodes
   uses, so the glyph and the animated sparks are the same object. */
.intro-gate-spark {
  width: 11px;
  height: 11px;
  flex: 0 0 auto;
  background: #ffe176;
  clip-path: polygon(50% 0%, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0% 50%, 40% 40%);
  filter: drop-shadow(0 0 6px rgba(255, 225, 118, 0.6));
  animation: introSparkBreath 3.4s ease-in-out infinite;
}

@keyframes introSparkBreath {
  0%,
  100% {
    opacity: 0.78;
    transform: scale(0.88) rotate(0deg);
  }
  50% {
    opacity: 1;
    transform: scale(1.08) rotate(22.5deg);
  }
}

/* Hairlines fading outward, gold where they meet the spark, thinning through
   --blue-300 to nothing. scaleX on hover extends them away from the label. */
.intro-gate-seam {
  position: relative;
  width: clamp(26px, 8vw, 118px);
  height: 1px;
  flex: 0 0 auto;
  transition:
    transform 260ms ease,
    opacity 260ms ease;
}

.intro-gate-seam--left {
  transform-origin: right center;
  background: linear-gradient(90deg, transparent, rgba(119, 168, 255, 0.18) 42%, rgba(255, 195, 34, 0.5));
}

.intro-gate-seam--right {
  transform-origin: left center;
  background: linear-gradient(270deg, transparent, rgba(119, 168, 255, 0.18) 42%, rgba(255, 195, 34, 0.5));
}

/* A point of light tracing each seam inward, previewing the same travelling
   dot the exit burst runs down every link. Two keyframe sets, because a
   percentage translateX would resolve against the 3px dot, not the seam. */
.intro-gate-seam::after {
  position: absolute;
  top: 50%;
  left: 0;
  width: 3px;
  height: 3px;
  margin-top: -1.5px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 6px rgba(119, 168, 255, 0.9);
  content: "";
  opacity: 0;
  animation: introSeamTrace 5.2s ease-in-out 2200ms infinite;
}

@keyframes introSeamTrace {
  0% {
    left: 0;
    opacity: 0;
  }
  12% {
    opacity: 0.85;
  }
  60% {
    left: 100%;
    opacity: 0.85;
  }
  72% {
    left: 100%;
    opacity: 0;
  }
  100% {
    left: 100%;
    opacity: 0;
  }
}

.intro-gate-seam--right::after {
  left: auto;
  right: 0;
  animation-name: introSeamTraceRight;
  animation-delay: -0.4s;
}

@keyframes introSeamTraceRight {
  0% {
    right: 0;
    opacity: 0;
  }
  12% {
    opacity: 0.85;
  }
  60% {
    right: 100%;
    opacity: 0.85;
  }
  72% {
    right: 100%;
    opacity: 0;
  }
  100% {
    right: 100%;
    opacity: 0;
  }
}

.intro-gate-enter:hover {
  color: #fff3c4;
}

.intro-gate-enter:hover .intro-gate-seam {
  transform: scaleX(1.18);
  opacity: 1;
}

.intro-gate-enter:hover .intro-gate-spark {
  filter: drop-shadow(0 0 10px rgba(255, 225, 118, 0.95));
}

.intro-gate-enter:active {
  color: var(--yellow-500);
}

/* Kept deliberately visible: it only shows for keyboard users, where the
   affordance outranks staying invisible. The gate focuses this button on load
   so assistive tech lands inside the dialog, and a ring painted by that
   programmatic focus would put the box back around the invitation, so the
   script marks that single focus as quiet. */
.intro-gate-enter:focus-visible:not(.is-quiet-focus) {
  border-radius: 4px;
  outline: 1px solid rgba(255, 225, 118, 0.7);
  outline-offset: 8px;
}

/* :focus-visible does match that programmatic focus, so the UA's own default
   ring has to be silenced explicitly as well, or it paints a blue box. */
.intro-gate-enter.is-quiet-focus:focus-visible {
  outline: none;
}

/* --------------------------------------------------------------------------
   Arrival choreography. Input stays live from frame zero, so an impatient
   visitor can skip straight past any of this.
   -------------------------------------------------------------------------- */

html.is-intro .intro-gate-kicker {
  animation: introRise 900ms cubic-bezier(0.16, 1, 0.3, 1) 150ms both;
}

/* Focus-pull rather than a plain fade: it is the arrival moment, and it also
   hides raster softness in the wordmark at large display sizes. */
html.is-intro .intro-gate-logo {
  animation: introFocusPull 1500ms cubic-bezier(0.16, 1, 0.3, 1) 620ms both;
}

/* Focus-pull again rather than a rise: the invitation should condense into
   focus like a star, not slide in like a card. With the instruction line gone
   this is the closing beat. */
html.is-intro .intro-gate-enter {
  animation: introFocusPull 1200ms cubic-bezier(0.16, 1, 0.3, 1) 1120ms both;
}

@keyframes introFocusPull {
  from {
    opacity: 0;
    filter: blur(14px);
    transform: scale(0.94);
  }
  to {
    opacity: 1;
    filter: blur(0);
    transform: scale(1);
  }
}

@keyframes introRise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --------------------------------------------------------------------------
   Departure: the canvas warps in tsuroya-intro.js while these run alongside.
   -------------------------------------------------------------------------- */

.intro-gate.is-leaving {
  will-change: opacity;
  animation: introFade 900ms ease 620ms both;
}

@keyframes introFade {
  to {
    opacity: 0;
  }
}

.intro-gate.is-leaving .intro-gate-core {
  animation: introCoreOut 820ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes introCoreOut {
  to {
    opacity: 0;
    filter: blur(9px);
    transform: scale(1.14);
  }
}

.intro-gate.is-leaving .intro-gate-bloom {
  will-change: transform, opacity;
  animation: introBloom 900ms cubic-bezier(0.16, 1, 0.3, 1) 120ms both;
}

@keyframes introBloom {
  0% {
    opacity: 0;
    transform: scale(0.28);
  }
  28% {
    opacity: 0.92;
  }
  100% {
    opacity: 0;
    transform: scale(2.3);
  }
}

/* --------------------------------------------------------------------------
   Small screens and short viewports
   -------------------------------------------------------------------------- */

@media (max-width: 760px) {
  .intro-gate-core {
    gap: 15px;
  }

  .intro-gate-kicker {
    font-size: 10px;
    letter-spacing: 0.2em;
  }

  /* Kept under the PNG's native width so the wordmark stays crisp at 3x. */
  .intro-gate-logo {
    width: min(70vw, 300px);
  }

  .intro-gate-enter {
    gap: 8px;
    font-size: 13px;
    letter-spacing: 0.05em;
  }

  .intro-gate-spark {
    width: 9px;
    height: 9px;
  }

  .intro-gate-seam {
    width: clamp(18px, 7vw, 56px);
  }
}

@media (max-height: 560px) {
  .intro-gate-core {
    gap: 12px;
  }

  .intro-gate-logo {
    width: min(46vw, 240px);
    max-height: 26vh;
  }

  .intro-gate-kicker {
    font-size: 10px;
  }

  .intro-gate-seam {
    width: clamp(18px, 6vw, 72px);
  }
}

@media (prefers-reduced-transparency: reduce) {
  .intro-gate-enter::before {
    background: radial-gradient(46% 62% at 50% 50%, rgba(2, 10, 29, 0.9), rgba(2, 10, 29, 0) 90%);
  }
}

@media (prefers-reduced-motion: reduce) {
  html.is-intro .intro-gate-kicker,
  html.is-intro .intro-gate-logo,
  html.is-intro .intro-gate-enter {
    opacity: 1;
    filter: none;
    transform: none;
    animation: none;
  }

  .intro-gate-nebula,
  .intro-gate-logo-wrap::before,
  .intro-gate-spark,
  .intro-gate-seam::after {
    animation: none;
  }

  .intro-gate-logo-wrap::before {
    opacity: 0.6;
  }

  .intro-gate.is-leaving {
    animation: introFade 260ms ease both;
  }

  .intro-gate.is-leaving .intro-gate-core,
  .intro-gate.is-leaving .intro-gate-bloom {
    animation: none;
  }
}
