/* ── INSTAGRAM WIDGET ──────────────────────────────────────────────────────
   Layout / hover variants for /js/instagram-widget.js.
   Uses the design tokens declared in main.css — no new palette here.
   ------------------------------------------------------------------------ */

.ig-widget {
  --ig-cols: 3;
  --ig-gap: 1rem;
  margin-top: 2.5rem;
}

.ig-widget.ig-cols-2 { --ig-cols: 2; }
.ig-widget.ig-cols-3 { --ig-cols: 3; }
.ig-widget.ig-cols-4 { --ig-cols: 4; }

/* ── LAYOUT: GRID ── */
.ig-widget.ig-layout-grid {
  display: grid;
  grid-template-columns: repeat(var(--ig-cols), 1fr);
  gap: var(--ig-gap);
}

/* ── LAYOUT: HERO ──
   First post is featured at 2x2; the rest fill the remaining cells at 1x1.
   Unlike the grid layout, every tile is cropped to a square so the mosaic
   tiles cleanly — mixed portrait/landscape posts would otherwise leave holes.
   Needs at least 3 columns to have a "rest" column, so it floors at 3. */
.ig-widget.ig-layout-hero {
  display: grid;
  grid-template-columns: repeat(max(3, var(--ig-cols)), 1fr);
  gap: var(--ig-gap);
}
/*
 * The square media box is what sizes the grid rows. A 2x2 feature then spans
 * two rows plus the gap, which equals two columns plus the gap — so it stays
 * square without being told to. Keep the aspect-ratio on the media box, not
 * the tile, or an enabled caption would break the ratio.
 */
.ig-widget.ig-layout-hero .ig-post-media { aspect-ratio: 1 / 1; }
.ig-widget.ig-layout-hero .ig-post-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ig-widget.ig-layout-hero .ig-post-featured {
  grid-column: span 2;
  grid-row: span 2;
}
/*
 * A 2-row span is taller than the feature's square media plus one caption,
 * so the tile has slack. Rather than leaving that as dead space, let the
 * feature's image absorb it: drop the square constraint and have the media
 * box grow to fill whatever the caption does not use.
 */
.ig-widget.ig-layout-hero .ig-post {
  display: flex;
  flex-direction: column;
}
/* 1x1 tiles hug their own content instead of stretching to the taller row,
   which is what left a gap under their caption. */
.ig-widget.ig-layout-hero .ig-post:not(.ig-post-featured) { align-self: start; }
/* The feature does stretch across both rows, and its image takes up whatever
   slack the caption leaves rather than showing as dead space. */
.ig-widget.ig-layout-hero .ig-post-featured .ig-post-media {
  aspect-ratio: auto;
  flex: 1 1 auto;
  min-height: 0;
}
.ig-widget.ig-layout-hero .ig-post-meta { flex-shrink: 0; }
/* The featured tile earns a slightly louder caption. */
.ig-widget.ig-layout-hero .ig-post-featured .ig-post-caption { font-size: 0.86rem; }

/* ── LAYOUT: CAROUSEL (CSS scroll-snap, no JS) ── */
.ig-widget.ig-layout-carousel {
  display: flex;
  gap: var(--ig-gap);
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-padding-left: 0;
  padding-bottom: 0.75rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--light) transparent;
}
.ig-widget.ig-layout-carousel .ig-post {
  flex: 0 0 calc((100% - (var(--ig-cols) - 1) * var(--ig-gap)) / var(--ig-cols));
  scroll-snap-align: start;
}
.ig-widget.ig-layout-carousel::-webkit-scrollbar { height: 6px; }
.ig-widget.ig-layout-carousel::-webkit-scrollbar-track { background: transparent; }
.ig-widget.ig-layout-carousel::-webkit-scrollbar-thumb {
  background: var(--light); border-radius: 3px;
}
.ig-widget.ig-layout-carousel:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }

/* ── TILE ── */
.ig-post {
  border-radius: 0.5rem;
  overflow: hidden;
  background: var(--white);
  position: relative;
}
.ig-post-clickable { cursor: pointer; }
.ig-post-clickable:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }

.ig-post-media { position: relative; overflow: hidden; line-height: 0; }
.ig-post-media img {
  width: 100%;
  /* Tiles carry width/height attributes from the media manifest so the grid
     reserves the right box before the image decodes. height:auto keeps those
     attributes advisory — without it the box takes the source's full pixel
     height instead of scaling to the column. */
  height: auto;
  display: block;
  transition: transform 0.3s, opacity 0.3s;
}

/* ── PLACEHOLDER ──
   A shimmering skeleton holds the tile while its image decodes, then the
   image fades in over it. .ig-loading is removed by the widget on load.
   (A true blur-up would need a low-res thumbnail generated at sync time,
   which would mean an image library in the pipeline.) */
/* Reserve space while the image is pending. Without this the media box has no
   intrinsic size until the image decodes, so lazy-loaded tiles collapse to the
   caption height and the grid jumps when they arrive. Released on load so the
   grid layout keeps each post's natural aspect ratio. */
.ig-post-media.ig-loading { aspect-ratio: 1 / 1; }
.ig-post-media.ig-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, var(--light) 30%, var(--cream) 50%, var(--light) 70%);
  background-size: 220% 100%;
  animation: igShimmer 1.4s ease-in-out infinite;
}
.ig-post-media.ig-loading img { opacity: 0; }
.ig-post-media img { opacity: 1; }

@keyframes igShimmer {
  0%   { background-position: 120% 0; }
  100% { background-position: -120% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ig-post-media.ig-loading::after { animation: none; background: var(--light); }
}

/* ── VIDEO / REEL INDICATOR ── */
.ig-post-badge {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 26, 26, 0.55);
  color: var(--white);
  line-height: 0;
  pointer-events: none;
}
.ig-post-badge svg { display: block; margin-left: 1px; }

/* ── OVERLAY ── */
.ig-post-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.ig-post-overlay span {
  color: var(--white);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.2s;
}
.ig-post-clickable:hover .ig-post-overlay,
.ig-post-clickable:focus-visible .ig-post-overlay { background: rgba(0, 0, 0, 0.25); }
.ig-post-clickable:hover .ig-post-overlay span,
.ig-post-clickable:focus-visible .ig-post-overlay span { opacity: 1; }

/* ── HOVER STYLES ── */
.ig-hover-zoom .ig-post-clickable:hover .ig-post-media img,
.ig-hover-zoom .ig-post-clickable:focus-visible .ig-post-media img { transform: scale(1.04); }

.ig-hover-fade .ig-post-clickable:hover .ig-post-media img,
.ig-hover-fade .ig-post-clickable:focus-visible .ig-post-media img { opacity: 0.75; }

.ig-hover-none .ig-post-media img { transition: none; }

/* ── CAPTION / DATE ── */
.ig-post-meta { padding: 0.7rem 0.75rem 0.85rem; border-top: 1px solid var(--light); }
.ig-post-caption {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--mid);
}
.ig-post-date {
  font-family: var(--font-sans);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--green);
  margin-top: 0.35rem;
}
.ig-post-caption + .ig-post-date { margin-top: 0.4rem; }

/* ── ENTRANCE ANIMATIONS ──
   Tiles start hidden and get .ig-anim-in when scrolled into view.
   --ig-i is the tile index, capped in JS, so the reveal staggers.
   Note the failsafe in the reduced-motion block below: if animation is
   suppressed the tiles must still be visible, never stuck at opacity 0. */
.ig-anim {
  opacity: 0;
  will-change: opacity, transform;
  transition:
    opacity   0.55s cubic-bezier(0.22, 0.61, 0.36, 1),
    transform 0.55s cubic-bezier(0.22, 0.61, 0.36, 1);
  transition-delay: calc(var(--ig-i, 0) * 65ms);
}
.ig-anim-rise { transform: translateY(18px); }
.ig-anim-zoom { transform: scale(0.94); }
/* .ig-anim-fade needs no transform — opacity alone. */

.ig-anim.ig-anim-in {
  opacity: 1;
  transform: none;
}

/* ── CTA ── */
.ig-cta { margin-top: 1.75rem; }

/* ── RESPONSIVE — matches the main.css breakpoint where .social-grid
      drops to two columns ── */
@media (max-width: 960px) {
  .ig-widget.ig-cols-3,
  .ig-widget.ig-cols-4 { --ig-cols: 2; }
}

@media (max-width: 600px) {
  .ig-widget { --ig-gap: 0.75rem; }
  .ig-widget.ig-layout-carousel .ig-post { flex-basis: 78%; }

  /* Two columns leaves no room for a 2x2 feature — give the hero the full
     width and let the rest run 2-up beneath it. */
  .ig-widget.ig-layout-hero { grid-template-columns: repeat(2, 1fr); }
  .ig-widget.ig-layout-hero .ig-post-featured {
    grid-column: 1 / -1;
    grid-row: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ig-post-media img { transition: none; }
  .ig-post-clickable:hover .ig-post-media img { transform: none; }
  .ig-widget.ig-layout-carousel { scroll-behavior: auto; }

  /* Content over motion — show every tile immediately, no transition. */
  .ig-anim {
    opacity: 1;
    transform: none;
    transition: none;
    transition-delay: 0s;
  }
}
