/*
 * Contents catalog direction — the cinematic screen, discovery, series galleries with
 * depth and the editorial index. Loaded after library.css, series.css and hero.css.
 */

/* ---------- The screen: the same framed cinema as a publication's opening ---------- */
.alan-library[data-library-catalog] .ea-drift {
  width: calc(100% - 24px);
  height: clamp(560px, calc(100svh - 112px), 900px);
  margin: 0 auto clamp(8px, 1vw, 16px);
  border-radius: clamp(16px, 1.6vw, 26px);
  /* The lower edge of the first round: the wall's own vertical fade (hero.css) and one
   * soft, restrained shadow beneath the screen. */
  box-shadow: 0 50px 140px -60px rgba(0, 0, 0, .7);
}
.alan-library[data-library-catalog] .ea-drift__copy {
  z-index: 3;
  left: clamp(28px, 6vw, 112px);
  width: min(620px, 52%);
  max-width: none;
}
.alan-library[data-library-catalog] .ea-drift .ea-drift__copy h1 {
  font-size: clamp(64px, 8.4vw, 146px);
  font-weight: 600;
  line-height: .94;
  letter-spacing: -.065em;
}
.alan-library[data-library-catalog] .ea-drift .ea-drift__description { margin: clamp(20px, 2.2vw, 30px) 0 14px; font-size: clamp(15px, 1.15vw, 18px); line-height: 1.6; }
.ea-drift__stats { display: flex; flex-wrap: wrap; gap: 6px 0; margin: 0 0 clamp(24px, 2.8vw, 36px); font: 500 11px/1.4 var(--lib-sans); letter-spacing: .06em; color: #aeb7c4; }
.ea-drift__stats span + span::before { content: ""; display: inline-block; width: 3px; height: 3px; margin: 0 12px; border-radius: 50%; background: currentColor; vertical-align: middle; opacity: .6; }
.ea-drift__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 28px; }
.ea-drift__latest {
  display: inline-grid;
  grid-template-columns: 76px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  max-width: 340px;
  padding: 6px 18px 6px 6px;
  border: 1px solid rgba(245, 245, 247, .18);
  border-radius: 16px;
  background: rgba(16, 20, 27, .5);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  backdrop-filter: blur(16px) saturate(1.3);
  color: #f5f5f7;
  transition: border-color .35s, background-color .35s, transform .5s var(--alan-ease-out, ease);
}
.ea-drift__latest:is(:hover, :focus-visible) { border-color: rgba(245, 245, 247, .45); background: rgba(24, 29, 38, .72); transform: translateY(-2px); }
.ea-drift__latest-image { display: block; aspect-ratio: 16 / 9; overflow: hidden; border-radius: 10px; background: #202630; }
.ea-drift__latest-image img { width: 100%; height: 100%; object-fit: cover; }
.ea-drift__latest-text { display: grid; gap: 3px; min-width: 0; }
.ea-drift__latest-text small { font: 600 9px/1.3 var(--lib-sans); letter-spacing: .14em; text-transform: uppercase; color: #aeb7c4; }
.ea-drift__latest-text strong { font: 500 13px/1.3 var(--lib-sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Entrance, in the Home's vocabulary: the frame opens, the title rises from behind its
 * baseline, the other lines follow in cascade, and the wall of covers unveils in one
 * piece once its images are decoded. The wall starts drifting only after that. */
.alan-library[data-library-catalog] .ea-drift { --ea-hero-ease: cubic-bezier(.22, 1, .36, 1); }
@media (prefers-reduced-motion: no-preference) {
  html:not([data-alan-vt-arrival]) .alan-library[data-library-catalog] .ea-drift { animation: ea-stage-in 1.2s var(--ea-hero-ease) backwards; }
  html:not([data-alan-vt-arrival]) .alan-library[data-library-catalog] .ea-drift__word { animation: ea-title-rise 1.15s var(--ea-hero-ease) .16s backwards; }
  html:not([data-alan-vt-arrival]) .alan-library[data-library-catalog] .ea-drift__copy > :not(h1) { animation: ea-rise 1s var(--ea-hero-ease) backwards; animation-delay: calc(460ms + var(--ea-i, 0) * 110ms); }
  .alan-library[data-library-catalog] .ea-drift[data-cinematic-ready] .ea-drift__root .ea-drift__wall { animation: ea-wall-unveil 1.5s var(--ea-hero-ease) backwards; }
  .alan-library[data-library-catalog] .ea-drift[data-cinematic-ready] .ea-drift__pause { animation: ea-fade .8s ease .8s backwards; }
}
@keyframes ea-title-rise { from { transform: translate3d(0, 104%, 0); } }
@keyframes ea-wall-unveil { from { opacity: 0; transform: scale(1.07); } to { opacity: 1; transform: none; } }

/* ---------- Discovery ---------- */
.ea-series-nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 22px auto 0; }
.ea-series-nav a {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 16px 0 12px;
  border: 1px solid var(--lib-line);
  border-radius: 999px;
  font: 500 13px/1 var(--lib-sans);
  transition: border-color .3s, background-color .3s;
}
.ea-series-nav a:is(:hover, :focus-visible) { border-color: hsl(var(--lib-swatch-h) 50% 72% / .7); background: hsl(var(--lib-swatch-h) 40% 50% / .1); }
.alan-library[data-library-catalog] :is(.alan-library-shelf__heading h2, .alan-library-all__heading h2) { margin-top: 0; }
.alan-library[data-library-catalog] .alan-library-all { padding-bottom: calc(clamp(24px, 4vw, 56px) + env(safe-area-inset-bottom, 0px)); }
.ea-series-nav__swatch { width: 10px; height: 10px; border-radius: 50%; background: hsl(var(--lib-swatch-h) var(--lib-swatch-s, 50%) 62%); box-shadow: 0 0 0 4px hsl(var(--lib-swatch-h) 50% 60% / .16); }

/* ---------- Series galleries: depth from the gallery's own scroll ---------- */
/* Atmospheric glow shared by catalog galleries and series episode grids ([data-glow]).
 * Three soft fields in the series tone; ambient while in view, full while engaged.
 * The layer moves by transform (pointer-eased in experience.js), so it never repaints. */
.alan-library-shelf { --glow-h: var(--shelf-h, 215); --glow-s: var(--shelf-s, 40%); }
[data-glow] { --gx: 0; --gy: 0; position: relative; isolation: isolate; }
[data-glow]::before {
  content: "";
  position: absolute;
  inset: -45% -30% -40%;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(40% 44% at 36% 50%, hsl(var(--glow-h, 215) var(--glow-s, 40%) 56% / .22), hsl(var(--glow-h, 215) var(--glow-s, 40%) 50% / .08) 55%, transparent 100%),
    radial-gradient(34% 38% at 66% 56%, hsl(calc(var(--glow-h, 215) + 26) var(--glow-s, 40%) 48% / .14), hsl(calc(var(--glow-h, 215) + 26) var(--glow-s, 40%) 44% / .05) 55%, transparent 100%),
    radial-gradient(64% 66% at 50% 50%, hsl(var(--glow-h, 215) 30% 38% / .07), transparent 100%);
  opacity: 0;
  transform: translate3d(calc(var(--gx) * 1%), calc(var(--gy) * 1%), 0);
  transition: opacity 1.4s var(--alan-ease-soft, ease);
  will-change: opacity, transform;
}
[data-glow].is-ambient::before { opacity: .36; }
[data-glow].is-engaged::before { opacity: 1; transition-duration: .9s; }
.alan-library-shelf__about { max-width: 52ch; margin: 12px 0 0; font: 400 14px/1.6 var(--lib-sans); color: var(--lib-muted); text-wrap: pretty; }
.alan-library-track .alan-library-card { flex-basis: clamp(272px, 30vw, 460px); }
.alan-library-card__image { transform: translateZ(0); }
.alan-library-card__link:is(:hover, :focus-visible) .alan-library-card__image > img { transform: scale(1.05); }
.alan-library-card__link:focus-visible { outline: none; }
.alan-library-card__link:focus-visible .alan-library-card__image { outline: 2px solid var(--alan-ui-focus, #b7d1ed); outline-offset: 4px; }
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .alan-library-track .alan-library-card__image {
      animation: ea-gallery-depth linear both;
      animation-timeline: view(inline);
      animation-range: cover 0% cover 100%;
    }
  }
}
/* Desktop: depth only as a card enters from the right; cards never fade away. */
@keyframes ea-gallery-depth {
  0% { scale: .95; filter: brightness(.82); }
  22%, 100% { scale: 1; filter: none; }
}
/* Mobile keeps its approved depth on both edges. */
@keyframes ea-gallery-depth-mobile {
  0% { scale: .9; filter: brightness(.55) saturate(.7); }
  24%, 76% { scale: 1; filter: none; }
  100% { scale: .9; filter: brightness(.55) saturate(.7); }
}
@media (max-width: 700px) {
  .alan-library-track .alan-library-card__image { animation-name: ea-gallery-depth-mobile !important; }
}
.alan-library-card__progress { display: block; height: 3px; margin-top: 12px; border-radius: 3px; background: var(--lib-line); overflow: hidden; }
.alan-library-card__progress[hidden] { display: none; }
.alan-library-card__progress > span { display: block; height: 100%; width: calc(var(--reading-progress, 0) * 100%); background: var(--lib-ink); border-radius: inherit; }
.alan-library-card__progress.is-done > span { background: var(--lib-accent); }

/* ---------- The complete index: an editorial list, not a second gallery ---------- */
.alan-library-grid--index { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; border-top: 1px solid var(--lib-line); }
.alan-library-card--row { border-bottom: 1px solid var(--lib-line); }
.alan-library-card--row .alan-library-card__link {
  display: grid;
  grid-template-columns: clamp(140px, 15vw, 220px) minmax(0, 1fr) auto;
  grid-template-areas: "image meta date" "image title date" "image excerpt date" "image progress date";
  grid-template-rows: auto auto 1fr auto;
  align-items: start;
  column-gap: clamp(18px, 2.6vw, 44px);
  padding: clamp(16px, 1.8vw, 24px) 0;
  transition: background-color .35s;
}
.alan-library-card--row .alan-library-card__image { grid-area: image; border-radius: 12px; }
.alan-library-card--row .alan-library-card__enter { display: none; }
.alan-library-card--row .alan-library-card__meta { grid-area: meta; margin-top: 2px; }
.alan-library-card--row h3 { grid-area: title; margin-top: 6px; font-size: clamp(19px, 1.7vw, 26px); }
.alan-library-card--row .alan-library-card__excerpt { grid-area: excerpt; margin-top: 8px; }
.alan-library-card--row .alan-library-card__progress { grid-area: progress; max-width: 240px; }
.alan-library-card__date { grid-area: date; display: flex; align-items: center; gap: 18px; padding-top: 2px; font: 500 12px/1.4 var(--lib-sans); color: var(--lib-muted); white-space: nowrap; text-transform: capitalize; }
.alan-library-card__date > span { display: grid; place-items: center; width: 40px; height: 40px; border: 1px solid var(--lib-line); border-radius: 50%; color: var(--lib-ink); transition: transform .5s var(--alan-ease-out, ease), background-color .3s, color .3s; }
.alan-library-card--row .alan-library-card__link:is(:hover, :focus-visible) .alan-library-card__date > span { transform: translateX(6px); background: var(--lib-ink); color: var(--lib-paper); }
.alan-library-card--row .alan-library-card__link:is(:hover, :focus-visible) h3 { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 6px; }

/* ---------- Series pages: the opening settles in once ---------- */
@media (prefers-reduced-motion: no-preference) {
  html:not([data-alan-vt-arrival]) .alan-library[data-series-style] .alan-library-opening { animation: ea-rise 1s var(--alan-ease-out, ease) .08s backwards; }
}

@media (max-width: 1000px) {
  .alan-library[data-library-catalog] .ea-drift__copy { width: min(560px, 64%); }
}
@media (max-width: 700px) {
  .alan-library[data-library-catalog] .ea-drift { width: calc(100% - 16px); height: clamp(560px, 84svh, 720px); border-radius: 18px; }
  .alan-library[data-library-catalog] .ea-drift__copy { left: 22px; right: 22px; width: auto; bottom: 30px; }
  .alan-library[data-library-catalog] .ea-drift .ea-drift__copy h1 { font-size: clamp(52px, 15vw, 72px); }
  .alan-library[data-library-catalog] .ea-drift .ea-drift__description { font-size: 14px; }
  .ea-drift__stats { margin-bottom: 20px; column-gap: 14px; }
  .ea-drift__stats span + span::before { display: none; }
  .ea-drift__actions { gap: 14px; }
  .ea-drift__latest { max-width: 100%; width: 100%; }
  .alan-library[data-library-catalog] .ea-drift .ea-drift__pause { top: 16px; bottom: auto; }
  .alan-library-track .alan-library-card { flex-basis: 78vw; }
  .alan-library-card--row .alan-library-card__link { grid-template-columns: 112px minmax(0, 1fr); grid-template-areas: "image meta" "image title" "image progress"; grid-template-rows: auto auto 1fr; }
  .alan-library-card--row .alan-library-card__excerpt, .alan-library-card__date { display: none; }
  .alan-library-card--row h3 { font-size: 17px; -webkit-line-clamp: 3; }
}
@media (prefers-reduced-motion: reduce) {
  [data-glow]::before, .ea-drift__latest, .alan-library-card__date > span { transition: none; }
}
