/*
 * Blog pages (/blog, /blog/{slug}). Loaded only by those pages, so the locked
 * terraapath.css stays untouched. Uses the site tokens from partials/theme-styles.
 */

.blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: clamp(16px, 2vw, 24px);
}

.blog-card {
  display: flex;
  flex-direction: column;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.blog-card:hover {
  transform: translateY(-2px);
}

.blog-card-img {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--card-placeholder, var(--bg));
}

/* Absolutely placed so a tall photo can't stretch the 16:9 frame. */
.blog-card-img img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.blog-card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 20px 20px;
}

.blog-card h2,
.blog-card h3 {
  margin: 0;
  font-size: var(--fs-lead);
  line-height: var(--lh-tight, 1.3);
  font-weight: var(--fw-semibold, 600);
}

.blog-card h2 a,
.blog-card h3 a {
  color: var(--text);
  text-decoration: none;
}

.blog-card h2 a:hover,
.blog-card h3 a:hover {
  color: var(--blue);
}

.blog-card p {
  margin: 0;
  color: var(--muted);
  line-height: var(--lh-relaxed, 1.6);
}

.blog-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: var(--fs-svc);
  color: var(--muted);
}

.blog-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.blog-tags a {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--blue);
  background: var(--accent-soft, var(--bg));
  border-radius: 999px;
  padding: 4px 10px;
  text-decoration: none;
}

.blog-tags a:hover {
  text-decoration: underline;
}

.blog-empty {
  color: var(--muted);
  text-align: center;
  padding: 40px 0;
}

.blog-clear {
  color: var(--blue);
  font-weight: 600;
  text-decoration: none;
}

.blog-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-top: 32px;
  color: var(--muted);
}

.blog-pager a {
  color: var(--blue);
  font-weight: 600;
  text-decoration: none;
}

.blog-pager [aria-disabled="true"] {
  opacity: 0.45;
}

/* Shared article column (blog posts and policy pages). */
.blog-narrow {
  max-width: 760px;
}

.blog-clear-row {
  margin-top: 8px;
}

.blog-body {
  font-size: var(--fs-lead);
  line-height: 1.75;
  color: var(--text);
  overflow-wrap: anywhere;
}

.blog-body > * + * {
  margin-top: 1em;
}

.blog-body h2,
.blog-body h3 {
  color: var(--blue);
  line-height: 1.3;
  margin-top: 1.8em;
}

.blog-body h2 {
  font-size: clamp(1.35rem, 1.15rem + 0.7vw, 1.65rem);
}

.blog-body h3 {
  font-size: clamp(1.15rem, 1.05rem + 0.4vw, 1.3rem);
}

.blog-body img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-card);
}

.blog-body a {
  color: var(--blue);
  text-underline-offset: 3px;
}

.blog-body blockquote {
  margin-left: 0;
  padding: 4px 0 4px 20px;
  border-left: 3px solid var(--blue);
  color: var(--muted);
  font-size: 1.05em;
}

.blog-body ul,
.blog-body ol {
  padding-left: 1.4em;
}

.blog-body li + li {
  margin-top: 0.4em;
}

.blog-preview {
  background: #fff4e0;
  color: #7a4a00;
  text-align: center;
  font-weight: 600;
  padding: 10px 16px;
}

/*
 * Single post (/blog/{slug}).
 * Shape rule: photos and cards use --radius-card; buttons and tags are pills.
 */
/* Title and text start at the cover's left edge; the text column stops at a readable width. */
.post-head {
  padding-top: clamp(24px, 4vw, 48px);
}

.post-head > * {
  max-width: 880px;
}

.post-back {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--blue);
  font-size: var(--fs-svc);
  font-weight: 600;
  text-decoration: none;
}

.post-back:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Same size and weight as the other page titles (.page-hero h1). */
.post-title {
  margin: 6px 0 0;
  font-size: var(--fs-page-title, var(--fs-h2));
  font-weight: var(--fw-semibold);
  line-height: var(--lh-heading);
  color: var(--blue);
  text-wrap: balance;
}

.post-dek {
  margin: 16px 0 0;
  max-width: 60ch;
  font-size: clamp(1.08rem, 1rem + 0.4vw, 1.25rem);
  line-height: 1.55;
  color: var(--muted);
  text-wrap: pretty;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-top: 18px;
  font-size: var(--fs-svc);
  color: var(--muted);
}

.post-meta-photos {
  margin-left: 8px;
  padding-left: 14px;
  border-left: 1px solid var(--line);
  color: var(--blue);
  font-weight: 600;
  text-decoration: none;
}

.post-meta-photos:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* The cover breaks out of the reading column to the full page width. */
.post-cover {
  margin: clamp(24px, 3.5vw, 40px) auto 0;
}

.post-cover img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius-card);
  background: var(--card-placeholder, var(--bg));
}

@media (min-width: 768px) {
  .post-cover img {
    aspect-ratio: 2 / 1;
  }
}

.post {
  padding-bottom: clamp(48px, 7vw, 88px);
}

.post-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "body" "gallery" "aside";
  gap: clamp(32px, 5vw, 48px);
  padding-top: clamp(28px, 4vw, 44px);
}

.post-body {
  grid-area: body;
  max-width: 820px;
}

.post-body > :first-child {
  margin-top: 0;
}

.post-gallery {
  grid-area: gallery;
}

.post-aside {
  grid-area: aside;
}

@media (min-width: 1024px) {
  .post-layout {
    grid-template-columns: minmax(0, 820px) minmax(260px, 320px);
    grid-template-areas: "body aside" "gallery gallery";
    justify-content: space-between;
    column-gap: 56px;
  }

  .post-aside-inner {
    position: sticky;
    top: 112px;
  }
}

.post-aside-inner {
  display: grid;
  gap: 28px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--white);
}

.post-aside-block + .post-aside-block {
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.post-aside-title {
  margin: 0 0 12px;
  font-size: var(--fs-svc);
  font-weight: 600;
  color: var(--text);
}

.post-related-list {
  display: grid;
  gap: 14px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-related-list a {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  color: var(--text);
  text-decoration: none;
}

.post-related-img {
  position: relative;
  display: block;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 10px;
  background: var(--card-placeholder, var(--bg));
}

.post-related-img img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.post-related-text {
  display: grid;
  gap: 4px;
}

.post-related-text strong {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--blue);
}

.post-related-list a:hover strong {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.post-related-text time {
  font-size: 0.82rem;
  color: var(--muted);
}

.post-section-title {
  margin: 0 0 20px;
  font-size: clamp(1.35rem, 1.1rem + 1vw, 1.75rem);
  font-weight: var(--fw-semibold, 600);
  line-height: 1.25;
  color: var(--blue);
}

/*
 * Gallery: the first photo is large with two beside it, then rows of three.
 * The last row stretches so the grid never ends with an empty cell. Photos are
 * cropped to fill their cells; the viewer shows each one whole.
 */
.post-gallery {
  scroll-margin-top: 96px;
}

.post-gallery-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-auto-rows: clamp(140px, 17vw, 230px);
  gap: 12px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-gallery-grid li {
  grid-column: span 2;
}

.post-gallery-grid li:first-child {
  grid-column: span 4;
  grid-row: span 2;
}

/* One photo: full width. Two photos: side by side. */
.post-gallery-grid li:only-child {
  grid-column: span 6;
}

.post-gallery-grid li:first-child:nth-last-child(2),
.post-gallery-grid li:first-child:nth-last-child(2) ~ li {
  grid-column: span 3;
  grid-row: span 2;
}

/* Rows after the first three: one left over fills the row, two left over share it. */
.post-gallery-grid li:nth-child(3n + 1):nth-child(n + 4):last-child {
  grid-column: span 6;
}

.post-gallery-grid li:nth-child(3n + 1):nth-child(n + 4):nth-last-child(2),
.post-gallery-grid li:nth-child(3n + 1):nth-child(n + 4):nth-last-child(2) + li {
  grid-column: span 3;
}

@media (max-width: 639px) {
  .post-gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: 150px;
    gap: 8px;
  }

  .post-gallery-grid li,
  .post-gallery-grid li:nth-child(3n + 1):nth-child(n + 4):nth-last-child(2),
  .post-gallery-grid li:nth-child(3n + 1):nth-child(n + 4):nth-last-child(2) + li,
  .post-gallery-grid li:nth-child(3n + 1):nth-child(n + 4):last-child {
    grid-column: span 1;
  }

  .post-gallery-grid li:first-child,
  .post-gallery-grid li:only-child {
    grid-column: span 2;
    grid-row: span 2;
  }

  /* After the large first photo the rest pair up; an odd one out takes the full row. */
  .post-gallery-grid li:nth-child(even):nth-child(n + 2):last-child {
    grid-column: span 2;
  }

  .post-gallery-grid li:first-child:nth-last-child(2) ~ li {
    grid-column: span 2;
    grid-row: span 1;
  }
}

.post-photo {
  display: block;
  height: 100%;
  overflow: hidden;
  border-radius: var(--radius-card);
  background: var(--card-placeholder, var(--bg));
  cursor: zoom-in;
}

.post-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.post-photo:hover img {
  transform: scale(1.03);
}

.post-photo:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

.post-share {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-svc);
  color: var(--muted);
}

.post-share-btn {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--white);
  color: var(--blue);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

.post-share-btn:hover {
  background: var(--accent-soft, var(--bg));
}

.post-share-btn:active {
  transform: translateY(1px);
}

.post-share-btn:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

/* Full-screen photo viewer (native <dialog>: Esc closes, focus stays inside). */
/* Sized from the viewport edges, not 100vw: the site's page zoom (--page-zoom) would scale vw past the screen. */
.lightbox {
  inset: 0;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #080f1e;
  color: #f4f7fb;
  overflow: hidden;
}

.lightbox::backdrop {
  background: rgb(8 15 30 / 0.6);
}

.lightbox[open] {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.lightbox-stage {
  position: relative;
  min-height: 0;
}

/* Centred in the space between the close button and the controls, never larger than it. */
.lightbox-stage img {
  position: absolute;
  inset: 72px 16px 8px;
  margin: auto;
  max-width: calc(100% - 32px);
  max-height: calc(100% - 80px);
  object-fit: contain;
  border-radius: 8px;
}

.lightbox-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
}

.lightbox-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid rgb(244 247 251 / 0.35);
  border-radius: 999px;
  background: transparent;
  color: #f4f7fb;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.lightbox-btn:hover {
  background: rgb(244 247 251 / 0.12);
}

.lightbox-btn:focus-visible {
  outline: 2px solid #f4f7fb;
  outline-offset: 2px;
}

.lightbox-close {
  position: absolute;
  top: 12px;
  right: 16px;
}

.lightbox-count {
  min-width: 9ch;
  margin: 0;
  text-align: center;
  font-size: 0.95rem;
  color: rgb(244 247 251 / 0.85);
}

@media (prefers-reduced-motion: no-preference) {
  .lightbox[open] .lightbox-stage img {
    animation: lightbox-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  }
}

@keyframes lightbox-in {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
}

@media (prefers-reduced-motion: reduce) {
  .blog-card,
  .post-photo img {
    transition: none;
  }

  .blog-card:hover,
  .post-photo:hover img {
    transform: none;
  }
}

/* Policy pages (/legal/{slug}) reuse the article styles above. */
.legal-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-svc);
}

.legal-body th,
.legal-body td {
  padding: 10px 12px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.legal-body th {
  background: var(--bg);
  color: var(--blue);
  font-weight: 600;
}

.legal-more {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: var(--fs-svc);
}

.legal-more span {
  flex-basis: 100%;
  color: var(--muted);
  font-weight: 600;
}

.legal-more a {
  color: var(--blue);
  font-weight: 600;
}
