/* District card (DistrictCard.jsx) - the state page's district grid and the district page's
   "more from this state" row. Tokens come from .epg in epmGallery.css. */

/* ---------- Grid ----------
   Rows always come out full: depending on how many cards there are (read with :nth-last-child,
   so it also holds for search results), the first one to three cards widen to two columns and
   take a panoramic crop. Every row shares one height (grid-auto-rows: 1fr), and a wide card's
   photo simply fills whatever its row leaves after the caption. */
.epg-district-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: clamp(12px, 1.6vw, 22px);
  list-style: none;
  margin: 0;
  padding: 0;
}

.epg-district-grid > li {
  display: flex;
  min-width: 0;
}

@media (min-width: 1181px) {
  .epg-district-grid > li:first-child:not(:nth-last-child(4n)),
  .epg-district-grid > li:nth-child(2):nth-last-child(4n),
  .epg-district-grid > li:nth-child(2):nth-last-child(4n + 1),
  .epg-district-grid > li:nth-child(3):nth-last-child(4n + 3) {
    grid-column: span 2;
    --epg-dcard-ratio: auto;
  }
}

@media (min-width: 821px) and (max-width: 1180px) {
  .epg-district-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .epg-district-grid > li:first-child:not(:nth-last-child(3n)),
  .epg-district-grid > li:nth-child(3):nth-last-child(3n + 2) {
    grid-column: span 2;
    --epg-dcard-ratio: auto;
  }
}

@media (max-width: 820px) {
  .epg-district-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .epg-district-grid > li:first-child:nth-last-child(2n + 1) {
    grid-column: span 2;
    --epg-dcard-ratio: auto;
  }
}

/* ---------- Card ---------- */
.epg-dcard {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 8px;
  border: 1px solid var(--epg-line);
  border-radius: var(--epg-radius-lg);
  background: var(--epg-surface);
  color: var(--epg-ink);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--epg-shadow-sm);
  transition:
    transform 0.5s var(--epg-ease),
    box-shadow 0.5s var(--epg-ease),
    border-color 0.3s;
}

.epg-dcard-media {
  position: relative;
  display: block;
  flex: 1 1 auto;
  min-height: 120px;
  aspect-ratio: var(--epg-dcard-ratio, 4 / 3);
  border-radius: 15px;
  overflow: hidden;
  isolation: isolate;
  background: var(--epg-sunken);
}

/* keeps the index and badge legible on bright skies */
.epg-dcard-media::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(5, 20, 13, 0.34) 0%, rgba(5, 20, 13, 0) 36%);
  pointer-events: none;
}

.epg-dcard-img {
  position: absolute;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 1.1s var(--epg-ease);
}

.epg-dcard-index {
  position: absolute;
  top: 13px;
  left: 15px;
  z-index: 1;
  font-family: var(--epg-font-text);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: rgba(255, 255, 255, 0.94);
  font-variant-numeric: tabular-nums;
}

.epg-dcard-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--epg-forest);
  font-family: var(--epg-font-text);
  font-size: 0.75rem;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(5, 20, 13, 0.16);
}

.epg-dcard-badge i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--epg-saffron);
}

.epg-dcard-body {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 8px 8px 10px;
}

.epg-dcard-text {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.epg-dcard-name {
  overflow: hidden;
  font-family: var(--epg-font-display);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.015em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.epg-dcard-meta {
  font-family: var(--epg-font-text);
  font-size: 0.8125rem;
  color: var(--epg-muted);
}

.epg-dcard-go {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--epg-line-strong);
  color: var(--epg-forest);
  transition: background-color 0.35s, border-color 0.35s, color 0.35s;
}

.epg-dcard-go svg {
  transition: transform 0.45s var(--epg-ease);
}

@media (hover: hover) {
  .epg-dcard:hover {
    transform: translateY(-4px);
    border-color: transparent;
    box-shadow: var(--epg-shadow-lg);
  }
  .epg-dcard:hover .epg-dcard-img { transform: scale(1.05); }
  .epg-dcard:hover .epg-dcard-go {
    background: var(--epg-forest);
    border-color: var(--epg-forest);
    color: #fff;
  }
  .epg-dcard:hover .epg-dcard-go svg { transform: translate(2px, -2px); }
}

.epg-dcard:focus-visible {
  outline: 3px solid var(--epg-saffron);
  outline-offset: 3px;
}

.epg-dcard.is-skeleton {
  cursor: default;
  box-shadow: none;
}

@media (max-width: 560px) {
  .epg-dcard {
    padding: 6px;
    border-radius: 18px;
  }
  .epg-dcard-media { border-radius: 13px; }
  .epg-dcard-body { padding: 11px 6px 6px; }
  .epg-dcard-name {
    font-size: 1.0625rem;
    white-space: normal;
  }
  .epg-dcard-meta { font-size: 0.75rem; }
  .epg-dcard-go,
  .epg-dcard-index { display: none; }
  .epg-dcard-badge {
    top: 8px;
    right: 8px;
    height: 24px;
    padding: 0 9px;
    font-size: 0.6875rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .epg-dcard,
  .epg-dcard-img,
  .epg-dcard-go,
  .epg-dcard-go svg {
    transition: none;
  }
  .epg-dcard:hover { transform: none; }
}
