/**
 * iPin Modern — Masonry Grid
 * WCAG notes:
 *   - .masonry-actionbar is aria-hidden="true" (decorative overlay)
 *     and shown on hover + :focus-within so sighted keyboard users
 *     see it when the card title link is focused
 *   - Each <article> has aria-labelledby pointing to .thumbtitle
 *   - The sole keyboard-accessible link per card is .thumbtitle a
 *   - The image wrapper is a <div> (not <a>) to avoid nested links
 */

/* ── Grid wrapper ── */
#masonry-wrap {
  max-width: var(--max-grid);
  margin: 28px auto 0;
  padding: 0 24px;
  position: relative;
}

/* ── Masonry container ──
   opacity: 0 → 1 on init (not visibility: hidden) so the browser
   never has to repaint an invisible-then-visible shift.
   Elements at opacity:0 are still in the layout flow, so masonry
   can measure and position them before the fade-in fires — the
   visible paint never shows the un-positioned state. */
#masonry {
  margin: 0 auto;
  opacity: 0;
  transition: opacity .28s ease;
}

/* ── Individual card ── */
#masonry .thumb {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  width: var(--card-width);
  float: left;
  margin-left:  calc(var(--card-gap) / 2);
  margin-right: calc(var(--card-gap) / 2);
  margin-bottom: var(--card-gap);
  box-shadow: var(--card-shadow-custom, var(--shadow-sm));
  transition: transform var(--dur) var(--ease), box-shadow var(--dur), border-color var(--dur);
  will-change: transform;
}

#masonry .thumb:hover,
#masonry .thumb:focus-within {
  transform: translateY(-5px) scale(1.015);
  box-shadow: var(--shadow-lg);
  border-color: var(--clr-accent-1);
}

/* Sticky */
#masonry .sticky {
  border-color: var(--clr-accent-4);
  box-shadow: 0 0 0 2px var(--clr-accent-4), var(--shadow-md);
}

/* ── Thumbnail image wrapper (div — NOT an anchor) ── */
.thumb-img-wrap {
  display: block;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--bg-input);
  aspect-ratio: 3 / 4;
  cursor: pointer;
}
/* When a fixed image height is set, override aspect-ratio with exact height */
.thumb-img-wrap {
  height: var(--card-img-height, auto);
}
.thumb-img-wrap img {
  width: 100%;
  height: 100%;
  display: block;
  transition: transform var(--dur-slow) var(--ease);
  object-fit: cover;
  pointer-events: none;
}
#masonry .thumb:hover .thumb-img-wrap img,
#masonry .thumb:focus-within .thumb-img-wrap img { transform: scale(1.05); }

/* ── Hover action bar (decorative — aria-hidden="true" in HTML)
      Shown on hover AND focus-within so sighted keyboard users
      can see it. AT users navigate via the title link.
   ── */
.masonry-actionbar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(10,6,20,.52);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  opacity: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  transition: opacity var(--dur);
  pointer-events: none;
  z-index: 2;
}

#masonry .thumb:hover .masonry-actionbar,
#masonry .thumb:focus-within .masonry-actionbar {
  opacity: 1;
  pointer-events: auto;
}

.masonry-actionbar .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 16px;
  height: 36px;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: .78rem;
  font-weight: 700;
  line-height: 1;
  border: none;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
}
.btn-comment { background: var(--clr-accent-1); color: #fff; }
.btn-view    { background: var(--clr-accent-3); color: #fff; }

/* ── Pinterest Save button — corner overlay ── */
.pin-save-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #E60023;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  cursor: pointer;
  opacity: 0;
  transform: scale(.75);
  transition: opacity var(--dur), transform var(--dur);
  z-index: 3;
  border: none;
  text-decoration: none;
}

#masonry .thumb:hover .pin-save-btn,
#masonry .thumb:focus-within .pin-save-btn {
  opacity: 1;
  transform: scale(1);
}

.pin-save-btn:hover,
.pin-save-btn:focus-visible {
  background: #ad081b;
  outline: none;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #E60023;
}

/* ── Card body ── */
.thumb-body { padding: 12px 13px 9px; }

.thumbtitle {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: .88rem;
  line-height: 1.35;
  color: var(--txt-primary);
  text-align: center;
  margin-bottom: 8px;
}
.thumbtitle a { color: inherit; }
.thumbtitle a:hover { color: var(--clr-accent-1); }
/* Focus ring on card title link is provided by global :focus-visible */

/* ── Meta row ── */
.masonry-meta {
  border-top: 1px solid var(--border);
  padding: 7px 0 4px;
  color: var(--txt-secondary);
  font-size: .78rem;
  line-height: 1.45;
  display: flex;
  align-items: flex-start;
  gap: 7px;
}
.masonry-meta.text-center { justify-content: center; }
.masonry-meta-avatar { flex-shrink: 0; width: 24px; height: 24px; }
.masonry-meta-avatar img { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }
.masonry-meta-author { font-weight: 700; color: var(--txt-primary); }
.masonry-meta a { color: var(--txt-muted); font-style: italic; }
.masonry-meta a:hover { color: var(--clr-accent-1); }

/* ── AJAX / masonry loader ── */
#ajax-loader-masonry { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); }

.ajax-loader {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--clr-accent-1);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Infinite scroll bar ── */
#infscr-loading {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--grad-brand-btn);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-lg);
  padding: 10px 24px;
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .02em;
  white-space: nowrap;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

#infscr-loading em {
  font-style: normal;
}

@media (max-width: 600px) {
  #infscr-loading { bottom: 16px; padding: 9px 20px; font-size: .8rem; }
}


/* ── Pagination ── */
.pager {
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 0;
  margin: 24px 0 0;
}
.pager li a, .pager li span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: .85rem;
  border: 1.5px solid var(--border);
  color: var(--txt-secondary);
  background: var(--bg-card);
  transition: background var(--dur), color var(--dur), border-color var(--dur), transform var(--dur) var(--ease);
}
.pager li a:hover {
  background: var(--grad-brand-btn);
  color: #fff;
  border-color: transparent;
  transform: scale(1.03);
}

/* ── Empty state ── */
.empty-state { text-align: center; padding: 64px 24px; }
.empty-state .empty-icon { font-size: 4rem; margin-bottom: 18px; display: block; line-height: 1; }
.empty-state h1 {
  font-size: 1.6rem;
  background: var(--grad-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}
.empty-state p { color: var(--txt-secondary); margin-bottom: 24px; }

/* ── No-image placeholder ────────────────────────────────────
   Shown when a post has no featured image or attached image.
   Uses the brand gradient so it matches the active scheme and
   integrates with the hover action bar exactly like a real image.
   ──────────────────────────────────────────────────────────── */
.thumb-no-image {
  position: relative;
  width: 100%;
  /* 4:3-ish ratio — gives cards a readable height without being too tall */
  padding-bottom: 75%;
  background: var(--grad-brand);
  overflow: hidden;
}

/* Subtle noise texture using a radial gradient pattern */
.thumb-no-image::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,.12) 0%, transparent 55%),
    radial-gradient(circle at 80% 75%, rgba(0,0,0,.18) 0%, transparent 55%);
}

/* Large monogram letter — first character of the post title */
.thumb-no-image__initial {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: clamp(3.5rem, 20cqw, 5.5rem);
  font-weight: 800;
  color: rgba(255, 255, 255, .22);
  line-height: 1;
  letter-spacing: -.02em;
  user-select: none;
  /* Subtle text shadow gives depth */
  text-shadow: 0 4px 24px rgba(0,0,0,.18);
}

/* Small pin icon — bottom-right corner accent */
.thumb-no-image__icon {
  position: absolute;
  bottom: 10px;
  right: 12px;
  font-size: 1.1rem;
  opacity: .55;
  line-height: 1;
  user-select: none;
}

/* The action bar (Comment / View) overlays normally on hover */
#masonry .thumb:hover .thumb-no-image .masonry-actionbar,
#masonry .thumb:focus-within .thumb-no-image .masonry-actionbar {
  opacity: 1;
}

/* ── Responsive ── */
@media (max-width: 600px) { :root { --card-width: 155px; --card-gap: 10px; } }
@media (max-width: 420px) {
  #masonry .thumb { width: calc(100vw - 48px) !important; float: none; margin-left: 0; margin-right: 0; }
}


/* ── Popular posts sort bar ──────────────────────────── */
.sort-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 14px var(--grid-gap, 12px) 10px;
  position: sticky;
  top: var(--nav-height, 60px);
  z-index: 10;
  background: var(--bg-body);
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.sort-bar__btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  font-size: .78rem;
  font-weight: 600;
  color: var(--txt-secondary);
  text-decoration: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}

.sort-bar__btn:hover {
  color: var(--clr-accent-1);
  border-color: var(--clr-accent-1);
}

.sort-bar__btn.active,
.sort-bar__btn[aria-current="page"] {
  background: var(--clr-accent-1);
  color: #fff;
  border-color: transparent;
}

.sort-bar__btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
