/* ==========================================================================
   Riddle Educat – Gallery page (student achievement posters)
   Posters are shown in full (object-fit: contain) so no text is ever cropped.
   Loaded AFTER the page's inline <style>.
   ========================================================================== */

.rd-gallery {
  --rdg-navy: var(--primary, #0f2438);
  --rdg-gold: var(--accent, #c8962c);
  --rdg-gold-deep: var(--secondary, #a97a1e);
  --rdg-ink: var(--dark, #1e293b);
  --rdg-muted: var(--gray, #45566b);
  --rdg-line: #e3e8ef;
  --rdg-paper: #f3f5f9;
  max-width: 1300px;
  margin: 0 auto;
  padding: 36px 25px 96px;
}

/* ---------- Filters ---------- */
.rd-filters {
  position: relative;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 14px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--rdg-line);
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(15, 36, 56, .04), 0 12px 28px -18px rgba(15, 36, 56, .3);
}
.rd-filters[hidden] { display: none; }
.rd-filter-ind {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 999px;
  background: var(--rdg-navy);
  box-shadow: 0 8px 18px -8px rgba(15, 36, 56, .6), inset 0 -2px 0 var(--rdg-gold);
  transition: transform .5s cubic-bezier(.2, .8, .2, 1), width .5s cubic-bezier(.2, .8, .2, 1), height .5s ease;
  pointer-events: none;
  z-index: 0;
}
.rd-filter {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: var(--rdg-muted);
  font: inherit;
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
  transition: color .3s ease;
}
.rd-filter:hover { color: var(--rdg-navy); }
.rd-filter[aria-pressed="true"] { color: #fff; }
.rd-filter__n {
  font-size: .72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(15, 36, 56, .07);
  font-variant-numeric: tabular-nums;
  transition: background-color .3s ease, color .3s ease;
}
.rd-filter[aria-pressed="true"] .rd-filter__n { background: var(--rdg-gold); color: var(--rdg-navy); }
.rd-meta {
  text-align: center;
  margin: 0 0 30px;
  font-size: .85rem;
  color: var(--rdg-muted);
  min-height: 1.3em;
}
.rd-filter:focus-visible,
.rd-card:focus-visible,
.rd-lb__btn:focus-visible,
.rd-lb__open:focus-visible { outline: 2px solid var(--rdg-gold); outline-offset: 3px; }

/* ---------- Grid ---------- */
.rd-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 26px;
  align-items: start;
  transition: opacity .16s ease;
}
.rd-grid.is-switching { opacity: 0; }
.rd-grid > li[hidden] { display: none; }

.rd-card {
  display: block;
  width: 100%;
  padding: 0;
  text-align: left;
  font: inherit;
  color: inherit;
  background: #fff;
  border: 1px solid var(--rdg-line);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 36, 56, .04), 0 10px 24px -16px rgba(15, 36, 56, .24);
  transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateY(var(--ty, 0px));
  transition: transform .5s cubic-bezier(.2, .8, .2, 1), box-shadow .3s ease, border-color .3s ease;
  -webkit-tap-highlight-color: transparent;
}
.rd-card__media {
  display: block;
  position: relative;
  aspect-ratio: 5 / 6;               /* the posters are 5:6 portrait; others are letterboxed, never cropped */
  background: var(--rdg-paper);
  overflow: hidden;
}
.rd-card__img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform .8s cubic-bezier(.2, .8, .2, 1), opacity .3s ease;
}
.rd-card__img.is-loading { opacity: 0; }
.rd-card__zoom {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 36, 56, .86);
  color: #fff;
  font-size: .8rem;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.rd-card__body {
  display: block;
  padding: 14px 16px 16px;
  border-top: 1px solid var(--rdg-line);
}
.rd-card__title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  font-weight: 600;
  font-size: .94rem;
  line-height: 1.4;
  color: var(--rdg-navy);
}
.rd-card__tag {
  display: block;
  margin-top: 4px;
  font-size: .78rem;
  font-weight: 600;
  color: var(--rdg-gold-deep);
}

@media (hover: hover) {
  .rd-card:hover {
    --ty: -6px;
    border-color: rgba(200, 150, 44, .65);
    box-shadow: 0 2px 4px rgba(15, 36, 56, .06), 0 26px 44px -20px rgba(15, 36, 56, .42), 0 0 0 4px rgba(200, 150, 44, .08);
  }
  .rd-card.is-tilting { transition: transform .12s ease-out, box-shadow .3s ease, border-color .3s ease; }
  .rd-card:hover .rd-card__img { transform: scale(1.04); }
  .rd-card:hover .rd-card__zoom,
  .rd-card:focus-visible .rd-card__zoom { opacity: 1; transform: none; }
}

/* ---------- Editorial layout (desktop): a few featured posters span 2x2 ----------
   Row height is set by JS (--rd-row) so every card keeps the poster's 5:6 area;
   images stay object-fit: contain, so featured posters are never cropped either. */
@media (min-width: 900px) {
  .rd-grid { grid-auto-rows: var(--rd-row, 400px); grid-auto-flow: dense; align-items: stretch; }
  .rd-grid > li { min-height: 0; }
  .rd-card { height: 100%; display: flex; flex-direction: column; }
  .rd-card__media { aspect-ratio: auto; flex: 1 1 auto; min-height: 0; }
  .rd-card__body { flex: none; height: 92px; box-sizing: border-box; overflow: hidden; }
  .rd-grid > li.is-featured { grid-column: span 2; grid-row: span 2; }
  .is-featured .rd-card__title { font-size: 1.08rem; }
}


/* Cursor shine (soft highlight that follows the pointer while tilting) */
.rd-card__media::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--gx, 50%) var(--gy, 50%), rgba(255, 255, 255, .42), transparent 55%);
  mix-blend-mode: soft-light;
  opacity: 0;
  transition: opacity .35s ease;
  pointer-events: none;
}
.rd-card.is-tilting .rd-card__media::after { opacity: 1; }

/* Curtain reveal: each poster unveils top-to-bottom while its image settles from a slight zoom */
@media (scripting: enabled) {
  .rd-grid > li .rd-card__media { clip-path: inset(0 0 100% 0); }
  .rd-grid > li.is-visible .rd-card__media {
    clip-path: inset(0 0 0 0);
    transition: clip-path 1.05s cubic-bezier(.77, 0, .18, 1) calc(var(--d, 0ms) + 160ms);
  }
  :where(.rd-grid > li:not(.is-visible)) .rd-card__img { transform: scale(1.16); }
  .rd-grid > li .rd-card__body { opacity: 0; transform: translateY(8px); }
  .rd-grid > li.is-visible .rd-card__body {
    opacity: 1;
    transform: none;
    transition: opacity .6s ease calc(var(--d, 0ms) + 520ms), transform .7s cubic-bezier(.2, .8, .2, 1) calc(var(--d, 0ms) + 520ms);
  }
}

/* ---------- Scroll reveal ---------- */
@media (scripting: enabled) {
  .rd-grid > li {
    opacity: 0;
    transform: translateY(24px) scale(.97);
    transition: opacity .6s ease, transform .7s cubic-bezier(.2, .8, .2, 1);
    transition-delay: var(--d, 0ms);
  }
  .rd-grid > li.is-visible { opacity: 1; transform: none; }
}

.rd-empty { text-align: center; padding: 72px 20px; color: #7b879b; }
.rd-empty[hidden] { display: none; }
.rd-empty i { font-size: 2.6rem; display: block; margin-bottom: 14px; color: #c3ccda; }

/* ---------- Lightbox ---------- */
.rd-lb {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: rgba(8, 16, 30, .8);
  -webkit-backdrop-filter: blur(16px) saturate(.85);
  backdrop-filter: blur(16px) saturate(.85);
  opacity: 0;
  visibility: hidden;
  transition: opacity .22s ease, visibility 0s linear .22s;
  overscroll-behavior: contain;
}
.rd-lb.is-open { opacity: 1; visibility: visible; transition: opacity .22s ease; }

.rd-lb__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  color: #fff;
}
.rd-lb__count { font-size: .88rem; font-weight: 600; opacity: .8; font-variant-numeric: tabular-nums; }
.rd-lb__tools { display: flex; align-items: center; gap: 10px; }
.rd-lb__open {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .28);
  color: #fff;
  font-size: .82rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color .2s ease;
}
.rd-lb__open:hover { background: rgba(255, 255, 255, .12); }

.rd-lb__btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .22);
  background: rgba(255, 255, 255, .08);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color .2s ease;
}
.rd-lb__btn:hover { background: rgba(255, 255, 255, .2); }

.rd-lb__stage {
  position: relative;
  min-height: 0;
  padding: 0 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pinch-zoom;          /* we handle horizontal swipes ourselves; pinch-zoom stays native */
}
.rd-lb__fig {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rd-lb__img {
  display: block;
  flex: 0 1 auto;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .07), 0 0 90px rgba(200, 150, 44, .22), 0 30px 80px rgba(0, 0, 0, .6);
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity .2s ease;
}
.rd-lb__img.is-loading { opacity: .25; }
.rd-lb__nav { position: absolute; top: 50%; transform: translateY(-50%); }
.rd-lb__prev { left: 14px; }
.rd-lb__next { right: 14px; }

.rd-lb__cap {
  padding: 14px 20px 20px;
  text-align: center;
  color: #fff;
  min-height: 24px;
  transition: opacity .45s ease .3s;
}
.rd-lb:not(.is-open) .rd-lb__cap { opacity: 0; transition-delay: 0s; }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .rd-lb { background: rgba(8, 16, 30, .96); }
}
.rd-lb__title { font-size: .98rem; font-weight: 600; line-height: 1.4; }
.rd-lb__tag { margin-top: 2px; font-size: .8rem; color: var(--rdg-gold); font-weight: 600; }


/* Lightbox ambience, caption motion, filmstrip */
.rd-lb::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 42%, rgba(200, 150, 44, .17), transparent 62%);
  pointer-events: none;
}
.rd-lb > * { position: relative; z-index: 1; }
.rd-cap-in { animation: rd-cap .55s cubic-bezier(.2, .8, .2, 1) both; }
.rd-lb__tag.rd-cap-in { animation-delay: .06s; }
@keyframes rd-cap { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.rd-lb__thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 14px 4px 2px;
  scrollbar-width: none;
}
.rd-lb__thumbs[hidden] { display: none; }
.rd-lb__thumbs::-webkit-scrollbar { display: none; }
.rd-lb__thumbs > :first-child { margin-left: auto; }
.rd-lb__thumbs > :last-child { margin-right: auto; }
.rd-thumb {
  flex: none;
  width: 44px;
  height: 54px;
  padding: 0;
  border-radius: 7px;
  border: 2px solid transparent;
  background: #0b1626;
  overflow: hidden;
  opacity: .5;
  cursor: pointer;
  transition: opacity .3s ease, border-color .3s ease, transform .3s cubic-bezier(.2, .8, .2, 1);
}
.rd-thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
.rd-thumb:hover { opacity: .85; }
.rd-thumb.is-active { opacity: 1; border-color: var(--rdg-gold); transform: translateY(-3px); }
.rd-thumb:focus-visible { outline: 2px solid var(--rdg-gold); outline-offset: 2px; }
@media (max-width: 700px) {
  .rd-thumb { width: 34px; height: 42px; }
  .rd-meta { margin-bottom: 22px; }
  .rd-filters { width: auto; margin-left: 0; margin-right: 0; overflow-x: auto; flex-wrap: nowrap; justify-content: flex-start; scrollbar-width: none; }
  .rd-filters::-webkit-scrollbar { display: none; }
}

body.rd-lb-lock { overflow: hidden; }

@media (max-width: 700px) {
  .rd-gallery { padding: 28px 16px 72px; }
  .rd-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .rd-card__body { padding: 10px 12px 12px; }
  .rd-card__title { font-size: .84rem; }
  .rd-card__tag { font-size: .72rem; }
  .rd-filter { flex: none; }
  .rd-lb__stage { padding: 0 8px; }
  .rd-lb__nav { top: auto; bottom: 8px; transform: none; width: 40px; height: 40px; background: rgba(10, 22, 36, .7); }
  .rd-lb__prev { left: 12px; }
  .rd-lb__next { right: 12px; }
}
@media (max-width: 380px) {
  .rd-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .rd-grid > li .rd-card__media { clip-path: none !important; transition: none !important; }
  .rd-grid > li .rd-card__body { opacity: 1 !important; transform: none !important; transition: none !important; }
  .rd-filter-ind, .rd-thumb, .rd-cap-in, .rd-card__media::after { transition: none !important; animation: none !important; }
  .rd-grid,
  .rd-grid > li,
  .rd-card,
  .rd-card__img,
  .rd-card__zoom,
  .rd-lb,
  .rd-lb__img {
    transition: none !important;
    transform: none !important;
  }
  .rd-grid > li { opacity: 1 !important; }
}
