/* Cosmos: scroll-driven star field behind the home page and the star finale.
   Loaded only on index.html, after styles.css. Driven by cosmos.js. */

/* ---------- Canvas layer ---------- */

.cosmos-canvas {
  display: none;
}

html.cosmos-ready .cosmos-canvas {
  position: fixed;
  z-index: -1;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100vh;
  height: 100lvh;
  pointer-events: none;
}

/* The body paints above negative z-index layers, so it must not hide the canvas.
   html keeps its black ground. */
html.cosmos-ready body {
  background: transparent;
}

/* Full-bleed opaque backgrounds that would cover the sky. */
html.cosmos-ready main {
  background: transparent;
  /* The blasting hero video scales past the screen edge; it must not widen the
     page (mobile browsers would zoom out to fit). clip keeps sticky/scroll intact. */
  overflow-x: clip;
}

html.cosmos-ready .site-footer {
  background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.55) 70%);
}

/* ---------- Black hole blast (--cosmos-blast: 0..1 on .hero-visual) ---------- */

html.cosmos-ready .hero-visual {
  --cosmos-blast: 0;
  /* The video's black frame must not cut a dark box out of the sky behind it. */
  mix-blend-mode: screen;
}

html.cosmos-ready .hero-visual .signal-core--video {
  opacity: clamp(0, calc(1.75 - var(--cosmos-blast) * 2.9), 1);
  transform: translateX(var(--signal-video-shift)) scale(calc(1 + var(--cosmos-blast) * 1.7));
  transition: none;
}

html.cosmos-ready .hero-visual .signal-core--video:hover,
html.cosmos-ready .hero-visual .signal-core--video:focus-within {
  transform: translateX(var(--signal-video-shift)) scale(calc(1.025 + var(--cosmos-blast) * 1.7));
}

html.cosmos-ready .hero-visual[data-cosmos-blasting] .signal-core--video {
  pointer-events: none;
}

/* Only while blasting: at rest the original filter from styles.css applies untouched. */
html.cosmos-ready .hero-visual[data-cosmos-blasting] .signal-core--video video {
  filter:
    contrast(1.7)
    brightness(calc(1.08 + var(--cosmos-blast) * 4.5))
    saturate(calc(1.04 + var(--cosmos-blast) * 0.8))
    blur(calc(var(--cosmos-blast) * 5px));
}

/* ---------- Finale ---------- */

.cosmos-finale {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(28px, 4vh, 48px);
  width: min(100% - var(--page-gutter), var(--page-max));
  min-height: 100vh;
  min-height: 100svh;
  margin: var(--section-stack-gap) auto 0;
  padding: clamp(88px, 12vh, 120px) 0 clamp(48px, 8vh, 88px);
  text-align: center;
}

.cosmos-finale h2 {
  max-width: 980px;
  margin: 0;
  color: var(--white);
  font-size: clamp(32px, 4.3vw, 60px);
  font-weight: 500;
  letter-spacing: 0;
  line-height: 0.98;
  text-shadow: 0 0 28px rgba(0, 0, 0, 0.85);
  text-wrap: balance;
}

.cta-starword {
  position: relative;
  display: grid;
  place-items: center;
  width: min(100%, 820px);
  aspect-ratio: 2.7 / 1;
}

.cta-starword-fallback {
  color: var(--heat-light);
  font-family: "Oswald", "Tilda Sans", Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(84px, 19vw, 250px);
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1;
  text-shadow:
    0 0 18px rgba(255, 243, 231, 0.45),
    0 0 48px rgba(255, 138, 31, 0.3);
}

html.cosmos-ready .cta-starword-fallback {
  visibility: hidden;
}

/* ---------- «Начать»: a button that glows like a star ---------- */

.star-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: clamp(220px, 20vw, 272px);
  height: 58px;
  padding: 0 40px;
  border: 1px solid rgba(255, 243, 231, 0.82);
  border-radius: var(--radius-control, 10px);
  background:
    radial-gradient(120% 140% at 50% 0%, rgba(255, 243, 231, 0.2), transparent 70%),
    rgba(14, 8, 4, 0.72);
  color: var(--white);
  font-family: "Oswald", "Tilda Sans", Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 19px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-decoration: none;
  text-transform: uppercase;
  text-shadow: 0 0 12px rgba(255, 243, 231, 0.75);
  box-shadow:
    0 0 0 1px rgba(255, 138, 31, 0.22),
    0 0 12px rgba(255, 243, 231, 0.35),
    inset 0 0 16px rgba(255, 243, 231, 0.14);
  transition:
    border-color 0.3s ease,
    background-color 0.3s ease,
    box-shadow 0.3s ease;
}

/* Halo: a separate layer so the pulse animates opacity, not box-shadow. */
.star-button::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  pointer-events: none;
  box-shadow:
    0 0 18px rgba(255, 243, 231, 0.55),
    0 0 42px rgba(255, 138, 31, 0.42),
    0 0 96px rgba(255, 47, 31, 0.22);
  opacity: 0.6;
  animation: star-button-pulse 3.4s ease-in-out infinite;
}

/* Four-point spark twinkling at the top-right corner. */
.star-button::after {
  content: "";
  position: absolute;
  top: -15px;
  right: -15px;
  width: 30px;
  height: 30px;
  pointer-events: none;
  background:
    radial-gradient(circle, #fff 0 9%, rgba(255, 243, 231, 0.85) 16%, rgba(255, 138, 31, 0.28) 30%, transparent 46%),
    linear-gradient(90deg, transparent 0%, rgba(255, 243, 231, 0.95) 50%, transparent 100%) center / 100% 2px no-repeat,
    linear-gradient(180deg, transparent 0%, rgba(255, 243, 231, 0.95) 50%, transparent 100%) center / 2px 100% no-repeat;
  filter: drop-shadow(0 0 4px rgba(255, 186, 120, 0.9));
  animation: star-button-twinkle 2.6s ease-in-out infinite;
}

.star-button-label {
  position: relative;
}

.star-button:hover {
  border-color: #fff;
  background-color: rgba(34, 18, 8, 0.78);
  box-shadow:
    0 0 0 1px rgba(255, 138, 31, 0.4),
    0 0 20px rgba(255, 243, 231, 0.6),
    inset 0 0 22px rgba(255, 243, 231, 0.24);
}

.star-button:hover::before {
  opacity: 1;
  animation-duration: 1.8s;
}

.star-button:focus-visible {
  outline: 2px solid var(--heat-light);
  outline-offset: 6px;
}

@keyframes star-button-pulse {
  0%,
  100% {
    opacity: 0.55;
  }

  50% {
    opacity: 1;
  }
}

@keyframes star-button-twinkle {
  0%,
  100% {
    opacity: 0.55;
    transform: scale(0.6) rotate(0deg);
  }

  45% {
    opacity: 1;
    transform: scale(1.12) rotate(45deg);
  }

  60% {
    opacity: 0.9;
    transform: scale(0.95) rotate(45deg);
  }
}

@media (max-width: 560px) {
  .cosmos-finale {
    width: min(100% - (var(--page-gutter-mobile) * 2), var(--page-max));
  }

  .star-button {
    width: 100%;
    max-width: 320px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .star-button::before {
    opacity: 0.85;
    animation: none;
  }

  .star-button::after {
    opacity: 0.9;
    transform: rotate(45deg);
    animation: none;
  }
}

html.cosmos-reduced .star-button::before {
  opacity: 0.85;
  animation: none;
}

html.cosmos-reduced .star-button::after {
  opacity: 0.9;
  transform: rotate(45deg);
  animation: none;
}

/* ---------- Debug overlay (?cosmos-debug) ---------- */

.cosmos-debug {
  position: fixed;
  z-index: 40;
  left: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.78);
  color: #9cff9c;
  font: 12px/1.4 ui-monospace, Consolas, monospace;
  white-space: pre;
  pointer-events: none;
}
