/* ============================================
   Work Detail — Layout + Rail Blocks V1
   ============================================ */

/* ── Header ── */
.work-detail__header {
  /* margin-bottom: var(--space-xs); */
  container-type: inline-size;
  transition: margin-bottom 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.work-detail__title {
  font-family: var(--font-display-current);
  font-size: clamp(1.5rem, 15cqi, 4rem);
  line-height: 1;
  letter-spacing: -0.02em;
  white-space: nowrap;
  transform-origin: left center;
  transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  will-change: transform;
}

.work-detail.is-compact .work-detail__title {
  transform: scale(0.65);
}

/* ── Tags (pills) ── */
.work-detail__tags {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-sm) 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 80px;
  overflow: hidden;
  opacity: 1;
  transition:
    max-height 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    opacity 0.4s ease,
    margin 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.work-detail__tag {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  background: color-mix(in srgb, var(--surface-text) 12%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: none;
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: var(--text-xxxs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--surface-text);
  line-height: 1;
  white-space: nowrap;
}

.work-detail__tag--more {
  opacity: 0.45;
  background: color-mix(in srgb, var(--surface-text) 6%, transparent);
}

/* ── Meta line: "Year · Role" ── */
.work-detail__meta-line {
  max-height: 40px;
  overflow: hidden;
  opacity: 0.45;
  margin-top: var(--space-xs);
  margin-bottom: 0;
  line-height: 1.4;
  transition:
    max-height 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    opacity 0.4s ease,
    margin 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ── Compact state (non-context sections) ── */
/* Font size logic moved to transform for fluidity */

.work-detail.is-compact .work-detail__tags {
  max-height: 0;
  opacity: 0;
  margin-bottom: 0;
  pointer-events: none;
}

.work-detail.is-compact .work-detail__meta-line {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  pointer-events: none;
}

/* .work-detail.is-compact .work-detail__header {
  margin-bottom: var(--space-xs);
} */

/* Show toggle button in compact mode */
.work-detail.is-compact .work-detail__tocToggle {
  display: flex;
}

/* Collapse list in compact mode */
.work-detail.is-compact .work-detail__tocList {
  max-height: 0;
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 60%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0, #000 60%, transparent 100%);
}

/* Expand on hover (desktop) or explicit toggle */
.work-detail.is-compact .work-detail__toc:hover .work-detail__tocList,
.work-detail.is-compact.is-toc-open .work-detail__tocList {
  max-height: clamp(120px, 28vh, 260px);
  overflow-y: auto;
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 18px), transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 18px), transparent 100%);
}

/* Chevron rotation when open */
.work-detail.is-compact .work-detail__toc:hover .work-detail__tocChevron,
.work-detail.is-compact.is-toc-open .work-detail__tocChevron {
  transform: rotate(-135deg);
}

.work-detail.is-compact .work-detail__index-list {
  gap: 0;
}

.work-detail.is-compact .work-detail__index-link {
  padding: 2px 0;
  font-size: calc(var(--text-xs) - 0.05rem);
}

/* ── Sticky Dynamic Bar (Cintillo) ── */
.work-detail__bar {
  position: sticky;
  top: 0;
  /* Sticky to the absolute top to hide content behind navbar */
  z-index: 90;
  /* Lower than main navbar but higher than content */
  background: var(--surface-bg);
  width: 100%;
  padding-top: calc(var(--nav-height) + var(--space-md));
  padding-bottom: var(--space-md);
  border-bottom: 1px solid transparent;
  transition: all 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.work-detail.is-compact .work-detail__bar {
  padding-top: calc(var(--nav-height) + 10px);
  padding-bottom: 10px;
  background: rgba(14, 14, 14, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.work-detail__bar-inner {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: clamp(16px, 3vw, 48px);
  max-width: var(--wide-max);
  margin-inline: auto;
  padding-inline: var(--edge-margin);
  width: 100%;
  align-items: center;
  /* Perfect vertical sync */
}

/* Removed class-based toggles to avoid reflow glitch */

/* Header (Title + Tags) aligned with Narrative column (Col 1-4) */
.work-detail__header {
  grid-column: 1 / span 4;
}

/* TOC aligned with Media column (Col 5-12) handled in the TOC section below */

/* Replaced by GSAP ScrollTrigger for 60fps fluidity */

/* ── Content Container ── */
.work-detail__content {
  padding-inline: var(--edge-margin);
  max-width: var(--wide-max);
  margin-inline: auto;
  padding-top: var(--space-md);
}

/* ── Modular Section (The Renglón) ── */
.work-section {
  padding-bottom: var(--space-xl);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.work-section:first-child {
  border-top: none;
}

.work-section__grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: clamp(16px, 3vw, 48px);
  align-items: start;
}

.work-section__narrative {
  grid-column: 1 / span 4;
  position: sticky;
  /* Top offset = Navbar height + Sticky Bar height + some air */
  top: calc(var(--nav-height) + 120px);
  padding-top: var(--space-sm);
  transition: opacity 0.4s ease, top 0.4s ease;
}

.work-detail.is-compact .work-section__narrative {
  top: calc(var(--nav-height) + 70px);
}

.work-section__body {
  opacity: 0.35;
  transition: opacity 0.5s ease;
}

.work-section.is-active .work-section__body {
  opacity: 1;
}

.section-label {
  display: block;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.4;
  margin-bottom: var(--space-xs);
}

/* ── Right Rail (Media) ── */
.work-section__rail {
  grid-column: 5 / span 8;
  display: flex;
  flex-direction: column;
  gap: clamp(16px, 2vw, 32px);
  padding-top: var(--space-sm);
}

.work-detail__bar-toc {
  grid-column: 5 / span 8;
  position: relative;
  justify-self: end;
  overflow: visible;
  /* CRITICAL: Allow dropdown to float outside */
}

/* Toggle Trigger */
.work-detail__toc-trigger {
  background: color-mix(in srgb, var(--surface-text) 8%, transparent);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 8px 16px;
  border-radius: 999px;
  color: var(--surface-text);
  font-family: var(--font-ui);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.3s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.work-detail__toc-trigger:hover {
  background: color-mix(in srgb, var(--surface-text) 12%, transparent);
  border-color: rgba(255, 255, 255, 0.2);
}

.work-detail.is-toc-open .work-detail__toc-trigger {
  background: var(--work-color);
  color: #fff;
  border-color: transparent;
}

.toc-trigger__icon {
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.3s ease;
}

.work-detail.is-toc-open .toc-trigger__icon {
  transform: rotate(-135deg) translateY(-2px);
}

/* Floating Dropdown */
.work-detail__toc-dropdown {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: 300px;
  /* Increased width */
  max-width: calc(100vw - (var(--edge-margin) * 2));
  background: rgba(14, 14, 14, 0.96);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 8px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 110;
}

.work-detail.is-toc-open .work-detail__toc-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.work-detail__toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.work-detail__toc-link {
  text-decoration: none;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  /* Align number to top of wrapped text */
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  transition: all 0.2s ease;
  color: var(--surface-text);
  opacity: 0.5;
}

.work-detail__toc-link:hover,
.work-detail__toc-link.is-active {
  background: rgba(255, 255, 255, 0.08);
  opacity: 1;
}

.work-detail__toc-link.is-active {
  color: var(--accent-current);
}

.index-num {
  font-family: var(--font-ui);
  font-size: 0.6rem;
  opacity: 0.6;
  line-height: 1.4;
  /* Match text sizing air */
  flex-shrink: 0;
}

.index-num::after {
  content: "·";
  margin-left: 8px;
  opacity: 0.4;
}

.index-txt {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
  line-height: 1.2;
  white-space: normal;
  /* Enable wrapping for long titles */
  flex: 1;
}

/* ── Responsive Refinements ── */
@media (max-width: 900px) {
  .work-section__grid {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }

  .work-section__narrative {
    grid-column: 1;
    position: static;
    padding-bottom: 0;
  }

  .work-section__rail {
    grid-column: 1;
    padding-top: 0;
  }

  .work-detail__bar-index {
    gap: var(--space-sm);
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: none;
  }

  .work-detail__bar-index::-webkit-scrollbar {
    display: none;
  }

  .work-detail.is-compact .work-detail__bar-inner {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Old Grid and Narrative styles removed in favor of Sectional Rows */

/* ── Section head (discrete dividers + mobile section titles) ── */
.rail-section-head {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: var(--space-sm);
}

.rail-section-head__label {
  display: none;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--surface-text);
  opacity: 0.4;
}

/* ── Rail ── */
.work-detail__rail {
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.5vw, 24px);
}

/* ── Placeholder media ── */
.ph {
  width: 100%;
  border-radius: 8px;
  background:
    linear-gradient(135deg,
      rgba(255, 255, 255, 0.04) 0%,
      rgba(255, 255, 255, 0.02) 50%,
      rgba(255, 255, 255, 0.05) 100%);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

/* ── Base block ── */
.rail-block {
  position: relative;
  border-radius: var(--radius-card);
  overflow: hidden;
  background: var(--surface-bg);
  filter: blur(0);
  transition: filter 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    opacity 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ── Section defocus (non-active sections get subtle blur) ── */
.rail-block.is-defocused {
  filter: blur(2px);
  opacity: 0.5;
}

/* ── Surface (content layer, always present) ── */
.rail-block__surface {
  position: relative;
  z-index: 1;
}

.rail-block[data-aura="true"] .rail-block__surface {
  border-radius: inherit;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(14, 14, 14, 0.35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* grain overlay via pseudo */
.rail-block[data-aura="true"] .rail-block__surface::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0.07;
  mix-blend-mode: overlay;
  background-image:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.045) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 4px);
  filter: contrast(120%) brightness(90%);
}

/* ── Aura layer ── */
.rail-block__aura {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: inherit;

  --aura-base: var(--work-color, var(--accent-current, #2865FF));
  --aura-light: color-mix(in oklab, var(--aura-base) 55%, white);
  --aura-dark: color-mix(in oklab, var(--aura-base) 55%, black);
}

/* ── Blobs ── */
.aura-blob {
  display: block;
  position: absolute;
  filter: blur(40px) saturate(140%);
  mix-blend-mode: screen;
  will-change: transform, border-radius;
}

/* blob 0: base puro, centrado, detrás de todos */
.aura-blob--0 {
  width: 70%;
  aspect-ratio: 1;
  top: 50%;
  left: 50%;
  translate: -50% -50%;
  opacity: 0.95;
  background: radial-gradient(ellipse at center, var(--aura-base) 0%, transparent 65%);
  border-radius: 50% 50% 50% 50%;
  filter: blur(50px) saturate(140%);
  z-index: 0;
  animation:
    blobDrift0 16s ease-in-out infinite alternate;
}

.aura-blob--1 {
  width: 55%;
  aspect-ratio: 1;
  top: 10%;
  left: 5%;
  opacity: 0.9;
  z-index: 1;
  background: radial-gradient(ellipse at center, var(--aura-light) 0%, transparent 70%);
  border-radius: 43% 57% 62% 38% / 55% 42% 58% 45%;
  animation:
    blobMorph1 8s ease-in-out infinite alternate,
    blobDrift1 10s ease-in-out infinite alternate;
}

.aura-blob--2 {
  width: 50%;
  aspect-ratio: 1.15;
  top: 20%;
  right: 5%;
  opacity: 0.85;
  z-index: 1;
  background: radial-gradient(ellipse at center, var(--aura-base) 0%, transparent 70%);
  border-radius: 58% 42% 35% 65% / 45% 60% 40% 55%;
  animation:
    blobMorph2 10s ease-in-out infinite alternate,
    blobDrift2 13s ease-in-out infinite alternate;
}

.aura-blob--3 {
  width: 55%;
  aspect-ratio: 0.9;
  bottom: 5%;
  left: 15%;
  opacity: 0.8;
  z-index: 1;
  background: radial-gradient(ellipse at center, var(--aura-dark) 0%, transparent 70%);
  border-radius: 38% 62% 52% 48% / 60% 38% 62% 40%;
  animation:
    blobMorph3 9s ease-in-out infinite alternate,
    blobDrift3 12s ease-in-out infinite alternate;
}

/* ── Aura seed: vary duration + delay per block for true variety ── */
.rail-block__aura .aura-blob--0 {
  animation-duration: calc(16s + var(--aura-seed, 0) * 0.9s);
  animation-delay: calc(var(--aura-seed, 0) * -3.2s);
}

.rail-block__aura .aura-blob--1 {
  animation-duration: calc(8s + var(--aura-seed, 0) * 0.7s), calc(10s + var(--aura-seed, 0) * 1.1s);
  animation-delay: calc(var(--aura-seed, 0) * -1.7s), calc(var(--aura-seed, 0) * -2.3s);
}

.rail-block__aura .aura-blob--2 {
  animation-duration: calc(10s + var(--aura-seed, 0) * 0.5s), calc(13s + var(--aura-seed, 0) * 0.8s);
  animation-delay: calc(var(--aura-seed, 0) * -2.1s), calc(var(--aura-seed, 0) * -1.4s);
}

.rail-block__aura .aura-blob--3 {
  animation-duration: calc(9s + var(--aura-seed, 0) * 1.3s), calc(12s + var(--aura-seed, 0) * 0.6s);
  animation-delay: calc(var(--aura-seed, 0) * -1.3s), calc(var(--aura-seed, 0) * -2.8s);
}

/* Flip direction on even-seeded blocks for extra variety */
.rail-block[data-aura="true"]:nth-child(even) .aura-blob {
  animation-direction: alternate-reverse;
}

/* ── Background color options ── */
/* Applied per .rail-media so color stays inside each card, not bleeding into gaps */
/* brand_alt falls back to brand which falls back to accent */
.rail-block[data-bg="accent"] .rail-media {
  background: var(--accent-current);
}

.rail-block[data-bg="brand"] .rail-media {
  background: var(--work-color, var(--accent-current));
}

.rail-block[data-bg="brand_alt"] .rail-media {
  background: var(--work-color-alt, var(--work-color, var(--accent-current)));
}

.rail-block[data-bg="white"] .rail-media,
.rail-block[data-bg="light"] .rail-media {
  background: #ffffff;
}

.rail-block[data-bg="dark"] .rail-media {
  background: #060606;
}

.rail-block[data-bg="soft-dark"] .rail-media {
  background: #2e2e2e;
}

/* ── Desaturated aura (mono) ── */
.rail-block[data-aura-mono="true"] .rail-block__aura {
  filter: grayscale(1) brightness(0.7);
}

/* ── Logo overlay inside surface ── */
.rail-block__logo {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.rail-block__logo-img {
  width: 48%;
  max-height: 58%;
  opacity: 0.85;
  object-fit: contain;
}

/* ── Blob morph keyframes ── */
@keyframes blobMorph1 {
  0% {
    border-radius: 43% 57% 62% 38% / 55% 42% 58% 45%;
  }

  33% {
    border-radius: 52% 48% 45% 55% / 40% 60% 38% 62%;
  }

  66% {
    border-radius: 60% 40% 55% 45% / 48% 52% 45% 55%;
  }

  100% {
    border-radius: 45% 55% 50% 50% / 58% 42% 55% 45%;
  }
}

@keyframes blobMorph2 {
  0% {
    border-radius: 58% 42% 35% 65% / 45% 60% 40% 55%;
  }

  33% {
    border-radius: 42% 58% 55% 45% / 60% 40% 55% 45%;
  }

  66% {
    border-radius: 50% 50% 42% 58% / 38% 62% 48% 52%;
  }

  100% {
    border-radius: 55% 45% 60% 40% / 50% 50% 42% 58%;
  }
}

@keyframes blobMorph3 {
  0% {
    border-radius: 38% 62% 52% 48% / 60% 38% 62% 40%;
  }

  33% {
    border-radius: 55% 45% 40% 60% / 48% 52% 50% 50%;
  }

  66% {
    border-radius: 42% 58% 58% 42% / 55% 45% 38% 62%;
  }

  100% {
    border-radius: 50% 50% 45% 55% / 42% 58% 55% 45%;
  }
}

/* ── Blob drift keyframes ── */
@keyframes blobDrift0 {
  0% {
    transform: scale(1.0);
  }

  50% {
    transform: scale(1.18);
  }

  100% {
    transform: scale(0.95);
  }
}

@keyframes blobDrift1 {
  0% {
    transform: translate3d(0, 0, 0) scale(1.0);
  }

  33% {
    transform: translate3d(35%, -15%, 0) scale(1.2);
  }

  66% {
    transform: translate3d(-20%, 25%, 0) scale(0.9);
  }

  100% {
    transform: translate3d(10%, 10%, 0) scale(1.15);
  }
}

@keyframes blobDrift2 {
  0% {
    transform: translate3d(0, 0, 0) scale(1.05);
  }

  33% {
    transform: translate3d(-35%, 20%, 0) scale(1.3);
  }

  66% {
    transform: translate3d(25%, -25%, 0) scale(0.85);
  }

  100% {
    transform: translate3d(-10%, -10%, 0) scale(1.1);
  }
}

@keyframes blobDrift3 {
  0% {
    transform: translate3d(0, 0, 0) scale(1.1);
  }

  33% {
    transform: translate3d(25%, -30%, 0) scale(0.9);
  }

  66% {
    transform: translate3d(-30%, 20%, 0) scale(1.3);
  }

  100% {
    transform: translate3d(15%, -5%, 0) scale(1.05);
  }
}

.rail-block__figure {
  margin: 0;
  height: 100%;
  width: 100%;
  position: relative;
  z-index: 2;
  /* Always above aura blobs */
}

/* ── Media wrapper (ratio lives here) ── */
.rail-media {
  position: relative;
  width: 100%;
  overflow: hidden;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  display: block;
}

.rail-media::after {
  display: none;
}

/* ── Video restart button ── */
.rail-media__restart {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  background: color-mix(in srgb, var(--surface-text) 5%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 0.5px solid color-mix(in srgb, var(--surface-text) 15%, transparent);
  border-radius: 999px;
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--surface-text) 2%, transparent),
    0 4px 12px rgba(0, 0, 0, 0.15);
  color: var(--surface-text);
  cursor: pointer;
  transition: transform 0.3s ease, background 0.3s ease, border-color 0.3s ease;
}

.rail-media__restart:hover {
  transform: translateY(-1px) scale(1.04);
  background: color-mix(in srgb, var(--surface-text) 10%, transparent);
  border-color: color-mix(in srgb, var(--surface-text) 28%, transparent);
}

/* ── Individual Card (The Premium Unit) ── */
.rail-card {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Individual card background variants */
.rail-card[data-bg="brand"] {
  background: var(--work-color, var(--accent-current));
}

.rail-card[data-bg="white"] {
  background: #fffffff2;
}

.rail-card[data-bg="dark"] {
  background: #060606;
}

.rail-card[data-bg="soft-dark"] {
  background: #2e2e2e;
}

/* If a card has background, give it some padding so the media floats inside 
   Note: removed default padding as per user feedback to allow images to fill the container */
.rail-card[data-bg] {
  padding: 0;
  justify-content: center;
}

/* Ensure media fills the card when no padding is present */
.rail-card[data-bg] .rail-media {
  width: 100%;
  height: 100%;
  border-radius: 0;
}

/* Specific fix for strip_screens: tighter padding so phones stay large */
.rail-block__strip .rail-card[data-bg] {
  padding: 0;
}

.rail-card[data-bg] .rail-media {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Make both image + placeholder fill the ratio box */
.rail-media__img,
.rail-media .ph {
  width: 100%;
  height: 100%;
  display: block;
}

/* Real image behavior */
.rail-media__img {
  object-fit: cover;
  object-position: center;
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-select: none;
}

/* fit variants */
.rail-media--contain .rail-media__img {
  object-fit: contain;
}

/* ── Media caption / credits ── */
.rail-media__caption {
  font-family: var(--font-ui);
  font-size: var(--text-xs, 0.75rem);
  line-height: 1.4;
  color: var(--surface-text);
  opacity: 0.45;
  padding-top: 8px;
  letter-spacing: 0.01em;
}

/* ── hero_full: brand color panel + logo — fills the above-fold viewport ── */
.rail-block--hero_full {
  background: var(--work-color, var(--accent-current));
  height: calc(100dvh - 10dvh);
}

.rail-block--hero_full .rail-block__surface {
  height: 100%;
}

.rail-block--hero_full .rail-block__logo-img {
  width: 52%;
  max-height: 65%;
}

/* ── duo_equal ── */
.rail-block__duo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 1.5vw, 16px);
}

/* ── duo_stack (right / left) ── */
.rail-block__duo-stack {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 1.5vw, 16px);
  align-items: stretch;
}

/* Make right stack match left height */
.rail-block__duo-stack .rail-block__stack {
  height: 100%;
}

.rail-block__duo-stack .rail-card {
  height: 100%;
}

.rail-block__duo-stack .rail-block__stack>.rail-card {
  flex: 1;
  min-height: 0;
}

.rail-block__duo-stack .rail-card .rail-media {
  height: 100%;
}

.rail-block__duo-stack>* {
  min-width: 0;
}

.rail-block__duo-stack--reverse {
  direction: ltr;
}

.rail-block__stack {
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.5vw, 16px);
}

.rail-block__stack .rail-card {
  flex: 1;
  min-height: 0;
}

.rail-block__stack .rail-card .rail-media {
  height: 100%;
}

.rail-block__stack .ph {
  height: 100%;
}

/* ── quad_grid (2x2) ── */
.rail-block__quad {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 1.5vw, 16px);
}

/* ── mosaic ── */
.rail-block__mosaic {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: clamp(8px, 1.5vw, 16px);
}

.rail-block__mosaic>.rail-card .rail-media {
  height: 100%;
}

.rail-block__mosaic>.rail-card .ph {
  height: 100%;
}

/* ── strip_screens (horizontal scroll) ── */
.rail-block__strip {
  display: flex;
  gap: clamp(8px, 1.5vw, 16px);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
}

.rail-block__strip::-webkit-scrollbar {
  display: none;
}

/* ── Per-card wrapper for strip_screens ── */
.strip-card {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  flex: 0 0 auto;
  width: clamp(120px, 18vw, 200px);
}

.strip-card .rail-block__aura {
  border-radius: inherit;
}

.strip-card .rail-card {
  position: relative;
  z-index: 1;
  height: 100%;
}

.strip-card .aura-blob {
  filter: blur(24px) saturate(140%);
}

.strip-card:nth-child(even) .aura-blob {
  animation-direction: alternate-reverse;
}

/* Fallback: items without strip-card wrapper keep sizing */
.rail-block__strip>.rail-card {
  flex: 0 0 auto;
  width: clamp(120px, 18vw, 200px);
}

/* ── float_cluster ── */
.rail-block__cluster {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
}

.rail-block__cluster .rail-block__cluster-item {
  position: absolute;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .work-detail {
    padding-top: var(--space-md);
  }

  .work-detail__grid {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }

  .work-detail__left {
    grid-column: 1;
    position: static;
    max-height: none;
    padding-top: 0;
    width: 100%;
  }

  .work-detail__right {
    grid-column: 1;
    width: 100%;
  }

  .work-detail__tocToggle {
    display: none !important;
  }

  .work-detail__tocList {
    max-height: none !important;
    overflow: visible !important;
    -webkit-mask-image: none !important;
    mask-image: none !important;
  }

  .work-detail__index-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px 12px;
    margin-bottom: var(--space-md);
    max-height: none;
    overflow-y: visible;
  }

  .work-detail__index-link {
    padding: 4px 0;
  }

  .work-detail__narrative-body {
    overflow-y: visible;
    -webkit-mask-image: none;
    mask-image: none;
    padding-right: 0;
    scrollbar-gutter: auto;
  }

  .work-detail__narrative {
    margin-bottom: var(--space-md);
  }

  .work-detail__narrative-window {
    overflow: visible;
    -webkit-mask-image: none;
    mask-image: none;
  }

  .work-detail__narrative-item {
    opacity: 1 !important;
    padding-bottom: var(--space-md);
  }

  .work-detail__narrative-scroll {
    padding-bottom: 0;
  }

  /* Show section titles in rail on mobile */
  .rail-section-head__label {
    display: block;
    margin-bottom: 8px;
  }

  /* Logo block: taller aspect ratio + bigger logo on mobile */
  .rail-block[data-logo="true"] .rail-media {
    aspect-ratio: 4/3 !important;
  }

  .rail-block[data-logo="true"] .rail-block__logo-img {
    max-width: 55%;
    max-height: 60%;
  }

  /* hero_full: shorter on mobile since narrative stacks above */
  .rail-block--hero_full {
    height: 65svh;
  }
}

@media (max-width: 600px) {
  .work-detail__tags {
    max-height: none;
  }

  .rail-block__duo,
  .rail-block__quad {
    grid-template-columns: 1fr;
  }

  .rail-block__duo-stack {
    grid-template-columns: 1fr;
  }

  .rail-block__mosaic {
    grid-template-columns: 1fr;
  }

  /* Ensure mosaic cards don't force height on mobile */
  .rail-block__mosaic>.rail-card .rail-media {
    height: auto;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {

  .work-detail__title,
  .work-detail__tags,
  .work-detail__meta-line,
  .work-detail__header,
  .work-detail__index-list,
  .work-detail__index-link,
  .work-detail__tocList,
  .work-detail__tocChevron,
  .rail-block {
    transition: none;
  }

  .aura-blob {
    animation: none;
  }

  .rail-media__restart {
    transition: none;
  }
}