/* components/post.css — the parts of post.hbs and page.hbs that aren't their
   own component: headline block, feature figure, actions row, tag footer. */

/* POST__TOP — the six top layouts (see post-article.hbs), on data-layout.
   Text alignment is separate, on data-align (ALIGNMENT). "large-image" and
   "wide-image" differ only in figure width, so they are named side by side
   in the same selectors. .post__actions is
   outside .post__top, so no layout rule reaches it. --post-top-bg/-fg are
   the per-post colour hooks; COLOR BANNER and BAND fill them from the band
   pair. */
.post__top-text {
  background-color: var(--post-top-bg, transparent);
  color: var(--post-top-fg, inherit);
}

/* ALIGNMENT — data-align on .post: #header-left / #header-center, else the
   template's default (on HERO IMAGE, the column of its position tag). The
   headline block follows on every layout. */
.post[data-align="center"] .post__header {
  align-items: center;
  text-align: center;
}

.post[data-align="right"] .post__header {
  align-items: flex-end;
  text-align: end;
}

/* .post__tag pins itself to flex-start; override the flex placement. */
.post[data-align="center"] .post__tag {
  align-self: center;
}

.post[data-align="right"] .post__tag {
  align-self: flex-end;
}

/* The byline follows too, except on STANDARD and COLOR BANNER, which keep
   their own (MERGED ROW in post-info.css). post-info.css centres a lone
   "meta" part, so only left and right need rules. */
.post[data-align="left"]:not([data-layout="standard"], [data-layout="color-banner"]) .post-info[data-part="meta"] {
  justify-content: flex-start;
}

.post[data-align="left"]:not([data-layout="standard"], [data-layout="color-banner"]) :is(.post-info__meta, .post-info__byline, .post-info__dates) {
  align-items: flex-start;
}

.post[data-align="left"]:not([data-layout="standard"], [data-layout="color-banner"]) .post-info__authors {
  justify-content: flex-start;
}

.post[data-align="right"] .post-info[data-part="meta"] {
  justify-content: flex-end;
}

.post[data-align="right"] :is(.post-info__meta, .post-info__byline, .post-info__dates) {
  align-items: flex-end;
}

.post[data-align="right"] .post-info__authors {
  justify-content: flex-end;
}

/* SPLIT COLUMN: text | image from --bp-lg, stacked below. The image fills
   its column at its own aspect ratio and the text centres on whatever height
   it comes out at. */
@media (width >= 64rem) {
  .post[data-layout="split-column"] .post__top {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    gap: var(--space-10);
  }

  .post[data-layout="split-column"] .post__figure {
    --post-figure-width: 100%;
    margin-block: 0;
  }

  /* Drop the outer margins so the visible text (not its spacing) is what
     centres against the image. */
  .post[data-layout="split-column"] .post__header {
    margin-block-start: 0;
  }

  .post[data-layout="split-column"] .post-info[data-part="meta"] {
    margin-block-end: 0;
  }
}

/* Left-aligned SPLIT COLUMN: below --bp-lg the header and byline drop their
   gutters and share --measure with the figure, so the left edges line up;
   from it they hug the column's left edge. */
.post[data-layout="split-column"][data-align="left"] .post__header,
.post[data-layout="split-column"][data-align="left"] .post-info[data-part="meta"] {
  --container: var(--container-content);
  padding-inline: 0;
}

@media (width >= 64rem) {
  .post[data-layout="split-column"][data-align="left"] .post__header,
  .post[data-layout="split-column"][data-align="left"] .post-info[data-part="meta"] {
    margin-inline: 0;
  }
}

/* COLOR BANNER — .post__top-text becomes a full-bleed band in the band pair
   (dark unless the post has #custom- colour tags); the header joins it via
   data-banner-top on <body>. 100vw breakout (body's overflow-x: clip
   absorbs the scrollbar overhang); the children's own .container keeps the
   text at reading width. Post with No Image is this layout too when it has
   a band tag.
   :where() keeps specificity at a bare class, so a per-post Code injection
   override of .post__top-text still wins. */
:where(.post[data-layout="color-banner"]) .post__top-text {
  --post-top-bg: var(--color-band-bg);
  --post-top-fg: var(--color-band-fg);

  /* Re-point the quiet text tokens to the band's own colours, so the dek and
     dates invert too (and follow a per-post recolour). Same ratios as
     01-tokens.css. */
  --color-fg-tone: color-mix(in srgb, var(--post-top-fg) 80%, var(--post-top-bg) 20%);
  --color-fg-muted: color-mix(in srgb, var(--post-top-fg) 60%, var(--post-top-bg) 40%);

  width: 100vw;
  margin-inline: calc(50% - 50vw);
  padding-block: var(--space-10);
}

/* No strip of page background between the band and the masthead. Outside
   :where() — this isn't a colour decision. */
.post[data-layout="color-banner"] .post__top {
  padding-block-start: 0;
}

/* Space under the band, whether the image or the article comes next (No
   Image has no figure margin to lean on). Collapses with the figure's. */
.post[data-layout="color-banner"] .post__top-text {
  margin-block-end: var(--space-10);
}

/* BAND — any other layout with a #dark or #custom- colour tag: the whole
   .post__top (image included) sits on the band. Split Column + #dark is the
   old SPLIT DARK. The fill is a ::before pushed to the viewport edges, so the
   layout keeps the container's edges; z-index: -1 is safe as .post__top
   makes no stacking context. Keeps its top padding (it's inside the band
   here) and gets a real bottom padding. HERO IMAGE never gets data-band. */
:where(.post[data-band]:not([data-layout="color-banner"])) .post__top {
  --post-top-bg: var(--color-band-bg);
  --post-top-fg: var(--color-band-fg);
  --color-fg-tone: color-mix(in srgb, var(--post-top-fg) 80%, var(--post-top-bg) 20%);
  --color-fg-muted: color-mix(in srgb, var(--post-top-fg) 60%, var(--post-top-bg) 40%);

  color: var(--post-top-fg);
  position: relative;
  padding-block-end: var(--space-10);
}

.post[data-band]:not([data-layout="color-banner"]) .post__top::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline: calc(50% - 50vw);
  z-index: -1;
  background-color: var(--post-top-bg);
}

/* LARGE IMAGE and WIDE IMAGE widen the figure through the
   --post-figure-width knob, so the min(…, 100%) clamp stays: Large to
   --container-wide, Wide to the masthead's width (the declared
   --container-site resolves to its inner width at every size). The caption
   and headline keep reading width. */
.post[data-layout="large-image"] .post__figure {
  --post-figure-width: var(--container-wide);
}

.post[data-layout="wide-image"] .post__figure {
  --post-figure-width: var(--container-site);
}

/* HERO IMAGE — the feature image full-bleed at --post-hero-height, under the
   masthead ([data-hero-overlap] in site-header.css), with the text over it
   at one of nine places from data-hero-position (the text inside the block
   aligns by data-align, so a #header- tag can differ from the column).
   Unknown positions read as bottom-center. The text is the home hero text
   setting; the scrim is its inverse. The caption sits below the image. */
.post[data-layout="hero-image"] .post__top {
  position: relative;
  padding-block: 0;
}

.post[data-layout="hero-image"] .post__figure {
  position: relative;
  width: 100vw;
  max-width: none;
  margin-block: 0;
  margin-inline: calc(50% - 50vw);
}

.post[data-layout="hero-image"] .post__figure img {
  height: var(--post-hero-height);
  object-fit: cover;
}

/* Scrim over the image only, not the caption: top for the masthead, and a
   second gradient behind the text's row. Drawn in the text colour inverted,
   so it always backs the text; --color-bg stands in where relative colour
   is unsupported (the hero text defaults to --color-fg). */
.post[data-layout="hero-image"] .post__figure::after {
  --post-hero-scrim-color: var(--color-bg);
  --hero-scrim: linear-gradient(
    to top,
    color-mix(in srgb, var(--post-hero-scrim-color) 70%, transparent),
    transparent 45%
  );

  content: "";
  position: absolute;
  inset-inline: 0;
  inset-block-start: 0;
  height: var(--post-hero-height);
  pointer-events: none;
  background:
    linear-gradient(
      to bottom,
      color-mix(in srgb, var(--post-hero-scrim-color) 55%, transparent),
      transparent 25%
    ),
    var(--hero-scrim);
}

@supports (color: rgb(from red r g b)) {
  .post[data-layout="hero-image"] .post__figure::after {
    --post-hero-scrim-color: rgb(from var(--color-hero-text) calc(255 - r) calc(255 - g) calc(255 - b));
  }
}

.post[data-layout="hero-image"][data-hero-position^="top-"] .post__figure::after {
  --hero-scrim: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--post-hero-scrim-color) 45%, transparent),
    transparent 60%
  );
}

.post[data-layout="hero-image"][data-hero-position^="center-"] .post__figure::after {
  --hero-scrim: linear-gradient(
    color-mix(in srgb, var(--post-hero-scrim-color) 35%, transparent),
    color-mix(in srgb, var(--post-hero-scrim-color) 35%, transparent)
  );
}

/* The text box covers the image (inset to the container's gutters, so the
   left and right columns line up with the masthead). z-index lifts it over
   the figure, which comes later in the markup. `safe` keeps an overlong
   headline from spilling off the top. Top padding clears the masthead. */
.post[data-layout="hero-image"] .post__top-text {
  --color-fg-tone: var(--color-hero-text);
  --color-fg-muted: var(--color-hero-text);

  position: absolute;
  z-index: 1;
  inset-block-start: 0;
  inset-inline: 0;
  height: var(--post-hero-height);
  display: flex;
  flex-direction: column;
  justify-content: safe flex-end;
  align-items: center;
  padding: var(--space-32) var(--gutter) var(--space-16);
  color: var(--color-hero-text);
}

.post[data-layout="hero-image"][data-hero-position^="top-"] .post__top-text {
  justify-content: flex-start;
}

.post[data-layout="hero-image"][data-hero-position^="center-"] .post__top-text {
  justify-content: safe center;
}

.post[data-layout="hero-image"][data-hero-position$="-left"] .post__top-text {
  align-items: flex-start;
}

.post[data-layout="hero-image"][data-hero-position$="-right"] .post__top-text {
  align-items: flex-end;
}

/* The flex box places the text, so the header and byline drop their own
   centring and gutters, and the outer margins that would offset them. */
.post[data-layout="hero-image"] :is(.post__header, .post-info[data-part="meta"]) {
  --container: var(--container-content);
  margin-inline: 0;
  padding-inline: 0;
}

.post[data-layout="hero-image"] .post__header {
  margin-block-start: 0;
}

.post[data-layout="hero-image"] .post-info[data-part="meta"] {
  margin-block-end: 0;
}

/* Under the image, at the body copy's width. */
.post[data-layout="hero-image"] .post__figure-caption {
  max-width: min(var(--measure), 100% - var(--gutter) * 2);
  margin-inline: auto;
}

/* POST__ACTIONS — the share/comment row, a sibling of .post__top so no
   layout reaches it. It owns the vertical rhythm (the inner .post-info's
   margin is zeroed so it can't collapse through). More space below than
   above. */
.post__actions {
  margin-block: var(--space-6) var(--space-10);
}

/* STANDARD, COLOR BANNER and left-aligned LARGE IMAGE show these controls in
   the byline row instead (on COLOR BANNER, that's the only way onto the
   band). header-scroll.js watches whichever copy is visible. */
.post[data-layout="standard"] .post__actions,
.post[data-layout="color-banner"] .post__actions,
.post[data-layout="large-image"][data-align="left"] .post__actions {
  display: none;
}

.post__actions .post-info {
  margin-block: 0;
}

.post__header,
.page__header {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-block-start: var(--space-10);
  margin-block-end: var(--space-10);
}

/* Below --bp-md, less space above the kicker: .post__top's padding alone,
   cut from its pt-10 (post.css loads after the utilities, so this wins). */
@media (width < 48rem) {
  .post__top {
    padding-block-start: var(--space-6);
  }

  .post__header {
    margin-block-start: 0;
  }

  .post__title {
    font-size: var(--post-title-mobile-size);
  }
}

/* STANDARD / LARGE and WIDE IMAGE: the header's and byline's
   .container gutter doubles the .post__top one; zero it so the text matches
   the figure's width. --container undoes the byline's two-gutter widening
   (post-info.css), which assumes no outer gutter. */
.post[data-layout="standard"] :is(.post__header, .post-info[data-part="meta"]),
.post[data-layout="large-image"] :is(.post__header, .post-info[data-part="meta"]),
.post[data-layout="wide-image"] :is(.post__header, .post-info[data-part="meta"]) {
  --container: var(--container-content);
  padding-inline: 0;
}

/* COLOR BANNER is the opposite: the band escapes .post__top, so there's no
   outer gutter to rely on. Widen the box by two gutters instead (as
   post-info.css does) so the headline lines up with the byline. */
.post[data-layout="color-banner"] .post__header {
  --container: calc(var(--container-content) + var(--gutter) * 2);
}

/* PAGES: the copy below sits at --measure inside a --wide container, so its
   gutter is outside the column; widen the header the same way or its gutter
   insets the title from --bp-md up. Phones keep the gutter. */
.page__header {
  --container: calc(var(--measure) + var(--gutter) * 2);
}

/* The kicker: 17px via --post-tag-size (design layer), falling back to
   --text-base. Still a link, but not underlined. */
.post__tag {
  font-family: var(--font-ui);
  font-size: var(--post-tag-size, var(--text-base));
  font-weight: var(--weight-normal);
  align-self: flex-start;
  text-decoration: none;
}

.post__excerpt,
.page__excerpt {
  font-size: var(--text-lg);
  color: var(--color-fg-tone);
  max-width: var(--measure);
}

/* FEATURE FIGURE — capped at --measure. --post-figure-width is the one knob
   a layout may use to widen it (WIDE IMAGE does). */
.post__figure,
.page__figure {
  /* min() because nothing else stops it overflowing a narrow viewport. */
  max-width: min(var(--post-figure-width, var(--measure)), 100%);
  margin-block: var(--space-8);
  margin-inline: auto;
}

.post__figure img,
.page__figure img {
  width: 100%;
  height: auto;
}

/* POST-UPDATED — the #show-updated "Last updated" line, caption-styled.
   Widened by two gutters (as post-info.css does) so it lines up with the
   body copy. */
.post-updated {
  --container: calc(var(--container-content) + var(--gutter) * 2);
  margin-block: var(--space-6);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--color-fg-tone);
}

/* TAG FOOTER — "Tagged" over a comma-separated list, directly above
   author-box.css, whose first row supplies the rule beneath. The label is an
   h2 for the outline, sized back down. The gutter moves from padding to the
   max-width so the top rule spans the body copy's width, not past it. */
.post__footer {
  --container: min(var(--container-content), 100% - var(--gutter) * 2);
  padding-inline: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-block-start: var(--space-16);
  padding-block: var(--space-4) var(--space-10);
  border-block-start: var(--border-width) solid var(--color-border-soft);
  font-family: var(--font-ui);
  font-size: var(--text-base);
}

.post__tags-label {
  font-family: inherit;
  font-size: inherit;
  font-weight: var(--weight-bold);
}

.post__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--space-1);
}

.post__tags-link {
  text-decoration: none;
  transition: opacity var(--transition);
}

@media (hover: hover) {
  .post__tags-link:hover {
    opacity: var(--card-hover-opacity);
  }
}

/* Comma between tags (kept out of the link text). */
.post__tags li:not(:last-child)::after {
  content: ",";
}

/* FEATURE IMAGE CAPTION — left on the image's edge on every layout, capped
   at --measure (even under a wide image). Overrides 02-base.css's centred
   figcaption. */
.post__figure-caption,
.page__figure-caption {
  max-width: var(--measure);
  text-align: start;
}
