/* ======================================================
   SITE HEADER (LEGIBLE ON ANY IMAGE)
   ====================================================== */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 10;
  pointer-events: none;
}

.site-header-inner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  height: var(--site-header-height);
  padding: 0 2rem; /* Stable fixed padding instead of vw */
  background: rgba(255, 255, 255, var(--nav-bg-alpha));
  transition: background 220ms linear;
}

/* Mobile header adjustments */
@media (max-width: 768px) {
  .site-header-inner {
    padding: 0 0 0 1rem; /* Left padding only — actions flush to right edge */
  }

  .site-actions {
    margin-left: 0;
    gap: 2px;
  }

  .site-actions .icon-btn,
  .site-actions .mobile-menu-toggle {
    padding: 0.25rem;
    min-width: 40px;
    min-height: 40px;
  }
}

.site-header a,
.site-header svg {
  color: white;
  stroke: white;
  transition: color 220ms linear, stroke 220ms linear;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

@supports (color: color-mix(in srgb, #fff, #000)) {
  .site-header a,
  .site-header svg {
    color: color-mix(in srgb, var(--paper) calc((1 - var(--nav-bg-alpha)) * 100%), var(--ink) calc(var(--nav-bg-alpha) * 100%));
    stroke: color-mix(in srgb, var(--paper) calc((1 - var(--nav-bg-alpha)) * 100%), var(--ink) calc(var(--nav-bg-alpha) * 100%));
    text-shadow: 0 1px 2px rgba(0, 0, 0, calc((1 - var(--nav-bg-alpha)) * 0.55));
  }

  .site-title {
    border-color: color-mix(in srgb, var(--paper) calc((1 - var(--nav-bg-alpha)) * 100%), var(--ink) calc(var(--nav-bg-alpha) * 100%));
  }
}

.site-title {
  pointer-events: auto;
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border: 2px solid white;
  text-shadow: none;
  transition: border-color 220ms linear, background 220ms linear;
  font-family: "DM Sans", sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  text-decoration: none;
  min-height: 44px; /* Ensure minimum touch target height */
  display: flex; /* Change to flex to center content vertically */
  align-items: center; /* Center content vertically */
  box-sizing: border-box; /* Include padding and border in height calculation */
  background: rgba(0, 0, 0, 0.22); /* Dark tint ensures white text contrast over any hero image */
}

@supports (color: color-mix(in srgb, #fff, #000)) {
  .site-title {
    background: color-mix(
      in srgb,
      rgba(0, 0, 0, 0.22) calc((1 - var(--nav-bg-alpha, 0)) * 100%),
      transparent calc(var(--nav-bg-alpha, 0) * 100%)
    );
  }
}

/* Homepage: steel-grey state when scrolled past the carousel */
.site-header.is-scrolled {
  background-color: rgba(75, 85, 99, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.site-header.is-scrolled .site-header-inner {
  background-color: transparent;
}

.site-header.is-scrolled a,
.site-header.is-scrolled button {
  color: #fff;
}

.site-header.is-scrolled svg {
  stroke: #fff;
}

.site-nav {
  display: flex;
  justify-content: flex-end;
  gap: 2.2rem;
  pointer-events: auto;
}

.site-nav a {
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.3rem 0.6rem;
  box-sizing: border-box;
}

.site-actions {
  display: flex;
  gap: 1.6rem;
  margin-left: 3rem;
  pointer-events: auto;
  justify-content: flex-end; /* Ensure right alignment */
  align-items: center; /* Center items vertically */
}

/* Mobile adjustments to prevent overflow */
@media (max-width: 768px) {
  .site-actions {
    gap: 2px;
    margin-left: 0;
    justify-content: flex-end;
  }
}

.icon-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px; /* Optional: adds subtle rounded corner if background is ever added */
}

/* Mobile touch target optimization */
@media (max-width: 768px) {
  .icon-btn {
    width: 48px; /* Minimum 44px touch target, using 48px for comfort */
    height: 48px;
    /* Enhanced touch feedback */
    transition: background 120ms ease, transform 120ms ease;
  }
  
  /* Touch feedback - active state for mobile taps */
  .icon-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.15);
  }
}

.icon-btn svg {
  width: 1.4rem;
  height: 1.4rem;
  stroke-width: 1.75;
  fill: none;
}

.icon-btn:focus-visible,
.mobile-menu-toggle:focus-visible,
.mobile-nav-close:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
  border-radius: 4px;
}

.site-nav a:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 4px;
  border-radius: 2px;
}

#toggle-snow[aria-pressed="false"] {
  opacity: 0.55;
}

.eye-slash {
  stroke-width: 2;
  opacity: 0;
}

body.text-only .eye-slash {
  opacity: 1;
}

/* ======================================================
   MOBILE NAVIGATION STYLES
   ====================================================== */

/* Mobile menu toggle button (hamburger) */
.mobile-menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 48px; /* Increased from 2.5rem (40px) to meet 44px minimum */
  height: 48px; /* Increased from 2.5rem (40px) to meet 44px minimum */
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  gap: 0.25rem;
  pointer-events: auto;
}

.hamburger-line {
  width: 1.5rem;
  height: 2px;
  background: white;
  transition: all 0.3s ease;
  transform-origin: center;
}

@supports (color: color-mix(in srgb, #fff, #000)) {
  .hamburger-line {
    background: color-mix(in srgb, var(--paper) calc((1 - var(--nav-bg-alpha)) * 100%), var(--ink) calc(var(--nav-bg-alpha) * 100%));
  }
}

/* Hamburger animation when menu is open */
.mobile-menu-toggle[aria-expanded="true"] .hamburger-line:nth-child(1) {
  transform: rotate(45deg) translate(0.375rem, 0.375rem);
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-line:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-line:nth-child(3) {
  transform: rotate(-45deg) translate(0.375rem, -0.375rem);
}

/* Mobile navigation menu */
.mobile-nav {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 30000000; /* Higher than C2PA overlay (20000000) and lightbox (10000001) */
  pointer-events: none;
  /* Force isolation from backdrop filters */
  isolation: isolate;
}

.mobile-nav[aria-hidden="false"] {
  display: block;
  pointer-events: auto;
}

.mobile-nav-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s ease;
  /* Ensure overlay is isolated */
  isolation: isolate;
}

.mobile-nav[aria-hidden="false"] .mobile-nav-overlay {
  opacity: 1;
}

.mobile-nav-content {
  position: absolute;
  top: 0;
  right: 0;
  width: 280px;
  max-width: 80vw;
  height: 100%;
  background: #1a1f2c !important; /* Force solid background */
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  transform: translateX(100%) translateZ(0);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  padding: 0; /* Remove padding to control spacing better */
  gap: 0; /* Remove gap to control spacing better */
  z-index: 30000001; /* Higher than parent container */
  /* Force isolation to prevent transparency inheritance */
  isolation: isolate;
  /* Ensure no backdrop filters interfere */
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  /* Force stacking context without interfering with translateX */
  will-change: transform;
  /* Additional isolation properties */
  contain: layout style paint;
  /* Force opaque rendering */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  /* Ensure content is visible */
  overflow-y: auto;
  overflow-x: hidden;
}

.mobile-nav[aria-hidden="false"] .mobile-nav-content {
  transform: translateX(0) translateZ(0);
}

.mobile-nav-close {
  position: absolute;
  top: 0;
  right: 0.5rem; /* Match the hamburger button's right padding */
  background: none;
  border: none;
  cursor: pointer;
  width: 48px; /* Match hamburger button size */
  height: 48px; /* Match hamburger button size */
  display: flex;
  align-items: center;
  justify-content: center;
  color: white; /* White color for dark background */
  /* Enhanced touch feedback */
  transition: background 120ms ease, transform 120ms ease;
  z-index: 30000002; /* Above everything else */
  /* Align with site header height */
  margin-top: calc(var(--site-header-height, 64px) - 48px); /* Center vertically in header area */
}

/* Touch feedback - active state for mobile taps */
.mobile-nav-close:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.1); /* Light background on dark panel */
}

.mobile-nav-close svg {
  width: 1.5rem;
  height: 1.5rem;
  stroke: white; /* White stroke for dark background */
  stroke-width: 2;
}

.mobile-nav a {
  color: white; /* White text for dark background */
  text-decoration: none;
  font-family: "Fraunces", serif; /* Use Fraunces font to match content layouts */
  font-size: 1.6rem; /* Larger, more elegant size */
  font-weight: 400; /* Regular weight for Fraunces */
  padding: 1rem 2rem; /* Horizontal padding for touch targets */
  border-bottom: 1px solid rgba(255, 255, 255, 0.15); /* Subtle light border */
  transition: color 0.2s ease, background 0.2s ease;
  /* Ensure adequate touch target height */
  min-height: 48px; /* Minimum 44px touch target, using 48px for comfort */
  display: flex;
  align-items: center;
  border-radius: 0; /* Remove border radius for full-width touch targets */
  line-height: 1.3; /* Better line height for Fraunces */
  /* Ensure visibility */
  position: relative;
  z-index: 1;
}

/* Add top margin to first navigation link to account for close button */
.mobile-nav a:first-of-type {
  margin-top: calc(var(--site-header-height, 64px) + 1rem);
}

.mobile-nav a:hover {
  color: var(--accent, #d04b36); /* Accent color on hover */
  background: rgba(255, 255, 255, 0.05); /* Very subtle background on hover */
}

.mobile-nav a:last-child {
  border-bottom: none;
}

/* Responsive display logic */
@media (max-width: 768px) {
  .desktop-nav {
    display: none;
  }
  
  .mobile-menu-toggle {
    display: flex;
  }
  
  /* Mobile nav should still respect aria-hidden state */
  .mobile-nav[aria-hidden="true"] {
    display: none;
  }
  
  .mobile-nav[aria-hidden="false"] {
    display: block;
  }
  
}

@media (min-width: 769px) {
  .desktop-nav {
    display: flex;
  }
  
  .mobile-menu-toggle {
    display: none;
  }
  
  .mobile-nav {
    display: none;
  }
}

/* Override any backdrop filters that might affect mobile navigation */
.mobile-nav,
.mobile-nav-overlay,
.mobile-nav-content {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* Ensure mobile navigation is always above any backdrop-filtered elements */
@media (max-width: 768px) {
  .mobile-nav {
    z-index: 30000000 !important; /* Higher than all other elements */
    /* Create new stacking context to isolate from backdrop filters */
    position: fixed !important;
    isolation: isolate !important;
  }
  
  .mobile-nav-content {
    z-index: 30000001 !important;
    background: #1a1f2c !important;
    /* Ensure completely opaque background */
    opacity: 1 !important;
    /* Don't override transform here - let the main rules handle the slide animation */
  }
  
  /* Ensure mobile navigation is not affected by any parent backdrop filters */
  .site-header[style*="backdrop-filter"] ~ * .mobile-nav,
  .site-header[style*="-webkit-backdrop-filter"] ~ * .mobile-nav {
    z-index: 30000003 !important;
  }
  
  /* When Contents panel is open, ensure mobile nav overlay doesn't interfere */
  body.toc-open .mobile-nav-overlay {
    pointer-events: none !important;
  }
}
