.pdf-grid {
  display: grid;
  grid-template-columns: repeat(var(--pdf-cols, 4), minmax(0, 1fr));
  gap: 24px;
}

@media (max-width: 900px) {
  .pdf-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .pdf-grid { grid-template-columns: 1fr; }
}

/* Each card shares row tracks with its neighbours, so titles of different
   lengths no longer push thumbnails out of line */
.pdf-card {
  display: grid;
  grid-row: span 3;                 /* title, thumb, date */
  grid-template-rows: subgrid;
  row-gap: 0;                       /* don't inherit the 24px grid gap inside the card */
  text-decoration: none;
  color: inherit;
}

.pdf-card__thumb {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  position: relative;
  aspect-ratio: 8.5 / 11;           /* US Letter; use 1 / 1.414 for A4 */
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  transition: transform .2s ease, box-shadow .2s ease;
}

.pdf-card:hover .pdf-card__thumb,
.pdf-card:focus-visible .pdf-card__thumb {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0,0,0,.12);
}

.pdf-card__thumb img,
.pdf-card__canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  display: block;
}

.pdf-card__canvas { opacity: 0; transition: opacity .3s ease; }
.pdf-card.is-rendered .pdf-card__canvas { opacity: 1; }

.pdf-card__placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: .1em;
  color: #9ca3af;
}
.pdf-card.is-rendered .pdf-card__placeholder { display: none; }

.pdf-card__title {
  margin: 10px 0 10px;
  line-height: 1.3;
  text-transform: capitalize;
}

.pdf-card__date {
  margin: 0;
  font-size: .85rem;
  color: #6b7280;
  min-height: 1.2em;
}

/* Fallback for older browsers without subgrid: reserve 2 lines for the title */
@supports not (grid-template-rows: subgrid) {
  .pdf-card {
    display: flex;
    flex-direction: column;
  }
  .pdf-card__title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.6em;              /* 2 lines × 1.3 line-height */
  }
}