/* ==========================================================================
   Bada Global — FocusRail carousel
   visionOS-style click/swipe/wheel-driven spatial card browser.
   Pairs with assets/js/focusrail.js.

   Card width + translateX base are exposed as CSS custom properties so
   focusrail.js can read them via getComputedStyle without hard-coding
   breakpoint math in two places.
   ========================================================================== */

/* ---- Layout tokens (read by JS via getComputedStyle on .chapter-focusrail) */
.chapter-focusrail {
  --fr-card-w:   300px;  /* card width — desktop ≥1280px */
  --fr-tx-base:  320px;  /* translateX step between cards */
}

@media (max-width: 1279px) and (min-width: 768px) {
  .chapter-focusrail {
    --fr-card-w:  280px;
    --fr-tx-base: 300px;
  }
}

@media (max-width: 767px) {
  .chapter-focusrail {
    --fr-card-w:  240px;
    --fr-tx-base: 200px; /* narrowed so neighbors don't fly off-screen */
  }
}

/* ==========================================================================
   Section wrapper
   ========================================================================== */

.chapter-focusrail {
  position: relative;
  background: #0a0a0b;
  color: #ffffff;
  overflow: hidden;
  padding-block: clamp(4rem, 8vw, 7rem);
  /* outline:0 needed for tabindex="0" keyboard nav without visible focus ring
     on the section itself — individual interactive children still show focus */
  outline: 0;
}

/* ==========================================================================
   Background ambience — blurred clone of the active card's image
   ========================================================================== */

.focusrail-ambience {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.focusrail-ambience-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(80px) saturate(2);
  opacity: 0;
  transition: opacity 800ms ease-out;
  /* hardware-accelerated compositing — avoids layout thrash during opacity fade */
  will-change: opacity;
}

.focusrail-ambience-img[data-active="true"] {
  opacity: 0.4;
}

/* Dark gradient overlay — bottom-heavy so info text always stays readable */
.focusrail-ambience-grad {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top,
    #0a0a0b 0%,
    rgba(10, 10, 11, 0.5) 50%,
    transparent 100%
  );
}

/* ==========================================================================
   Stage — perspective container
   ========================================================================== */

.focusrail-stage {
  position: relative;
  z-index: 1;
  perspective: 1200px;
  perspective-origin: 50% 50%;
  /* Prevent perspective container from clipping neighbour cards */
  overflow: visible;
  margin-block-end: clamp(2.5rem, 4vw, 4rem);
  /* Fixed height so the section doesn't jump when active card changes */
  height: calc(var(--fr-card-w) * 4 / 3 + 2rem);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   Track — contains all cards; centered so card[0]'s center is mid-stage
   ========================================================================== */

.focusrail-track {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
  /* preserve-3d so child translateZ values compound with the stage perspective */
  transform-style: preserve-3d;
  /* Track itself doesn't translate — JS moves individual cards */
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   Cards
   ========================================================================== */

.focusrail-card {
  position: absolute;
  width: var(--fr-card-w);
  aspect-ratio: 3 / 4;
  border-radius: var(--bds-radius-feature, 12px);
  overflow: hidden;
  cursor: pointer;
  /* transform is set entirely by JS — CSS here is just defaults */
  transform-style: preserve-3d;
  will-change: transform, opacity, filter;
  /* Prevent list marker for <ol>/<li> usage */
  list-style: none;
  /* Base box-shadow — the active card also gets a glow ring via JS class */
  box-shadow:
    0 0.75rem 2.5rem rgba(0, 0, 0, 0.6),
    0 0.25rem 0.75rem rgba(0, 0, 0, 0.4);
}

/* Active card ring */
.focusrail-card[data-active="true"] {
  box-shadow:
    0 0.75rem 2.5rem rgba(0, 0, 0, 0.6),
    0 0.25rem 0.75rem rgba(0, 0, 0, 0.4),
    0 0 0 1.5px rgba(255, 255, 255, 0.2);
  cursor: default;
}

.focusrail-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 40%;
  display: block;
  pointer-events: none;
  /* Slight scale-up prevents white edge fringe when card is rotated */
  transform: scale(1.02);
}

/* Gloss highlight — top gradient that reads as light catching the card face */
.focusrail-card-gloss {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    160deg,
    rgba(255, 255, 255, 0.12) 0%,
    rgba(255, 255, 255, 0.0) 45%
  );
  pointer-events: none;
  border-radius: inherit;
  z-index: 2;
}

/* ==========================================================================
   Info area — step meta + title + description
   ========================================================================== */

.focusrail-info {
  position: relative;
  z-index: 1;
  max-width: var(--bds-max-w, 1280px);
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 4rem);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2rem;
}

@media (max-width: 767px) {
  .focusrail-info {
    flex-direction: column;
    align-items: stretch;
  }
}

/* Text wrapper — fades as a unit when active card changes */
.focusrail-info-text {
  flex: 1;
  min-width: 0;
  /* transition driven by JS adding/removing .fr-info-leave / .fr-info-enter */
}

.focusrail-info-meta {
  font-family: var(--bds-font-mono, ui-monospace, monospace);
  font-size: 0.75rem;           /* 12px */
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bds-blue, #0071e3);
  margin: 0 0 0.6rem 0;
}

.focusrail-info-title {
  font-family: var(--bds-font-sans, -apple-system, BlinkMacSystemFont, system-ui, sans-serif);
  font-size: clamp(1.5rem, 2vw + 0.75rem, 1.875rem); /* 24–30px */
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: #ffffff;
  margin: 0 0 0.75rem 0;
}

.focusrail-info-description {
  font-size: 1rem;              /* 16px */
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.72);
  margin: 0;
  max-width: 38rem;
}

/* Info animation states — toggled by JS */
.fr-info-leave {
  opacity: 0;
  transform: translateY(-10px);
  filter: blur(4px);
  transition:
    opacity 300ms ease-out,
    transform 300ms ease-out,
    filter 300ms ease-out;
}

.fr-info-enter {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0px);
  transition:
    opacity 300ms ease-out,
    transform 300ms ease-out,
    filter 300ms ease-out;
}


/* ==========================================================================
   Controls — prev/next pill
   ========================================================================== */

.focusrail-controls {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding-top: 0.25rem; /* align with meta eyebrow */
}

@media (max-width: 767px) {
  .focusrail-controls {
    align-self: flex-start;
    padding-top: 0;
  }
}

.focusrail-pill {
  display: flex;
  align-items: center;
  gap: 0;
  border-radius: var(--bds-radius-pill, 980px);
  background: rgba(20, 20, 20, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 4px;
}

.focusrail-prev,
.focusrail-next {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.55);
  transition:
    background var(--bds-dur-fast, 200ms) ease,
    color var(--bds-dur-fast, 200ms) ease,
    transform 120ms ease;
  outline: none;
}

.focusrail-prev:hover:not(:disabled),
.focusrail-next:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.focusrail-prev:active:not(:disabled),
.focusrail-next:active:not(:disabled) {
  transform: scale(0.95);
}

.focusrail-prev:disabled,
.focusrail-next:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.focusrail-prev:focus-visible,
.focusrail-next:focus-visible {
  outline: 2px solid var(--bds-blue, #0071e3);
  outline-offset: 2px;
}

.focusrail-counter {
  font-family: var(--bds-font-mono, ui-monospace, monospace);
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.4);
  min-width: 44px;
  text-align: center;
  user-select: none;
}

/* ==========================================================================
   Screen-reader only live region
   ========================================================================== */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Reduced-motion — disable springs, blur, remove filter animations
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .focusrail-ambience-img {
    transition: opacity 0ms;
  }

  .focusrail-card {
    /* JS bypasses spring and applies transforms directly — just prevent any
       CSS transitions from fighting the instant updates */
    transition: none !important;
    filter: none !important;
  }

  .fr-info-leave,
  .fr-info-enter {
    transition: none;
    filter: none;
    transform: none;
  }
}
