/**
 * @file
 * EU Space Programme Visualization Component
 *
 * Mobile-first responsive styles for the interactive visualization.
 * Uses theme CSS custom properties where possible (--eusp-color-*).
 * For rgba() with transparency, colors are documented to map to theme tokens.
 *
 * Theme color reference:
 * - primary-500: #4a2bd6 = rgb(74, 43, 214)
 * - primary-400: #4a2bd6 = rgb(74, 43, 214)
 * - grey-80: #2a293b = rgb(42, 41, 59)
 * - grey-40: #dee2e6 = rgb(222, 226, 230)
 * - white: #fff = rgb(255, 255, 255)
 *
 * Breakpoints:
 * - Mobile: < 768px (default)
 * - Tablet: 768px - 799px
 * - Desktop: 800px+
 */

/* ==========================================================================
   Full-Width Background on Paragraph Wrapper
   ========================================================================== */

.eusp-layout-paragraph:has(.block-defis-space-program-visualization) {
  --eusp-bg-full-w-gradient: var(--eusp-gradient-dark);
  margin-block: 0 !important;
}

/* ==========================================================================
   Main Container
   ========================================================================== */

.eusp-viz {
  position: relative;
  width: 100%;
  margin: 0;
  padding: 1rem;
  background: transparent;
  overflow: hidden;
}

@media (min-width: 768px) {
  .eusp-viz {
    padding-bottom: 2rem;
  }
}

@media (min-width: 800px) {
  .eusp-viz {
    padding-bottom: 3rem;
  }
}

/* ==========================================================================
   Canvas Area (Earth + Orbits)
   ========================================================================== */

.eusp-viz__canvas {
  position: relative;
  width: 100%;
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2rem;
  isolation: isolate;
  overflow: hidden;
  padding: 2rem 1rem;
}

@media (min-width: 768px) {
  .eusp-viz__canvas {
    min-height: 65vh;
    margin-bottom: 2.5rem;
    padding: 3rem 2rem;
  }
}

@media (min-width: 800px) {
  .eusp-viz__canvas {
    /* Ensure canvas is tall enough: last tile top (36.5rem) + tile height (5rem) + padding = ~44rem minimum */
    min-height: max(80vh, 44rem);
    margin-bottom: 3rem;
    padding: 4rem;
  }
}

/* ==========================================================================
   Earth Video
   ========================================================================== */

.eusp-viz__earth {
  position: relative;
  width: 50vmin;
  height: 50vmin;
  max-width: 400px;
  max-height: 400px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(74, 43, 214, 0.5); /* primary-500 @ 50% opacity */
  z-index: 2;
  margin: 0;
  flex-shrink: 0;
}

@media (min-width: 768px) {
  .eusp-viz__earth {
    width: 45vmin;
    height: 45vmin;
    max-width: 480px;
    max-height: 480px;
  }
}

@media (min-width: 800px) {
  .eusp-viz__earth {
    width: 50vmin;
    height: 50vmin;
    max-width: 712px;
    max-height: 712px;
  }
}

.eusp-viz__earth-video {
  width: 120%;
  height: 120%;
  object-fit: cover;
  object-position: center center;
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* ==========================================================================
   Orbital Ring
   ========================================================================== */

.eusp-viz__orbit-ring {
  position: absolute;
  width: calc(50vmin * 1.35);
  height: calc(50vmin * 1.35);
  max-width: calc(400px * 1.35);
  max-height: calc(400px * 1.35);
  border-radius: 50%;
  border: 1px solid rgba(102, 126, 234, 0.3); /* approx primary-400 @ 30% opacity */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  pointer-events: none;
}

@media (min-width: 768px) {
  .eusp-viz__orbit-ring {
    width: calc(45vmin * 1.35);
    height: calc(45vmin * 1.35);
    max-width: calc(480px * 1.35);
    max-height: calc(480px * 1.35);
  }
}

@media (min-width: 800px) {
  .eusp-viz__orbit-ring {
    width: calc(50vmin * 1.35);
    height: calc(50vmin * 1.35);
    max-width: calc(712px * 1.35);
    max-height: calc(712px * 1.35);
  }
}

/* ==========================================================================
   Animated Woosh Lines
   ========================================================================== */

.eusp-viz__woosh-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  overflow: visible;
}

.eusp-viz .woosh-line-group {
  transform-origin: 50% 50%;
}

.eusp-viz .woosh-line {
  opacity: 0;
  transform-origin: 50% 50%;
  will-change: transform, opacity;
}

/* Pause animations when visualization is off-screen */
.eusp-viz--paused .woosh-line {
  animation-play-state: paused !important;
}

.eusp-viz--paused .eusp-viz__satellite {
  animation-play-state: paused !important;
}

/* Intermittent animation - bursts with pauses */
/* Lines go from BOTTOM-RIGHT upward to TOP-LEFT */
@keyframes woosh-burst {
  0% {
    transform: translateX(150%) translateY(150%);
    opacity: 0;
  }
  5% {
    opacity: 1;
  }
  30% {
    opacity: 1;
  }
  35% {
    transform: translateX(-150%) translateY(-150%);
    opacity: 0;
  }
  100% {
    transform: translateX(-150%) translateY(-150%);
    opacity: 0;
  }
}

/* Different speeds for each line - white is fastest at 18s */
.eusp-viz .woosh-line--white {
  animation: woosh-burst 18s ease-in-out infinite;
  animation-delay: 0s;
}

.eusp-viz .woosh-line--green {
  animation: woosh-burst 20s ease-in-out infinite;
  animation-delay: 0.3s;
}

.eusp-viz .woosh-line--blue {
  animation: woosh-burst 22s ease-in-out infinite;
  animation-delay: 0.6s;
}

.eusp-viz .woosh-line--white-2 {
  animation: woosh-burst 24s ease-in-out infinite;
  animation-delay: 0.9s;
}

.eusp-viz .woosh-line--orange {
  animation: woosh-burst 26s ease-in-out infinite;
  animation-delay: 1.2s;
}

.eusp-viz .woosh-line--dark-blue {
  animation: woosh-burst 28s ease-in-out infinite;
  animation-delay: 1.5s;
}

.eusp-viz .woosh-line--light-blue {
  animation: woosh-burst 30s ease-in-out infinite;
  animation-delay: 1.8s;
}

.eusp-viz .woosh-line--dark-red {
  animation: woosh-burst 32s ease-in-out infinite;
  animation-delay: 2.1s;
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  .eusp-viz .woosh-line {
    animation: none !important;
    opacity: 0 !important;
  }
}

/* ==========================================================================
   Component Bubbles (Upper Half)
   ========================================================================== */

.eusp-viz__components {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  overflow: hidden;
}

/* Mobile: Hide Earth/satellites, show tiles stacked vertically */
@media (max-width: 799px) {
  /* Hide Earth video */
  .eusp-viz__earth {
    display: none;
  }

  /* Hide woosh lines */
  .eusp-viz__woosh-lines {
    display: none;
  }

  /* Hide orbital ring */
  .eusp-viz__orbit-ring {
    display: none;
  }

  /* Hide satellites */
  .eusp-viz__satellites {
    display: none;
  }

  /* Remove canvas height constraints and let content flow naturally */
  .eusp-viz__canvas {
    min-height: 0;
    height: auto;
    padding: 0;
    margin-bottom: 1rem;
    display: block;
    overflow: visible;
  }

  /* Make components container relative so it contributes to height */
  .eusp-viz__components {
    position: relative;
    inset: auto;
    overflow: visible;
    height: auto;
  }

  /* Ensure components container expands with flexbox content */
  .eusp-viz__components-container {
    position: relative;
    min-height: auto;
  }

  /* Remove negative margin on CTA wrapper to prevent overlap with tiles on mobile */
  .eusp-viz__cta-wrapper {
    margin-top: 2rem !important;
    padding: 2rem 1rem 1.5rem !important;
  }

  /* Ensure tiles are above CTA blocks */
  .eusp-viz__component {
    z-index: 5;
  }

  .eusp-viz__components-container {
    margin-bottom: 2rem;
  }
}

.eusp-viz__components-container {
  position: relative;
  width: 100%;
  padding: 1rem;
  padding-bottom: 2rem;
}

/* Mobile: Stack tiles vertically with specific order */
@media (max-width: 799px) {
  .eusp-viz__components-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 2rem 1rem;
  }

  .eusp-viz__component {
    position: relative !important;
    width: 90% !important;
    max-width: none !important;
    margin: 0 auto;
  }

  /* Make component link and circle fill the container width */
  .eusp-viz__component-link {
    width: 100% !important;
  }

  .eusp-viz__component-circle {
    width: 100% !important;
    min-width: 0 !important;
  }

  /* Order tiles: left - right - left - right - remaining */
  /* left-top = 1 */
  .eusp-viz__component--left-top {
    order: 1;
  }

  /* right-top = 2 */
  .eusp-viz__component--right-top {
    order: 2;
  }

  /* left-bottom = 3 */
  .eusp-viz__component--left-bottom {
    order: 3;
  }

  /* right-bottom = 4 */
  .eusp-viz__component--right-bottom {
    order: 4;
  }

  /* left-secondary-top = 5 */
  .eusp-viz__component--left-secondary-top {
    order: 5;
  }

  /* left-secondary-bottom = 6 */
  .eusp-viz__component--left-secondary-bottom {
    order: 6;
  }

  /* right-secondary-bottom = 7 */
  .eusp-viz__component--right-secondary-bottom {
    order: 7;
  }
}

/* Desktop: 800px+ (absolute positioning for tiles) */
@media (min-width: 800px) {
  .eusp-viz__components-container {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    pointer-events: none;
  }

  .eusp-viz__component {
    pointer-events: auto;
  }
}

.eusp-viz__component {
  position: relative;
  pointer-events: auto;
  width: 100%;
  height: auto;
}

@media (min-width: 800px) {
  .eusp-viz__component {
    position: absolute !important;
    width: auto !important;
    height: auto !important;
  }

  /* Tile height constants:
   * - Primary tiles: ~200px (~12.5rem)
   * - Secondary tiles: ~75px (~5rem)
   * - Gap between tiles: 1.5rem
   */

  /* Row 1: Top tiles - start at 2rem */
  .eusp-viz__component--left-top {
    top: 2rem !important;
    left: max(1rem, 3vw) !important;
  }

  .eusp-viz__component--right-top {
    top: 2rem !important;
    right: max(1rem, 3vw) !important;
  }

  /* Row 2: After primary tile (~12.5rem) + gap (1.5rem) = 16rem minimum */
  .eusp-viz__component--left-bottom {
    top: max(16rem, 20svh) !important;
    left: max(1rem, 3vw) !important;
  }

  .eusp-viz__component--right-bottom {
    top: max(16rem, 20svh) !important;
    right: max(1rem, 3vw) !important;
  }

  /* Row 3: After 2 primary tiles (2 * 14rem) + start (2rem) = 30rem minimum */
  .eusp-viz__component--left-secondary-top {
    top: max(30rem, 35svh) !important;
    left: max(1rem, 3vw) !important;
  }

  /* Row 4: After row 3 secondary (~5rem) + gap (1.5rem) = 36.5rem minimum */
  .eusp-viz__component--left-secondary-bottom {
    top: max(36.5rem, 43svh) !important;
    left: max(1rem, 3vw) !important;
  }

  /* Right secondary: positioned between row 2 and row 3 levels */
  .eusp-viz__component--right-secondary-bottom {
    top: max(33rem, 40svh) !important;
    right: max(1rem, 3vw) !important;
    left: auto !important;
  }
}

.eusp-viz__component-link {
  text-decoration: none;
  display: block;
}

.eusp-viz__component-circle {
  width: 200px;
  min-height: 150px;
  border-radius: 0.75rem;
  position: relative;
  background: rgba(42, 41, 59, 0.8); /* grey-80 @ 80% */
  border: 1px solid var(--eusp-color-primary-500);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  text-align: left;
  padding: 1.5rem;
  transition: all 0.3s ease;
  overflow: hidden;
  pointer-events: auto;
}

.eusp-viz__component-circle::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(102, 126, 234, 0.6),
    rgba(102, 126, 234, 0.9),
    rgba(102, 126, 234, 0.6),
    transparent
  ); /* approx primary-400 gradient */
  box-shadow: 0 0 10px rgba(102, 126, 234, 0.5); /* approx primary-400 @ 50% */
  animation: shimmer 5s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

@media (min-width: 768px) {
  .eusp-viz__component-circle {
    width: 240px;
    min-height: 180px;
  }
}

@media (min-width: 800px) {
  .eusp-viz__component-circle {
    width: 300px;
    min-height: 200px;
  }
}

.eusp-viz__component-link:hover .eusp-viz__component-circle {
  box-shadow: 0 4px 12px rgba(74, 43, 214, 0.4); /* primary-500 @ 40% */
  border-color: var(--eusp-color-primary-400);
  transform: translateY(-2px);
}

.eusp-viz__component--secondary .eusp-viz__component-circle {
  width: 180px;
  min-height: 65px;
  background: rgba(42, 41, 59, 0.5); /* grey-80 @ 50% */
  border: 1px dashed var(--eusp-color-primary-500);
  opacity: 0.85;
  padding: 1rem;
}

.eusp-viz__component--secondary .eusp-viz__component-circle::before {
  display: none;
}

@media (min-width: 768px) {
  .eusp-viz__component--secondary .eusp-viz__component-circle {
    width: 200px;
    min-height: 70px;
  }
}

@media (min-width: 800px) {
  .eusp-viz__component--secondary .eusp-viz__component-circle {
    width: 300px;
    min-height: 75px;
  }
}

.eusp-viz__component--secondary .eusp-viz__component-title {
  font-size: clamp(0.875rem, 0.8rem + 0.375vw, 1rem);
  margin-bottom: 0.25rem;
}

.eusp-viz__component--secondary .eusp-viz__component-description {
  font-size: clamp(0.65rem, 0.6rem + 0.25vw, 0.75rem);
  margin-top: 0;
  white-space: nowrap;
}

.eusp-viz__component-title {
  color: var(--eusp-color-white);
  margin: 0 0 1rem 0;
  position: relative;
  z-index: 3;
  font-size: clamp(1.15rem, 1.035rem + 0.575vw, 1.294rem);
  font-family: "Arial Black", sans-serif;
  font-weight: 900;
  transition: text-decoration 0.3s ease;
}

.eusp-viz__component--secondary .eusp-viz__component-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.eusp-viz__component-arrow {
  color: var(--eusp-color-primary-400);
  font-size: 1.3em;
  font-weight: normal;
  transition: transform 0.3s ease;
  flex-shrink: 0;
  margin-left: auto;
  padding-left: 0.75rem;
}

.eusp-viz__component-link:hover .eusp-viz__component-arrow {
  transform: translateX(4px);
}

.eusp-viz__component-arrow-bottom {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  color: var(--eusp-color-primary-400);
  font-size: 1.3em;
  font-weight: normal;
  transition: transform 0.3s ease;
  pointer-events: none;
}

.eusp-viz__component-link:hover .eusp-viz__component-arrow-bottom {
  transform: translateX(4px);
}

.eusp-viz__component:not(.eusp-viz__component--secondary)
  .eusp-viz__component-link:hover
  .eusp-viz__component-title {
  text-decoration: underline;
  text-decoration-color: var(--eusp-color-primary-500);
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

.eusp-viz__component-spikes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: auto;
}

.eusp-viz [data-component="space-security"] .eusp-viz__component-spikes {
  flex-direction: column;
  align-items: flex-start;
}

.eusp-viz [data-component="space-security"] .eusp-viz__spike-pill {
  margin-bottom: 0.25rem;
}

.eusp-viz [data-component="space-security"] .eusp-viz__spike-pill:last-child {
  margin-bottom: 0;
}

.eusp-viz__spike-pill {
  display: inline-block;
  padding: 0.375rem 0.75rem;
  background: rgba(74, 43, 214, 0.2); /* primary-500 @ 20% */
  border: 1px solid var(--eusp-color-primary-500);
  border-radius: 1rem;
  color: var(--eusp-color-white);
  font-size: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  text-decoration: none;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.eusp-viz__spike-pill:hover {
  background: var(--eusp-color-primary-500);
  color: var(--eusp-color-white);
  transform: translateY(-1px);
}

.eusp-viz__spike-pill--child {
  margin-left: 1rem;
  font-size: 0.75rem;
  padding: 0.25rem 0.625rem;
  background: rgba(74, 43, 214, 0.1);
}

.eusp-viz__component-description {
  color: var(--eusp-color-grey-40);
  font-size: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  line-height: 1.4;
  margin-top: 0.75rem;
}

@media (prefers-reduced-motion: reduce) {
  .eusp-viz__component-circle {
    animation: none !important;
  }

  .eusp-viz__component-circle::before {
    animation: none !important;
  }
}

/* ==========================================================================
   Animated Satellites
   ========================================================================== */

.eusp-viz__satellites {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}

.eusp-viz__satellite {
  position: absolute;
  width: 30px;
  height: 30px;
  top: 50%;
  left: 50%;
  transform-origin: center;
}

@media (min-width: 768px) {
  .eusp-viz__satellite {
    width: 40px;
    height: 40px;
  }
}

@media (min-width: 800px) {
  .eusp-viz__satellite {
    width: 50px;
    height: 50px;
  }
}

.eusp-viz__satellite-icon {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 10px rgba(74, 43, 214, 0.6)); /* primary-500 @ 60% */
}

@media (prefers-reduced-motion: reduce) {
  .eusp-viz__satellite {
    animation: none !important;
  }
}

/* ==========================================================================
   Call-to-Action Blocks
   ========================================================================== */

/* Wrapper with dotted border around CTA blocks */
.eusp-viz__cta-wrapper {
  position: relative;
  border: 1px dotted var(--ecl-color-primary-140);
  border-radius: 1rem;
  padding: 2.5rem 1.5rem 2rem;
  margin-top: -3rem;
  background: rgba(10, 9, 23, 0.3); /* Subtle dark background */
  backdrop-filter: blur(5px);
}

/* "Get involved" label positioned on top border */
.eusp-viz__cta-label {
  position: absolute;
  top: -1.1rem;
  left: 50%;
  transform: translateX(-50%);
  /* background: var(--eusp-color-grey-90); */
  color: var(--eusp-color-primary-100);
  padding: 0.25rem 1.5rem;
  font-size: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  font-family: "Arial Black", sans-serif;
  font-weight: 900;
  letter-spacing: 0.05em;
  /* border: 1px dotted var(--ecl-color-primary-140); */
  border-radius: 0.5rem;
  z-index: 2;
}

.eusp-viz__cta-blocks {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  z-index: 1; /* Keep below sticky menu (9999) */
}

@media (min-width: 768px) {
  .eusp-viz__cta-wrapper {
    padding: 3rem 2rem 2.5rem;
  }

  .eusp-viz__cta-blocks {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
  }
}

@media (min-width: 800px) {
  .eusp-viz__cta-wrapper {
    padding: 1rem 1rem 1rem;
    /* No negative margin on low height screens - container grows, users scroll */
    margin-top: 2rem;
  }

  .eusp-viz__cta-blocks {
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
  }
}

/* Only apply negative margin overlap on tall screens where there's enough space */
@media (min-width: 800px) and (min-height: 1000px) {
  .eusp-viz__cta-wrapper {
    margin-top: -20rem;
  }
}

.eusp-viz__cta-link {
  text-decoration: none;
  display: flex; /* Use flexbox to stretch the inner block */
  height: 100%; /* Fill the grid cell height */
}

.eusp-viz__cta {
  background: rgba(
    42,
    41,
    59,
    0.5
  ); /* grey-80 @ 50% - matches secondary tiles */
  border: 1px dashed var(--eusp-color-primary-500); /* Dashed border to match secondary tiles */
  border-radius: 0.75rem; /* Match component tiles */
  padding: 1.5rem;
  text-align: left; /* Left-align like secondary tiles */
  opacity: 0.85; /* Match secondary tiles */
  transition: all 0.3s ease;
  backdrop-filter: blur(10px); /* Add blur effect like main tiles */
  display: flex; /* Use flexbox for content layout */
  flex-direction: column; /* Stack title and description vertically */
  width: 100%; /* Fill the link width */
}

.eusp-viz__cta-link:hover .eusp-viz__cta {
  transform: translateY(-2px); /* Subtle hover like secondary tiles */
  box-shadow: 0 4px 12px rgba(74, 43, 214, 0.4); /* primary-500 @ 40% */
  border-color: var(--eusp-color-primary-400);
}

.eusp-viz__cta-title {
  color: var(--eusp-color-white);
  font-size: clamp(
    1.15rem,
    1.035rem + 0.575vw,
    1.294rem
  ); /* Match secondary title size */
  font-family: "Arial Black", sans-serif;
  font-weight: 900;
  line-height: 1.2;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.eusp-viz__cta-arrow {
  color: var(--eusp-color-primary-400);
  font-size: 1.3em;
  font-weight: normal;
  transition: transform 0.3s ease;
  flex-shrink: 0;
  margin-left: auto;
  padding-left: 0.75rem;
}

.eusp-viz__cta-link:hover .eusp-viz__cta-arrow {
  transform: translateX(4px);
}

.eusp-viz__cta-description {
  color: var(--eusp-color-grey-40);
  font-size: clamp(
    0.75rem,
    0.7rem + 0.25vw,
    0.875rem
  ); /* Match component description size */
  line-height: 1.4;
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

.eusp-viz a:focus,
.eusp-viz__cta-link:focus {
  outline: 2px solid var(--eusp-color-primary-500);
  outline-offset: 4px;
}
