/* Blog & Resources page */
body {
  background: #D2FFFB;
  margin: 0;
  padding: 0;
  position: relative;
  overflow-x: hidden;
}

/* Scoped to page content only, so the shared navbar/footer keep their own
   typography (same approach as volunteer.css). */
.blog-page,
.blog-modal {
  font-family: 'Zain', 'Zain Fallback', Arial, sans-serif;
  line-height: 1.6;
}

.blog-page {
  min-height: 100vh;
  padding: 160px 20px 60px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.hand-drawn-border {
  width: 100%;
  max-width: 1400px;
  min-width: 0;
  background: white;
  border: 4px solid #12A89C;
  border-radius: 20px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(18, 168, 156, 0.15);
  box-sizing: border-box;
}

.content-wrapper {
  padding: 40px;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

/* Header */
.blog-header {
  text-align: center;
  margin-bottom: 48px;
}

.blog-header h1 {
  font-family: 'Amatic SC', cursive;
  font-size: 3.5rem;
  color: #333;
  margin: 0 0 20px;
  font-weight: 700;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.blog-header p {
  font-family: 'Zain', cursive;
  font-size: 1.3rem;
  color: #666;
  max-width: 640px;
  margin: 0 auto;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Card grid — flex wrap + center so incomplete last rows (orphan cards)
   stay centred instead of left-aligned under a multi-column grid. */
.blog-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: stretch;
  gap: 28px;
  width: 100%;
}

.blog-card {
  /* Grow equally in a row up to 340px; shrink on narrow screens. */
  flex: 1 1 280px;
  width: min(340px, 100%);
  max-width: 340px;
  background: #fff;
  border: 1px solid #e8f5f3;
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
  box-shadow: 0 4px 18px rgba(18, 168, 156, 0.08);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.blog-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 28px rgba(18, 168, 156, 0.18);
}

.blog-card__media {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #eef8f7;
  overflow: hidden;
}

.blog-card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.blog-card__media-empty {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9fd4cf;
}

.blog-card__body {
  padding: 22px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex-grow: 1;
  min-width: 0;
}

.blog-card__title {
  font-family: 'Amatic SC', cursive;
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1.2;
  color: #333;
  margin: 0;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  /* A very long subject is trimmed on the card; the popup shows it in full. */
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.blog-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: auto;
}

.blog-card__btn {
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  font-family: 'Zain', cursive;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  box-sizing: border-box;
  transition: background 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease, color 0.3s ease;
}

.blog-card__btn--description {
  background: #FF9801;
  color: #fff;
  flex: 1 1 150px;
}

.blog-card__btn--description:hover {
  background: #ffb300;
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(255, 152, 1, 0.3);
}

.blog-card__btn--resource {
  background: #12A89C;
  color: #fff;
  flex: 1 1 150px;
}

.blog-card__btn--resource:hover {
  background: #0D948A;
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(18, 168, 156, 0.3);
}

.blog-card__btn:focus-visible {
  outline: 3px solid #0D948A;
  outline-offset: 2px;
}

.blog-card__btn--resource:focus-visible {
  outline-color: #FF9801;
}

/* Empty state */
.blog-empty {
  text-align: center;
  padding: 50px 20px 60px;
  color: #12A89C;
}

.blog-empty h2 {
  font-family: 'Amatic SC', cursive;
  font-size: 2.4rem;
  color: #333;
  margin: 16px 0 10px;
}

.blog-empty p {
  font-family: 'Zain', cursive;
  font-size: 1.15rem;
  color: #666;
  max-width: 480px;
  margin: 0 auto;
}

/* Description modal */
.blog-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1400;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  padding: 24px 16px;
  box-sizing: border-box;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  align-items: center;
  justify-content: center;
}

.blog-modal.is-open {
  display: flex;
}

.blog-modal__dialog {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  /* Explicit viewport cap (vh + dvh) so the dialog never spills past the screen.
     min-height: 0 lets the flex body shrink and scroll internally. */
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  /* fill-mode both keeps the settled end state (no leftover translate). */
  animation: blogModalIn 0.3s ease-out both;
  margin: 0;
  box-sizing: border-box;
  min-height: 0;
  flex-shrink: 1;
}

@keyframes blogModalIn {
  from {
    opacity: 0;
    /* Small rise only — large translates can spill past short viewports mid-animation. */
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .blog-modal__dialog {
    animation: none;
  }

  .blog-card,
  .blog-card__btn {
    transition: none;
  }
}

.blog-modal__header {
  background: #12A89C;
  color: #fff;
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-shrink: 0;
}

.blog-modal__title {
  margin: 0;
  font-family: 'Amatic SC', cursive;
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1.2;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  min-width: 0;
  /* A very long subject scrolls inside the header instead of squeezing the
     description out of view on small screens. The close button stays put. */
  max-height: 30vh;
}

.blog-modal__close {
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.blog-modal__close:hover {
  transform: scale(1.1);
}

.blog-modal__close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
  border-radius: 4px;
}

.blog-modal__body {
  padding: 28px 24px 32px;
  overflow-y: auto;
  overflow-wrap: anywhere;
  flex: 1;
  color: #444;
  font-size: 1.05rem;
  line-height: 1.75;
}

.blog-modal__body:focus-visible {
  outline: 2px solid #12A89C;
  outline-offset: -4px;
}

.blog-modal__body::-webkit-scrollbar {
  width: 8px;
}

.blog-modal__body::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.blog-modal__body::-webkit-scrollbar-thumb {
  background: #12A89C;
  border-radius: 4px;
}

/* ── Formatted description ──
   Scoped to the popup body, and covering exactly the elements the server-side
   allowlist can emit. The body's own colour, size and line height still set
   the baseline; these rules only give the block elements their rhythm. */
.blog-modal__body > :first-child {
  margin-top: 0;
}

.blog-modal__body > :last-child {
  margin-bottom: 0;
}

.blog-modal__body p {
  margin: 0 0 1em;
}

.blog-modal__body h2,
.blog-modal__body h3,
.blog-modal__body h4,
.blog-modal__body h5 {
  margin: 1.5em 0 0.5em;
  color: #1c3f3c;
  font-weight: 700;
  line-height: 1.3;
}

.blog-modal__body h2 {
  font-size: 1.35rem;
}

.blog-modal__body h3 {
  font-size: 1.18rem;
}

.blog-modal__body h4,
.blog-modal__body h5 {
  font-size: 1.06rem;
}

.blog-modal__body ul,
.blog-modal__body ol {
  margin: 0 0 1em;
  padding-left: 1.5em;
}

.blog-modal__body li {
  margin-bottom: 0.4em;
}

.blog-modal__body li:last-child {
  margin-bottom: 0;
}

.blog-modal__body blockquote {
  margin: 1.25em 0;
  padding: 0.25em 0 0.25em 1em;
  border-left: 3px solid #12A89C;
  color: #33605c;
  font-style: italic;
}

.blog-modal__body a {
  color: #0f8c82;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.blog-modal__body a:hover,
.blog-modal__body a:focus-visible {
  color: #0b6b63;
}

.blog-modal__body strong,
.blog-modal__body b {
  color: #1c3f3c;
  font-weight: 700;
}

.blog-modal__body em,
.blog-modal__body i {
  font-style: italic;
}

.blog-modal__body u {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Scroll lock while the modal is open */
body.blog-modal-open {
  overflow: hidden;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .content-wrapper {
    padding: 32px;
  }

  .blog-grid {
    gap: 24px;
  }

  .blog-card {
    flex-basis: 260px;
  }
}

@media (max-width: 900px) {
  .blog-page {
    padding: 140px 16px 50px;
  }
}

@media (max-width: 768px) {
  .blog-page {
    padding: 130px 14px 46px;
  }

  .content-wrapper {
    padding: 26px 20px 32px;
  }

  .blog-header {
    margin-bottom: 36px;
  }

  .blog-header h1 {
    font-size: 2.5rem;
  }

  .blog-header p {
    font-size: 1.1rem;
  }

  .blog-grid {
    gap: 20px;
  }

  .blog-card {
    flex-basis: min(280px, 100%);
  }

  .blog-card__title {
    font-size: 1.75rem;
  }

  .blog-modal {
    padding: 16px 12px;
  }

  .blog-modal__dialog {
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
  }

  .blog-modal__header {
    padding: 16px 18px;
  }

  .blog-modal__title {
    font-size: 1.6rem;
  }

  .blog-modal__body {
    padding: 20px 18px 24px;
  }
}

@media (max-width: 480px) {
  .blog-page {
    padding: 120px 12px 40px;
  }

  .content-wrapper {
    padding: 22px 16px 28px;
  }

  .blog-card {
    max-width: 100%;
  }

  .blog-card__body {
    padding: 18px 18px 20px;
  }

  .blog-card__btn {
    width: 100%;
    flex: 1 1 100%;
  }

  .blog-modal__body {
    font-size: 1rem;
  }
}

@media (max-width: 400px) {
  .blog-header h1 {
    font-size: 1.85rem;
  }

  .blog-header p {
    font-size: 1rem;
  }

  .blog-card__title {
    font-size: 1.55rem;
  }

  .blog-card__btn {
    padding-left: 16px;
    padding-right: 16px;
    font-size: 0.95rem;
  }
}

@media (max-height: 600px) {
  .blog-modal {
    padding: 12px 10px;
    /* Short viewports: pin dialog near the top so the header/close stay in view. */
    align-items: flex-start;
  }

  .blog-modal__dialog {
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    /* Opacity-only entrance — avoids any vertical translate overshoot. */
    animation-name: blogModalInFade;
  }
}

@keyframes blogModalInFade {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* Keep the fixed floats from forcing horizontal scroll on small screens */
@media (max-width: 768px) {
  body .main-footer {
    max-width: 100vw;
    overflow-x: hidden;
  }
}
