/* ════════════════════════════════════════════════════════════════
   WORK — STICKY CARD STACK
   Drop-in replacement for the old .work-strip image gallery.
   Ported from the "tatianaleon-astro-v2-hostinger-motion" prototype
   (AETHEREAL sticky card stack), restyled to THIS site's existing
   palette + typography (Cormorant Garamond display, DM Sans body).

   Linked ONLY on the homepage — index.astro injects it through Base's
   `<slot name="head" />`, so other pages never download it. All custom
   properties (--graphite, --olive, --sp-*, etc.) come from global.css
   :root, which loads first.
   ════════════════════════════════════════════════════════════════ */

.stack-section {
  background: var(--graphite);
  color: var(--chalk);
  padding: var(--sp-24) 0 0;
  position: relative;
  scroll-margin-top: var(--nav-h);
}

/* ── Header ──────────────────────────────────────────────────── */
.stack-header {
  max-width: var(--max-w);
  margin: 0 auto var(--sp-16);
  padding: 0 var(--sp-12);
  text-align: center;
}
.stack-section .section-label { color: var(--olive-soft); }
.stack-title {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(2rem, 3vw, var(--sz-4xl));
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--chalk);
  margin-top: var(--sp-4);
}

/* ── Stack container + sticky cards ──────────────────────────── */
.stack-container {
  width: 100%;
  /* "Gallery Frame" redesign (2026-07, option chosen by Rodrigo after two
     side-by-side iterations): the photo now sits ON TOP at full card width,
     so the canvas narrows to keep its landscape crop gentle (~1.8:1). */
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 var(--sp-6) var(--sp-12);
  position: relative;
}
.card-item {
  position: sticky;
  top: calc(var(--nav-h) + 1.5rem);
  /* 80vh → 88vh: buys the photo ~90px more height (still clears the sticky
     offset: 92px + 88vh ≈ 1042px on a 1080p display). */
  height: 88vh;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 5vh;
}
.card-item:last-child { margin-bottom: 0; }

.card-inner {
  width: 100%;
  height: 100%;
  background: var(--graphite-2);
  border: 1px solid rgba(247, 244, 240, 0.08);
  position: relative;
  overflow: hidden;
  display: grid;
  /* Gallery Frame: single column, two rows — the photo fills every pixel the
     text row doesn't need (~660px tall on a 1080p display → a true landscape
     stage for the 4:3/3:2 interior shots, no more portrait cropping). */
  grid-template-columns: 1fr;
  grid-template-rows: 1fr auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
  transform-origin: center;
  /* transform/opacity are set inline by the scroll handler */
}

/* ── Card content (left column) ──────────────────────────────── */
.card-content {
  /* Gallery Frame: a two-column placard row UNDER the photo — title block
     (num/title/meta) on the left, description + CTA on the right. Named
     areas keep it pure CSS; the ≤900px block resets this to the stacked
     mobile layout. */
  grid-row: 2;
  padding: var(--sp-8) var(--sp-10);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr);
  grid-template-areas:
    "head desc"
    "head link";
  column-gap: var(--sp-12);
  row-gap: var(--sp-4);
  align-items: start;
  background: var(--graphite-2);
  border-top: 1px solid rgba(247, 244, 240, 0.08);
  z-index: 2;
}
.card-head { grid-area: head; }
.card-num {
  display: block;
  font-family: var(--font-display);
  font-weight: 300;
  font-size: var(--sz-3xl);
  line-height: 1;
  color: var(--chalk);
  opacity: 0.22;
  margin-bottom: var(--sp-3);
}
.card-title {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(1.6rem, 2.4vw, var(--sz-3xl));
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--chalk);
}
.card-meta {
  font-size: var(--sz-xs);
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  color: rgba(247, 244, 240, 0.55);
  margin-top: var(--sp-4);
}
.card-desc {
  grid-area: desc;
  font-size: var(--sz-md);
  font-weight: 300;
  line-height: 1.8;
  color: rgba(247, 244, 240, 0.62);
  max-width: 65ch;              /* readable measure (65–75ch rule) */
  display: -webkit-box;
  -webkit-line-clamp: 3;        /* short placard row — 3 lines, not 6 */
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-link {
  grid-area: link;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  width: max-content;
  min-height: 44px;
  font-size: var(--sz-xs);
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  color: var(--chalk);
  border-bottom: 1px solid rgba(247, 244, 240, 0.3);
  padding-bottom: var(--sp-2);
  transition: color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
.card-link:hover { color: var(--olive-soft); border-color: var(--olive-soft); }

/* ── Card image (right column) ───────────────────────────────── */
.card-img-wrap {
  grid-row: 1;                  /* photo on top (markup has it second) */
  min-height: 0;                /* let the 1fr row size it, not the image */
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.card-img {
  width: 100%;
  height: 100%;
  /* contain, not cover (Rodrigo: "fit the picture to the space" — the covers
     are mixed 4:3 / 16:9 and cover-cropping mangled some). The WHOLE photo
     always shows, letterboxed on the graphite card like a matted gallery
     print. The ≤900px block restores cover for the approved mobile layout. */
  object-fit: contain;
  transition: transform 1.5s var(--ease-out);
}
.card-inner:hover .card-img { transform: scale(1.06); }

/* ── Closing CTA ─────────────────────────────────────────────── */
.stack-cta {
  text-align: center;
  padding: var(--sp-16) var(--sp-6) var(--sp-24);
}
.stack-cta-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 48px;
  font-size: var(--sz-xs);
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  color: var(--chalk);
  border: 1px solid rgba(247, 244, 240, 0.3);
  padding: 1rem 2.75rem;
  transition: background var(--dur-mid) ease, color var(--dur-mid) ease,
              border-color var(--dur-mid) ease;
}
.stack-cta-link:hover {
  background: var(--chalk);
  color: var(--graphite);
  border-color: var(--chalk);
}

/* ── Tablet / mobile (≤900px): drop the sticky stack ─────────────
   On small screens the sticky-overlap + scale/opacity depth effect (gated off
   in the index.astro script at ≤900px) looks cramped and the photo gets tiny.
   Instead: plain stacked cards, image-forward — a big full-width photo on top
   at a fixed 3:2 ratio, with the text below. The photo is the star again. */
@media (max-width: 900px) {
  .stack-section { padding-top: var(--sp-20); }
  .stack-header { margin-bottom: var(--sp-12); }
  .stack-container { padding: 0 var(--sp-6) var(--sp-12); }

  .card-item {
    position: static;            /* no more sticky */
    height: auto;
    margin-bottom: var(--sp-8);
  }
  .card-inner {
    grid-template-columns: 1fr;  /* single column, image stacked above text */
    box-shadow: 0 16px 32px -16px rgba(0, 0, 0, 0.6);
  }
  /* Plain (non-stacking) mode: clear any inline transform from the JS. */
  .stack-section:not(.stack-mobile) .card-inner {
    transform: none !important;
    opacity: 1 !important;
  }

  /* Stacking mode (`.stack-mobile`, set by the index.astro script only when
     every card fits the screen below the nav, and never under reduced motion):
     cards pin under the nav and the next one slides over. Each card pins
     10px lower than the one before, so the covered cards (shrunk + dimmed by
     the script, anchored at their top edge) peek out above like a deck of
     prints. Featured cards are capped at 4, hence nth-child. */
  .stack-section.stack-mobile .card-item {
    position: sticky;
    top: calc(var(--nav-h) + var(--sp-4));
  }
  .stack-section.stack-mobile .card-item:nth-child(2) { top: calc(var(--nav-h) + var(--sp-4) + 10px); }
  .stack-section.stack-mobile .card-item:nth-child(3) { top: calc(var(--nav-h) + var(--sp-4) + 20px); }
  .stack-section.stack-mobile .card-item:nth-child(4) { top: calc(var(--nav-h) + var(--sp-4) + 30px); }
  .stack-section.stack-mobile .card-inner {
    transform-origin: center top;
    /* a soft shadow on the TOP edge too, so the arriving card reads as
       lying on top of the one it covers */
    box-shadow: 0 -14px 28px -14px rgba(0, 0, 0, 0.55),
                0 16px 32px -16px rgba(0, 0, 0, 0.6);
  }
  /* The dim: a solid graphite veil whose opacity the script drives through
     --dim. The card underneath stays fully opaque, so nothing shows through. */
  .stack-section.stack-mobile .card-inner::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--graphite);
    opacity: var(--dim, 0);
    pointer-events: none;
    z-index: 3;                  /* above .card-content (z-index 2) */
  }
  .card-img-wrap {
    order: -1;                   /* image on top */
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 2;         /* generous, consistent photo size */
  }
  .card-img { object-fit: cover; }  /* mobile keeps the approved cover crop */
  .card-content {
    /* Reset the desktop placard grid back to the original stacked column —
       mobile is user-approved as-is and must not change. */
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    grid-template-areas: none;
    border-top: none;
    padding: var(--sp-8);
    gap: var(--sp-4);
  }
  .card-num { font-size: var(--sz-2xl); margin-bottom: var(--sp-1); }
  .card-desc { -webkit-line-clamp: 3; line-clamp: 3; }
}

/* ── Tablet / mobile (≤900px): scroll-in reveal ──────────────────
   Replaces the desktop depth effect on small screens. Each card rises
   32px and fades in as it enters the viewport, while its photo settles
   from a slight zoom (1.06 → 1), like a print being laid down. The text
   follows a beat later. Timing matches the site's [data-reveal] system
   (--dur-slow, --ease-out). Animates the OUTER .card-item so it never
   fights the inline styles the desktop script writes on .card-inner.
   `.js-reveal` is added by the index.astro script, so without JS (or
   without IntersectionObserver) the cards are simply visible.
   In stacking mode the card itself doesn't fade (a see-through card sliding
   over the previous one looks muddy); only the photo settle + text follow. */
@media (max-width: 900px) and (prefers-reduced-motion: no-preference) {
  .stack-section.js-reveal:not(.stack-mobile) .card-item {
    opacity: 0;
    transform: translateY(32px);
    transition: opacity var(--dur-slow) var(--ease-out),
                transform 900ms var(--ease-out);
  }
  .stack-section.js-reveal .card-img {
    transform: scale(1.06);
    transition: transform 1.4s var(--ease-out);
  }
  .stack-section.js-reveal .card-content {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity var(--dur-slow) var(--ease-out) 150ms,
                transform var(--dur-slow) var(--ease-out) 150ms;
  }
  .stack-section.js-reveal .card-item.in-view,
  .stack-section.js-reveal .card-item.in-view .card-content {
    opacity: 1;
    transform: none;
  }
  /* Also wins over the desktop :hover zoom, which "sticks" after a tap. */
  .stack-section.js-reveal .card-item.in-view .card-img { transform: scale(1); }
}

/* ── Reduced motion: no sticky overlap, no transforms ────────── */
@media (prefers-reduced-motion: reduce) {
  .card-item {
    position: static;
    height: auto;
    margin-bottom: var(--sp-8);
  }
  .card-inner {
    transform: none !important;
    opacity: 1 !important;
    min-height: 60vh;
  }
  .card-img { transition: none; }
  .card-inner:hover .card-img { transform: none; }
}
