/* ============================================
   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 {
  /* margin-bottom: var(--space-xs); */
  font-family: var(--font-display-current);
  font-size: clamp(1.5rem, 15cqi, 4rem);
  line-height: 1;
  letter-spacing: -0.02em;
  overflow-wrap: break-word;
  transition: font-size 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.work-detail__meta {
  display: flex;
  gap: var(--space-md);
  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__meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.work-detail__meta-item dt {
  opacity: 0.5;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.work-detail__meta-item dd {
  margin: 0;
}

/* ── Compact state (non-context sections) ── */
.work-detail.is-compact .work-detail__title {
  font-size: clamp(1rem, 1.5vw + 0.5rem, 1.5rem);
}

.work-detail.is-compact .work-detail__meta {
  max-height: 0;
  opacity: 0;
  margin-bottom: 0;
}

/* .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);
}

/* ── Main grid: 4/8 ── */
.work-detail {
  padding-inline: clamp(16px, 4vw, 56px);
  max-width: var(--wide-max);
  margin-inline: auto;
  padding-bottom: var(--space-2xl);
}

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

.work-detail__left {
  grid-column: 1 / span 4;
  position: sticky;
  top: clamp(16px, 6vh, 72px);
  align-self: start;
  padding-top: var(--space-lg);
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2vh, 20px);
  max-height: calc(100vh - clamp(16px, 6vh, 72px) - var(--space-lg));
}

.work-detail__right {
  grid-column: 5 / span 8;
}

/* ── TOC (collapsible index) ── */
.work-detail__toc {
  flex-shrink: 0;
}

.work-detail__tocHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.work-detail__tocLabel {
  opacity: 0.5;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.work-detail__tocToggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: none;
  color: var(--surface-text);
  opacity: 0.4;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.work-detail__tocToggle:hover {
  opacity: 1;
}

.work-detail__tocChevron {
  display: block;
  width: 10px;
  height: 10px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.work-detail__tocList {
  max-height: 600px;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ── Section index ── */
.work-detail__index-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition:
    gap 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.work-detail__index-link {
  display: flex;
  align-items: baseline;
  gap: 0.75em;
  padding: 6px 0;
  text-decoration: none;
  color: var(--surface-text);
  opacity: 0.4;
  transition:
    opacity 0.2s ease,
    padding 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    font-size 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.work-detail__index-link:hover,
.work-detail__index-link.is-active {
  opacity: 1;
}

.work-detail__index-label {
  font-variant-numeric: tabular-nums;
  min-width: 1.6em;
  opacity: 0.6;
}

/* ── Narrative body ── */
.work-detail__narrative {
  padding-top: var(--space-xs);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.work-detail__narrative .section-label {
  margin-bottom: var(--space-xs);
  display: block;
  flex-shrink: 0;
}

.work-detail__narrative-body {
  opacity: 0.75;
  line-height: 1.7;
  overflow-y: auto;
  min-height: 0;
  padding-right: 8px;
  scrollbar-gutter: stable;
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 12px), transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 12px), transparent 100%);
}

.work-detail__narrative-body p {
  margin-bottom: 0.8em;
}

.work-detail__narrative-body p:last-child {
  margin-bottom: 0;
}

/* ── 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: 10px;
  overflow: hidden;
  background: var(--surface-bg);
  filter: blur(0);
  transition: filter 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);
}

/* ── 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(--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;
}

/* ── 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;
}

/* ── hero_full ── */
.rail-block--hero_full .ph {
  border-radius: 10px;
  background:
    linear-gradient(
      160deg,
      var(--accent-current) 0%,
      color-mix(in srgb, var(--accent-current) 40%, #0e0e0e) 100%
    );
  border-color: rgba(255, 255, 255, 0.08);
}

/* ── 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);
}

.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-block__figure {
  flex: 1;
  min-height: 0;
}

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

.rail-block__duo-stack .rail-block__figure--large .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-block__figure--large .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;
}

.rail-block__strip .rail-block__figure {
  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__figure {
  position: absolute;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .work-detail__grid {
    grid-template-columns: 1fr;
  }

  .work-detail__left {
    grid-column: 1;
    position: static;
    max-height: none;
  }

  .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 {
    max-height: none;
    overflow-y: visible;
  }

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

  .work-detail__right {
    grid-column: 1;
  }

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

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

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

@media (max-width: 600px) {
  .work-detail__meta {
    flex-wrap: wrap;
    gap: var(--space-sm);
  }

  .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;
  }

  .rail-block__mosaic > .rail-block__figure--large .ph {
    height: auto;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .work-detail__title,
  .work-detail__meta,
  .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;
  }
}
