/*———— CSS CUSTOM PROPERTIES ————*/
:root {
  --header-height: 6.25rem;
  --hero-start-height: 100vh;
  /* Show content after ~70% of a viewport instead of the full 100% */
  --animation-scroll-range: 70vh;
  
  /* Initialize animation properties to prevent undefined behavior */
  --hero-bg-opacity: 0;
  --hero-justify: center;
  --hero-align: center;
  --hero-padding: 0 2rem;
  --content-opacity: 0;
  --nav-opacity: 0;
  --wiggle-amplitude: 1;
  --wordmark-opacity: 1;
}

/*———— LAYOUT CONTAINERS ————*/
.fixed-hero-container {
  /* This container becomes sticky after scroll, contains the transforming content */
  position: sticky;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  z-index: 0;
  overflow: hidden;
  
  /* GPU acceleration magic */
  will-change: transform;
  contain: layout;
  transform: translate3d(0, 0, 0); /* Force hardware acceleration */
  isolation: isolate; /* Create new stacking context */
  backface-visibility: hidden; /* GPU optimization */
}

.scroll-container {
  /* This provides scroll distance for the animation - no longer removed by JS */
  height: var(--animation-scroll-range);
  min-height: 480px;          /* optional guard for tiny phones */
  width: 100%;
}

.main-content {
  /* The actual page content, positioned naturally in document flow */
  background: transparent;
  position: relative;
  z-index: 1;
  padding: 2rem 1rem 4rem;
  min-height: 100vh;
  /* Opacity controlled by CSS custom property */
  opacity: var(--content-opacity, 0);
  transition: opacity 0.2s ease-out;
  
  /* GPU acceleration for smooth content fade */
  will-change: opacity;
  transform: translate3d(0, 0, 0); /* Hardware acceleration */
  contain: layout paint; /* Isolate content rendering */
  
  /* MW-3: Skip layout until content is visible/needed */
  content-visibility: auto;
  contain-intrinsic-size: 100vh; /* Provide hint for size calculation */
  
  /* QW-4: Disable pointer events when faded out for performance - handled by JS */
}

/*———— HERO ELEMENT ————*/
.main-hero {
  height: 100%;
  display: flex;
  justify-content: var(--hero-justify, center);
  align-items: var(--hero-align, center);
  padding: var(--hero-padding, 0 2rem);
  position: relative; /* For pseudo-element positioning */
}

.main-hero::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(10, 10, 10, 1);
  opacity: var(--hero-bg-opacity, 0);
  transition: opacity 0.1s ease-out;
  pointer-events: none; /* Allow clicks to pass through */
}

.hero-container {
  /* Container that allows both centered and grid-aligned content */
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Fix-GLOW-1: let shadows extend */
  overflow: visible;
}

/* Wordmark stays independently centered */
.animated-wordmark {
  font-family: "Roboto Flex", sans-serif;
  transition: all 0.1s ease-out;
  z-index: 2000; /* Always above header */
  position: relative;
  
  /* GPU acceleration for font variations */
  will-change: font-variation-settings, font-size, transform;
  transform: translate3d(0, 0, 0); /* Hardware acceleration */
  contain: layout style; /* Fix 1a: Remove paint contain to prevent glow clipping */
  overflow: visible; /* Fix 1b: Allow glow to extend beyond bounds */
  white-space: nowrap; /* Fix 2a: Prevent text wrapping on narrow viewports */
  backface-visibility: hidden; /* Prevent texture thrashing */
  isolation: isolate; /* New compositing layer */
}

/* Fixed header navigation - always at top, no layout impact */
.header-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 80px; /* Fixed header height */
  
  /* Use same responsive container as episode list */
  max-width: 393px;
  margin: 0 auto;
  padding: 0 22px;
  box-sizing: border-box;
  
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  column-gap: 14px;
  align-items: center;
  
  opacity: var(--nav-opacity, 0);
  transition: opacity 0.2s ease-out;
  z-index: 1000;
  
  /* QW-4: Disable pointer events when faded out for performance - handled by JS */
}

/* Responsive Display Logic */
.header-nav--desktop {
  display: none; /* Hidden by default on mobile */
}

.header-nav--mobile {
  display: block; /* Change to block for vertical layout */
  height: 200px; /* Taller header to accommodate dots + wordmark */
  min-height: 200px; /* Ensure sufficient space */
}

/* Individual navigation item positioning - XS (8 columns) */
.header-nav--catalog {
  grid-column: 1 / 3; /* Cols 1-2 */
}

.header-nav--listen {
  grid-column: 4 / 6; /* Cols 4-5 */
}

.header-nav--connect {
  grid-column: 7 / 9; /* Cols 7-8 (3-4 from end) - original plan */
}

.header-nav--theme-toggle {
  grid-column: 8 / 9; /* Col 8 (end position) */
  justify-self: end;
}

/* Absolutely position wordmark anchor relative to header */
#wordmark-anchor {
  position: absolute;
  display: inline-block;       /* makes height/width take effect */
  font: 600 clamp(3rem, 5vw, 6rem)/1 "Roboto Flex", sans-serif; /* medium viewport-based sizing */
  letter-spacing: 0.1em;       /* matches animated wordmark */
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%); /* center both horizontally and vertically */
  opacity: 0;                  /* still invisible placeholder */
  filter: drop-shadow(0 0 8px transparent); /* invisible but counted - matches hero glow */
}

.header-nav-item {
  font-family: "Space Mono", monospace;
  font-size: 10px; /* Match XS episode metadata */
  font-style: normal;
  font-weight: 400;
  line-height: normal;
  letter-spacing: 0.7px; /* Match episode metadata */
  text-transform: uppercase;
  text-decoration: none;
  color: var(--text-level3);
  transition: color 0.2s ease;
}

.header-nav-item:hover,
.header-nav-item.is-active {
  color: var(--text-color);
}

/* Mobile header positioning above existing wordmark (XS/SM) */
.header-nav--mobile {
  z-index: 2000; /* Above the hero container */
}

.mobile-header-content {
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  top: 3rem; /* Position dots at top with padding */
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
}

.header-nav--hamburger {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
}

.hamburger-dots {
  display: flex;
  gap: 3px;
  align-items: center;
}

.hamburger-dots .dot {
  width: 4px;
  height: 4px;
  background: var(--text-color);
  border-radius: 50%;
}

/* Mobile Menu Modal */
.mobile-menu-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.mobile-menu-modal.is-open {
  opacity: 1;
  visibility: visible;
}

.mobile-menu-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3); /* Less dark so content shows through */
  backdrop-filter: blur(10px);
}

.mobile-menu-content {
  position: relative;
  background: var(--bg-color);
  display: flex;
  flex-direction: column;
  padding: 0; /* Remove padding - let container handle it */
  z-index: 1;
  justify-content: flex-start;
}

.mobile-menu-header {
  /* Use exact same container system as episode-list-container */
  width: 100%;
  max-width: 393px;
  margin: 0 auto;
  padding: 22px 22px 0 22px; /* Only top padding differs */
  box-sizing: border-box;
  
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  column-gap: 14px;
  align-items: center;
}

.mobile-menu--back {
  grid-column: 1 / 2;
  justify-self: start;
}

.mobile-menu-wordmark {
  grid-column: 2 / 8;
  text-align: center;
}

.mobile-menu--close {
  grid-column: 8 / 9;
  justify-self: end;
  z-index: 10; /* Ensure it's above other elements */
}

.mobile-wordmark-text {
  font-family: "Roboto Flex", sans-serif;
  font-size: clamp(1.5rem, 4vw, 2rem); /* Match main header style */
  font-weight: 400;
  color: var(--text-color);
  letter-spacing: 0.1em;
}

.mobile-menu--back,
.mobile-menu--close {
  font-family: "Space Mono", monospace;
  font-size: 16px;
  color: var(--text-level3);
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  transition: color 0.2s ease;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-menu--close:hover,
.mobile-menu--back:hover {
  color: var(--text-level1);
}

.mobile-menu-nav {
  /* Use exact same container system as episode-list-container */
  width: 100%;
  max-width: 393px;
  margin: 0 auto;
  padding: 0 22px;
  box-sizing: border-box;
  
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.mobile-menu-item {
  font-family: "Space Mono", monospace;
  font-size: 11px;
  font-weight: 400; /* Regular weight like metadata */
  font-style: normal; /* No italic */
  text-transform: uppercase;
  letter-spacing: 0.07em;
  line-height: 1.4;
  margin-bottom: 24px;
  text-decoration: none;
  color: var(--text-level3);
  background: none;
  border: none;
  cursor: pointer;
  text-align: center; /* Center align */
  padding: 0;
  transition: color 0.2s ease;
  display: block;
  width: 100%;
}

.mobile-menu-subitem {
  font-family: "Space Mono", monospace;
  font-size: 11px;
  font-weight: 400;
  font-style: normal;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  line-height: 1.4;
  margin-bottom: 20px;
  text-decoration: none;
  color: var(--text-level3);
  transition: color 0.2s ease;
  display: block;
  text-align: center;
}

.mobile-menu-item:hover,
.mobile-menu-subitem:hover {
  color: var(--text-level1);
  transition: color 0.2s ease;
}

.mobile-menu-item.is-active,
.mobile-menu-subitem.is-active {
  color: var(--text-level1);
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* Theme toggle now in nav, styled as small dot */
.mobile-menu-nav .mobile-menu--theme {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-level3);
  border: none;
  cursor: pointer;
  transition: background 0.2s ease;
  margin-top: 12px;
}

.mobile-menu-nav .mobile-menu--theme svg {
  display: none; /* Hide the sun/moon icons, just show dot */
}

.mobile-menu-nav .mobile-menu--theme:hover {
  background: var(--text-level1);
}

/* Sub-menu functionality */
.mobile-menu-submenu {
  opacity: 0;
  visibility: hidden;
  max-height: 0;
  overflow: hidden;
  transition: all 0.3s ease;
  margin-left: 0;
}

.mobile-menu-submenu.is-visible {
  opacity: 1;
  visibility: visible;
  max-height: 200px; /* Adjust based on content */
}

/* XS: Full screen modal */
@media (max-width: 767px) {
  .mobile-menu-content {
    width: 100%;
    height: 100%;
    border-radius: 0;
  }
  
  /* XS: Smaller wordmark for mobile - now handled by JavaScript responsive system */
  /* .animated-wordmark .wordmark-text {
    font-size: clamp(1.5rem, 8vw, 3rem);
  } */
}

/* SM: Still uses vertical mobile header layout */
@media (min-width: 768px) and (max-width: 1023px) {
  .header-nav {
    max-width: 768px;
    padding: 0 50px;
  }
  
  .header-nav-item {
    font-size: 11px; /* Match S breakpoint episode metadata */
    letter-spacing: 0.77px; /* Match S breakpoint episode metadata */
  }
  
  .header-nav--mobile {
    height: 250px; /* Even taller for SM */
    min-height: 250px;
  }
  
  .mobile-header-content {
    top: 28px; /* Reduced top padding for SM */
  }
  
  .mobile-menu-content {
    width: 500px;
    height: 400px;
    border-radius: 22px; /* Exact Figma spec */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  
  /* Mobile menu header matches episode-list-container responsive sizing */
  .mobile-menu-header {
    max-width: 768px;
    padding: 22px 50px 0 50px; /* Match episode-list-container @768px */
    grid-template-columns: repeat(16, 1fr);
  }
  
  .mobile-menu-nav {
    max-width: 768px;
    padding: 0 50px; /* Match episode-list-container @768px */
  }
}

/* Add missing mobile menu responsive breakpoints to match episode-list-container */
@media (min-width: 1024px) {
  .mobile-menu-header {
    max-width: 1024px;
    padding: 22px 50px 0 50px; /* Match episode-list-container @1024px */
    grid-template-columns: repeat(24, 1fr);
  }
  
  .mobile-menu-nav {
    max-width: 1024px;
    padding: 0 50px; /* Match episode-list-container @1024px */
  }
}

@media (min-width: 1280px) {
  .mobile-menu-header {
    max-width: 1280px;
    /* padding stays same at 50px per episode-list-container */
  }
  
  .mobile-menu-nav {
    max-width: 1280px;
    /* padding stays same at 50px per episode-list-container */
  }
}

@media (min-width: 1920px) {
  .mobile-menu-header {
    max-width: 1920px;
    padding: 22px 60px 0 60px; /* Match episode-list-container @1920px */
  }
  
  .mobile-menu-nav {
    max-width: 1920px;
    padding: 0 60px; /* Match episode-list-container @1920px */
  }
}

/* MD+: Show desktop navigation, hide mobile */
@media (min-width: 1024px) {
  .header-nav--desktop {
    display: grid;
  }
  
  .header-nav--mobile {
    display: none;
  }
  
  .header-nav {
    max-width: 1024px;
    padding: 0 50px;
    grid-template-columns: repeat(24, 1fr);
    height: 80px; /* Restore fixed height for desktop */
    min-height: auto; /* Reset min-height */
  }
  
  .header-nav-item {
    font-size: 10px; /* Match M breakpoint episode metadata */
    letter-spacing: 0.7px; /* Match M breakpoint episode metadata */
  }
  
  
  /* MD+ (24 columns) positioning */
  .header-nav--catalog {
    grid-column: 1 / 3; /* Cols 1-2 */
  }
  
  .header-nav--listen {
    grid-column: 4 / 6; /* Cols 4-5 */
  }
  
  .header-nav--connect {
    grid-column: 20 / 22; /* Cols 20-21 (5-6 from end) - original plan */
  }
  
  .header-nav--theme-toggle {
    grid-column: 24 / 25; /* Col 24 (end position) */
    justify-self: end;
  }
}

@media (min-width: 1280px) {
  .header-nav {
    max-width: 1280px;
    column-gap: 16px;
  }
  
  .header-nav-item {
    font-size: 11px; /* Match L breakpoint episode metadata */
    letter-spacing: 0.77px; /* Match L breakpoint episode metadata */
  }
  
}

@media (min-width: 1920px) {
  .header-nav {
    max-width: 1920px;
    padding: 0 60px;
  }
  
  .header-nav-item {
    font-size: 13px; /* Match XL breakpoint episode metadata */
    letter-spacing: 0.91px; /* Match XL breakpoint episode metadata */
  }
  
}

/*———— WORDMARK SIZING ————*/
.animated-wordmark {
  /* FLIP transform: First ⨉ Invert ⨉ Play */
  transform:
    translate(
      calc(var(--p, 0) * var(--dx, 0px)),
      calc(var(--p, 0) * var(--dy, 0px))
    )
    scale(calc(1 + var(--p, 0) * (var(--s, 1) - 1)))
    translateZ(0)
    /* Additional transforms can be appended by JS */
    var(--wiggle-transform, rotate(0deg));
  
  transform-origin: center;     /* scale from center */
  
  /* GPU optimization - will-change toggled by JS */
  backface-visibility: hidden;
  isolation: isolate;
  white-space: nowrap;
  overflow: visible;
}

/* Wordmark anchor placeholder in header - real glyph size */
.nav-logo {
  font: 600 2rem/1 "Roboto Flex", sans-serif;
  opacity: 0;           /* reserve space, stay invisible */
  letter-spacing: 0.1em; /* match animated wordmark spacing */
}

.animated-wordmark .wordmark-text {
  /* Hero wordmark starting size - viewport responsive, starts larger than target */
  font-size: clamp(4rem, 6vw, 8rem); /* scales with viewport, bigger than anchor */
  line-height: 1;           /* tighter box */
  color: white;
  /* GPU-friendly drop-shadow with opacity animation */
  filter: drop-shadow(0 0 8px rgba(255,255,255, var(--glow-alpha,0.8)));
  opacity: var(--wordmark-opacity, 1);
  transition: opacity .15s ease-out;
  
  /* Optimized for transform-based scaling */
  -webkit-font-smoothing: antialiased;
  contain: layout;          /* drop 'paint' so shadows can spill */
}

/*———— DEBUG INFO OVERLAY ————*/
.debug-info {
  position: fixed;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-family: monospace;
  font-size: 12px;
  z-index: 9999;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.debug-info h4 {
  margin: 0 0 0.5rem 0;
  color: #00faff; /* Cyan */
  font-weight: normal;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  padding-bottom: 0.5rem;
}

.status-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  align-items: center;
}

.status-grid .label {
  color: #aaa;
}

.status-grid .value {
  color: #f5d76e; /* Yellow */
  font-weight: bold;
}

.debug-info .status {
  margin: 0.25rem 0;
}

.debug-info .status.active {
  color: #ffc107;
  font-weight: bold;
}

.debug-info .status.locked {
  color: #f44336;
  font-weight: bold;
}

/*———— DEBUG PANEL ————*/
.debug-panel {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #e0e0e0;
  padding: 0.75rem;
  border-radius: 8px;
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 0.75rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 180px;
}
.debug-panel__title {
  font-weight: bold;
  color: #00ffab;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 0.5rem;
}
.debug-panel__item {
  display: flex;
  justify-content: space-between;
}
.debug-panel__item span:first-child {
  color: #a0a0a0;
}

.episode-list-container {
  background: transparent;
  border-radius: 8px;
  padding: 1rem;
}
