/*
 * Layout overrides, loaded after the original stylesheet.
 *
 * The site frame runs the full width of the viewport; only the reading
 * column on a single article stays inside a measured container. Both
 * widths are variables, so putting the whole site back inside a fixed
 * container is a one-line change:
 *
 *   :root { --site-max: 1140px; }
 */

:root {
  --site-max: none;               /* site frame — none = full width */
  --site-gutter: clamp(16px, 2.5vw, 40px);
  --read-max: 1140px;             /* the article reading column */
}

/* ---------- Full-width frame ---------- */
.page,
.container {
  max-width: var(--site-max);
  margin-inline: auto;
  padding-inline: var(--site-gutter);
}

/* ---------- Body-class collisions ----------
 * WordPress adds `page` to <body> on every Page and `tag` on every tag
 * archive. Both names are already layout classes in this theme, so without
 * this reset <body> picks up the frame gutter (insetting the whole site by
 * an extra gutter and stopping the dark bars short of the edges) and, on a
 * tag archive, the uppercase pill type. Body is never a frame element. */
body.page,
body.container {
  max-width: none;
  margin-inline: 0;
  padding-inline: 0;
}
body.tag {
  font-family: var(--serif);
  font-size: 1.0625rem;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
  color: var(--ink);
}

/* ---------- The article keeps its container ----------
 * The gutters are added on top of --read-max, so the reading column itself
 * measures exactly --read-max, the same as the original static page. */
.single-post .page-hero__inner,
.single-post .article-layout,
.single-post main > .container,
.dp-read-width {
  max-width: calc(var(--read-max) + var(--site-gutter) * 2);
  margin-inline: auto;
}

@media (max-width: 640px) {
  :root { --site-gutter: 16px; }
}

/* ---------- Active nav item keeps its state on hover (#6) ----------
 * The base stylesheet's `.primary-nav ul a:hover` ties on specificity with
 * the aria-current rule and, coming later, wins — so hovering the current
 * page repainted it like any other hover. Pin the active look for hover and
 * focus too. */
.primary-nav ul a[aria-current="page"],
.primary-nav ul a[aria-current="page"]:hover,
.primary-nav ul a[aria-current="page"]:focus {
  background: var(--paper-deep);
  color: var(--ink);
  box-shadow: inset 0 2px 0 var(--accent);
}
.primary-nav a.nav-cta[aria-current="page"],
.primary-nav a.nav-cta[aria-current="page"]:hover,
.primary-nav a.nav-cta[aria-current="page"]:focus {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  color: var(--paper);
}

/* ---------- Whole-card click + hover (#8) ----------
 * Each card's heading link is stretched to cover the whole card via a
 * ::after overlay, so a click anywhere on the card opens the post. The
 * thumbnail's own <a> is decorative (aria-hidden, tabindex -1) and sits
 * behind the overlay. On hover the whole card lifts the title into its
 * hover style (accent + underline), matching the original link hover. */
.story-list li,
.feat-list li,
.article-card,
.mini-feature { position: relative; }

.story-list li h3 > a::after,
.feat-list li h3 > a::after,
.article-card h3 > a::after,
.mini-feature h3 > a::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* Keep the decorative thumbnail link from stealing the click. */
.story-list li a.thumb,
.feat-list li a.thumb,
.article-card .article-card__thumb,
.mini-feature .mini-feature__art { position: relative; z-index: 0; }

/* Anything genuinely interactive inside a card (e.g. source links) stays
 * above the overlay so it remains clickable. */
.article-card .article-card__sources a,
.story-list .summary a,
.mini-feature p a { position: relative; z-index: 2; }

/* Hover the whole card -> title takes its hover treatment. */
.story-list li:hover h3 a,
.feat-list li:hover h3 a,
.article-card:hover h3 a,
.mini-feature:hover h3 a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.story-list li:hover .thumb img,
.article-card:hover .article-card__thumb img,
.mini-feature:hover .mini-feature__art img { transform: scale(1.03); }

/* The card is a pointer target end to end. */
.story-list li,
.feat-list li,
.article-card,
.mini-feature { cursor: pointer; }

/* ---------- User-built primary menu (#2) ----------
 * wp_nav_menu() outputs <ul class="primary-menu"> inside .primary-nav, so the
 * base stylesheet's `.primary-nav ul`, `.primary-nav ul a`, hover and
 * aria-current rules already style it exactly like the hardcoded nav. We add
 * ONLY what the hardcoded version got from HTML classes the menu can't carry:
 * the Subscribe item (li given the CSS class "nav-cta") rendered as the accent
 * button. WordPress adds that class verbatim, so it lands on the <li> as
 * `nav-cta` (older installs may prefix it `menu-item-nav-cta`); both match. */
/* Constrain the menu <ul> so it shrink-wraps its items and always centers,
 * regardless of any inherited full-width / space-between rule. Without this a
 * stale or third-party rule can stretch the ul and blow a big gap open before
 * the Subscribe button. */
.primary-nav .primary-menu {
  width: auto;
  max-width: none;
  flex: 0 0 auto;
  justify-content: center;
  gap: 0;
}
.primary-nav .primary-menu > li { flex: 0 0 auto; }

.primary-nav .primary-menu > li.nav-cta,
.primary-nav .primary-menu > li.menu-item-nav-cta {
  align-self: center;
  margin: 6px 0 6px 16px;
}
.primary-nav .primary-menu > li.nav-cta > a,
.primary-nav .primary-menu > li.menu-item-nav-cta > a {
  /* Clone of .btn.btn--accent so the menu button matches the hardcoded one. */
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  padding: 7px 18px;
  border: 1px solid var(--accent-deep);
  border-left: 1px solid var(--accent-deep);
  border-radius: 2px;
  background: var(--accent);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  text-decoration: none;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.22);
}
.primary-nav .primary-menu > li.nav-cta > a:hover,
.primary-nav .primary-menu > li.menu-item-nav-cta > a:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  color: var(--paper);
}
.primary-nav .primary-menu > li.nav-cta > a[aria-current="page"],
.primary-nav .primary-menu > li.menu-item-nav-cta > a[aria-current="page"] {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

/* ---------- Pagination (#11) ---------- */
.feat__all .page-numbers,
nav[aria-label$="pagination"] .page-numbers {
  display: inline-block;
  min-width: 2.4em;
  padding: 0.5em 0.75em;
  margin: 0 3px;
  font-family: var(--sans);
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
  border: 1px solid var(--rule-dark);
  background: var(--paper);
}
.feat__all a.page-numbers:hover,
nav[aria-label$="pagination"] a.page-numbers:hover {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.feat__all .page-numbers.current,
nav[aria-label$="pagination"] .page-numbers.current {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
}
.feat__all .page-numbers.dots,
nav[aria-label$="pagination"] .page-numbers.dots {
  border-color: transparent;
  background: transparent;
}

/* ---------- TOC sidebar always present (#10) ---------- */
.toc__empty {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-style: italic;
}

/* ---------- Card descriptions clamp to two lines (…) ----------
 * Applies to every card blurb: the featured dek, story-list and archive
 * summaries, the articles-index card paragraph, and the related strip. */
.card-desc,
.feat-lead .dek.card-desc,
.story-list .summary.card-desc,
.article-card .card-desc,
.mini-feature .card-desc {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  /* Fallback ceiling for engines that ignore line-clamp: two lines of the
   * element's own line-height, so text can never exceed two lines. */
  max-height: calc(2 * 1.55em);
}
/* Some card blurbs use a tighter line-height; keep the ceiling in step. */
.feat-list .card-desc { max-height: calc(2 * 1.5em); }

/* ---------- Articles index: 2 columns on mobile ----------
 * The base stylesheet lays the index out as a single vertical stack of
 * horizontal cards, collapsing each card to thumb-over-text at <=640px. On
 * phones we instead show two compact cards per row: the grid becomes two
 * columns and each card stacks its own thumb over its text. Loaded last so it
 * wins over the base single-column rule. */
@media (max-width: 640px) {
  .article-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px 14px;
  }
  .article-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* Per-row dividers read badly in a 2-up grid — drop them, keep rhythm
     * with padding only. */
    border-bottom: none;
    padding: 0 0 6px;
  }
  .article-card__thumb img { aspect-ratio: 4 / 3; }
  .article-card h3 { font-size: 1.02rem; line-height: 1.25; margin: 0.1em 0 0.2em; }
  /* Descriptions are already clamped to two lines; hide on the narrowest
   * phones where a 2-up card has no room for body copy. */
  .article-card .card-desc { font-size: 0.9rem; }
  .article-card .tag-row .meta { font-size: 0.7rem; }
}

/* Very narrow phones: keep two columns but tighten further. */
@media (max-width: 380px) {
  .article-grid { gap: 14px 10px; }
  .article-card h3 { font-size: 0.95rem; }
  .article-card .card-desc { display: none; }
}

/* ---------- Archive/category page: 2 columns on mobile ----------
 * The archive uses the .story-list card (horizontal thumb+text, collapsing to
 * a single stacked column at <=640px). Scoped to body.archive so the same
 * .story-list on the home page keeps its single-column mobile layout. Two
 * compact stacked cards per row, mirroring the articles index. */
@media (max-width: 640px) {
  body.archive .story-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px 14px;
  }
  body.archive .story-list li {
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-bottom: none;
    padding: 0 0 6px;
  }
  body.archive .story-list .thumb img { aspect-ratio: 4 / 3; }
  body.archive .story-list h3 { font-size: 1.02rem; line-height: 1.25; margin: 0.1em 0 0.2em; }
  body.archive .story-list .summary { font-size: 0.9rem; }
  body.archive .story-list .meta { font-size: 0.68rem; }
}
@media (max-width: 380px) {
  body.archive .story-list { gap: 14px 10px; }
  body.archive .story-list h3 { font-size: 0.95rem; }
  body.archive .story-list .summary { display: none; }
}

/* ---------- Editor-inserted media in the article body ----------
 * The base stylesheet styles the theme's own hero and card images, but not
 * the images, figures and captions a user inserts through the block editor.
 * These rules give inserted media sensible spacing, caption styling and
 * support for the standard WordPress alignment classes so anything added in
 * the editor displays correctly. */
.article-body img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Images and image blocks inserted in content. */
.article-body figure,
.article-body .wp-block-image {
  margin: 1.6em 0;
}
.article-body figure img,
.article-body .wp-block-image img {
  width: 100%;
  border: 1px solid var(--rule-dark);
}

/* Captions. */
.article-body figcaption,
.article-body .wp-element-caption {
  margin-top: 0.6em;
  font-family: var(--sans);
  font-size: 0.8125rem;
  color: var(--ink-faint);
  text-align: center;
}

/* Standard WordPress alignment classes. */
.article-body .aligncenter {
  margin-inline: auto;
}
.article-body img.aligncenter,
.article-body .wp-block-image.aligncenter {
  margin-inline: auto;
}
.article-body .alignleft {
  float: left;
  margin: 0.4em 1.4em 1em 0;
  max-width: 50%;
}
.article-body .alignright {
  float: right;
  margin: 0.4em 0 1em 1.4em;
  max-width: 50%;
}
.article-body figure.alignleft img,
.article-body figure.alignright img { width: 100%; }

/* Wide and full-bleed images break out of the reading measure. */
.article-body .alignwide {
  width: min(100%, 1140px);
  margin-inline: auto;
}
.article-body .alignfull {
  width: 100%;
}

/* Galleries. */
.article-body .wp-block-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 1.6em 0;
}
.article-body .wp-block-gallery figure { margin: 0; }

/* Clear floats so following headings don't wrap awkwardly. */
.article-body h2,
.article-body h3 { clear: both; }
