/* =============================================================================
   Star Wars crawl — mechanics only (easter egg overlay)
   ============================================================================= */


body.crawl-active {
  overflow: hidden;
}

body.crawl-active .site-header,
body.crawl-active main,
body.crawl-active .site-footer,
body.crawl-active .starfield,
body.crawl-active .easter-egg-btn {
  visibility: hidden;
}

/* Full-screen black container */
.sw-crawl {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: none;
  height: 100vh;
  background: #000;
  overflow: hidden;
}

.sw-crawl[hidden] {
  display: none !important;
}

.sw-crawl.sw-crawl--active {
  display: block;
}

/* Starfield behind intro + crawl (must stay under text, above black void) */
.sw-crawl__stars {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.sw-crawl__stars .crawl-star {
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.35;
  animation: crawl-star-twinkle 3s ease-in-out infinite;
}

.sw-crawl__stars .crawl-star--bright {
  width: 3px;
  height: 3px;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.75);
}

@keyframes crawl-star-twinkle {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 0.85; }
}

/* Brighter twinkle while the crawl text is moving */
.sw-crawl--playing .sw-crawl__stars .crawl-star {
  animation-name: crawl-star-twinkle-bright;
}

.sw-crawl--playing .sw-crawl__stars .crawl-star--bright {
  box-shadow: 0 0 8px rgba(200, 220, 255, 0.9);
}

@keyframes crawl-star-twinkle-bright {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

/* --- Intro: blue tagline, then yellow title zooms toward viewer (Star Wars style) --- */
.sw-crawl__tagline,
.sw-crawl__logo {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  margin: 0;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.sw-crawl__tagline {
  width: min(88vw, 20em);
  transform: translate(-50%, -50%);
  font-family: var(--font-sans, "Source Sans 3", "Franklin Gothic Medium", "Arial", sans-serif);
  font-size: clamp(1.05rem, 2.8vw, 1.5rem);
  font-weight: 400;
  letter-spacing: 0.03em;
  line-height: 1.55;
  color: #4bd5ee;
  transition: opacity 0.9s ease, visibility 0.9s ease;
}

.sw-crawl__logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.12em;
  width: max-content;
  max-width: 92vw;
  margin: 0;
  transform: translate(-50%, -50%) scale(2.15);
  font-family: var(--font-display, "Barlow Condensed", sans-serif);
  font-size: clamp(3rem, 14vw, 6.5rem);
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 0.9;
  text-align: center;
  text-transform: uppercase;
}

/* Hollow yellow outline, transparent fill — like the film logo */
.sw-crawl__logo-line {
  display: block;
  color: transparent;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: clamp(2px, 0.42vw, 5px) #ffe81f;
  paint-order: stroke fill;
}

.sw-crawl--tagline .sw-crawl__tagline {
  opacity: 1;
  visibility: visible;
}

.sw-crawl--tagline .sw-crawl__logo {
  opacity: 0;
  visibility: hidden;
}

.sw-crawl--logo .sw-crawl__tagline {
  opacity: 0;
  visibility: hidden;
  transition-duration: 0.5s;
}

.sw-crawl--logo .sw-crawl__logo {
  opacity: 1;
  visibility: visible;
  animation: crawl-logo-recede 2s linear forwards;
}

@keyframes crawl-logo-recede {
  from {
    transform: translate(-50%, -50%) scale(2.15);
  }
  to {
    transform: translate(-50%, -50%) scale(0.36);
  }
}

.sw-crawl--playing .sw-crawl__tagline,
.sw-crawl--playing .sw-crawl__logo {
  opacity: 0;
  visibility: hidden;
  animation: none;
}

/*
 * Perspective parent
 * - Establishes 3D space; horizon sits at bottom center (like looking at a receding floor).
 */
.sw-crawl__perspective {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  /* Transparent so stars remain visible during crawl */
  background: transparent;
  perspective: 380px;
  perspective-origin: 50% 100%;
  transform-style: preserve-3d;
  opacity: 0;
  visibility: hidden;
}

.sw-crawl--playing .sw-crawl__perspective {
  opacity: 1;
  visibility: visible;
}

/*
 * Tilted plane (fixed) — scroll happens on .sw-crawl__track inside.
 */
.sw-crawl__crawl {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 75vw;
  max-width: none;
  transform: translateX(-50%) rotateX(22deg);
  transform-origin: 50% 100%;
}

/* Top of crawl sits just below the frame, then scrolls in immediately */
.sw-crawl__track {
  transform: translateY(calc(100% + 2vh));
  will-change: transform;
}

.sw-crawl--playing .sw-crawl__track {
  animation: crawl-depth 70s linear forwards;
}

@keyframes crawl-depth {
  from {
    transform: translateY(calc(100% + 2vh));
  }
  to {
    transform: translateY(calc(-100% - 150vh));
  }
}

/* Yellow bold copy — sized to fill ~3/4 of the viewport */
.sw-crawl__content {
  color: #ffe81f;
  font-family: var(--font-display, "Barlow Condensed", sans-serif);
  font-weight: 700;
  font-size: clamp(2.25rem, 5.25vw, 4.25rem);
  line-height: 1.45;
  letter-spacing: 0.02em;
  text-align: justify;
  padding-top: 6vh;
  padding-bottom: 25vh;
}

.sw-crawl__content h2 {
  font-size: clamp(3.25rem, 11vw, 7rem);
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.12em;
  margin-bottom: 2.5rem;
  line-height: 1.1;
}

/* Episode line (e.g. Episode I: …) — centered like the film crawl */
.sw-crawl__content h2 + p {
  text-align: center;
  letter-spacing: 0.06em;
}

.sw-crawl__content p {
  margin-bottom: 2.25rem;
}

.sw-crawl__content p:last-child {
  margin-bottom: 0;
}

/* Minimal skip control (keyboard: Esc or Space) */
.sw-crawl__skip {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 10;
  font-family: var(--font-sans, sans-serif);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
}

.sw-crawl__skip:hover,
.sw-crawl__skip:focus-visible {
  color: #ffe81f;
  outline: none;
}

/* Easter egg trigger on main site */
.easter-egg-btn {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 999;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--c-brand);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.35;
  transition: opacity 0.25s, transform 0.25s;
}

.easter-egg-btn:hover,
.easter-egg-btn:focus-visible {
  opacity: 1;
  transform: scale(1.08);
  outline: none;
}

@media (max-width: 640px) {
  .sw-crawl__crawl {
    width: 88vw;
  }

  .sw-crawl__content {
    font-size: clamp(1.65rem, 6.5vw, 2.75rem);
  }

  .sw-crawl__content h2 {
    font-size: clamp(2.25rem, 14vw, 4rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sw-crawl--playing .sw-crawl__track {
    animation-duration: 40s;
  }

  .sw-crawl--logo .sw-crawl__logo {
    animation: none;
    transform: translate(-50%, -50%) scale(1);
  }

  .sw-crawl__logo-line {
    -webkit-text-stroke-width: 2px;
  }
}
