/* ghost-content.css — structure (widths, rhythm, overflow) for editor
   content in .post-content. Appearance is the design layer's. Ghost's own
   card_assets cover card internals; this places the cards in the flow.
   Cards: https://ghost.org/docs/themes/content/ */

.post-content {
  /* Children sit at the measure; wide cards break out via --content-wide. */
  --content-width: min(var(--measure), 100%);
  --content-wide: var(--container-wide);

  /* Article copy is a step up from the UI size. */
  font-size: var(--text-xl);
  line-height: var(--leading-body);

  /* Body copy's, for the rhythm fill below. */
  --half-leading: calc((1lh - 1em) / 2);

  display: flow-root;
}

/* Registered so it resolves to px here and children inherit body copy's
   value, not one recomputed from a heading's or card's own font size. */
@property --half-leading {
  syntax: "<length>";
  inherits: true;
  initial-value: 0px;
}

.post-content > * {
  max-width: var(--content-width);
  margin-inline: auto;
}

/* Pasted HTML cards carry inline margins (the newsletter teasers set
   margin: 36px 0 0 0); !important is the only way to keep them centred.
   Not full-width cards: header cards carry an inline style too, and this
   would cancel the breakout margins below. */
.post-content > [style]:not(.kg-width-full) {
  margin-inline: auto !important;
}

.post-content > * + * {
  margin-block-start: calc(var(--space-5) + var(--fill-above, 0px) + var(--fill-below, 0px));
}

/* More space above headings than below. */
.post-content > :is(h2, h3, h4, h5, h6) {
  margin-block-start: calc(var(--space-10) + var(--fill-below, 0px));
}

.post-content > :is(h2, h3, h4, h5, h6) + * {
  margin-block-start: calc(var(--space-3) + var(--fill-above, 0px));
}

/* Text has half its leading above and below its glyphs, so two paragraphs
   sit a full leading further apart than their margin says. Images, embeds
   and cards have none; these add it back on a box's side of a gap so every
   gap reads the same. hr keeps its own margins. */
.post-content > * + :not(p, ul, ol, dl, blockquote, h1, h2, h3, h4, h5, h6, hr, script) {
  --fill-above: var(--half-leading);
}

.post-content > :not(p, ul, ol, dl, blockquote, h1, h2, h3, h4, h5, h6, hr, script, :has(> figcaption:last-child)) + * {
  --fill-below: var(--half-leading);
}

/* A captioned figure already ends in text, but the caption's smaller size
   carries less leading; this pads it out to body copy's. */
.post-content > * > figcaption:last-child {
  padding-block-end: calc(var(--half-leading) - (1lh - 1em) / 2);
}

/* Newsletters. tag-newsletter, not data-section: the primary tag varies
   (daily-, weekly-, books-newsletter) but all carry plain "newsletter". */
.tag-newsletter .post-content > :is(h2, h3, h4, h5, h6) + :not(p) {
  margin-block-start: calc(var(--space-6) + var(--fill-above, 0px));
}

/* The next element's smaller top margin collapses into this one. */
.tag-newsletter .post-content > hr {
  margin-block: var(--space-10);
}

/* Prose lists get their markers back (the reset removes them). */
.post-content :is(ul, ol) {
  padding-inline-start: var(--space-6);
}

.post-content ul { list-style: disc; }
.post-content ol { list-style: decimal; }

.post-content li + li {
  margin-block-start: var(--space-2);
}

/* Card widths: Koenig's .kg-width-wide / .kg-width-full. */
.post-content .kg-width-wide {
  max-width: var(--content-wide);
}

/* Full-bleed: 100vw recentred with a negative margin. */
.post-content .kg-width-full {
  max-width: 100vw;
  width: 100vw;
  margin-inline: calc(50% - 50vw);
}

/* Captions stay at reading width under full-bleed images. */
.post-content figcaption {
  max-width: var(--content-width);
  margin-inline: auto;
}

/* Embeds */
.post-content .kg-embed-card {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Stretch the provider's wrapper so the iframe gets a width to fill (it
   otherwise falls back to 300px). Captions still shrink-to-fit. */
.post-content .kg-embed-card > div,
.post-content .kg-embed-card > iframe {
  align-self: stretch;
}

/* X's widget caps its wrapper at max-width: 550px, which the stretch above
   pins to the left edge; auto margins override the stretch and centre it. */
.post-content .kg-embed-card > .twitter-tweet-rendered {
  margin-inline: auto;
}

/* Override the provider's width attribute. Not ad iframes: GPT's width
   and height attributes are the creative's size, and components/outpost.css
   scales them instead. */
.post-content iframe:not(.responsive-gpt-ad iframe) {
  width: 100%;
  border: 0;
}

/* 16:9 needs height: auto to beat the height attribute. [data-no-aspect]
   (added by hand for non-video embeds) is excluded rather than reverted, so
   its height attribute stays in control. */
.post-content iframe:not(.responsive-gpt-ad iframe, [data-no-aspect]) {
  height: auto;
  aspect-ratio: 16 / 9;
}

/* Overflow: wide content scrolls inside itself, never the page. */
.post-content :is(pre, table) {
  overflow-x: auto;
}

.post-content table {
  display: block;
  max-width: var(--content-width);
}

/* Colours the editor output hardcodes for a white page, pointed at tokens so
   they follow dark mode. */

/* HTML cards' inline text colours (the newsletter teasers set #1a1a1a).
   Ghost's own cards are skipped: their colours sit on backgrounds they set. */
.post-content [style*="color"]:not([style*="background"], .kg-card, .kg-card *) {
  color: inherit !important;
}

/* CTA outline and dividers. !important on the dividers because Ghost's card
   CSS loads after ours and one of its divider rules is very specific. */
.post-content .kg-cta-bg-white {
  box-shadow: inset 0 0 0 var(--border-width) var(--color-border-soft);
}

.post-content .kg-cta-card :is(.kg-cta-sponsor-label-wrapper, .kg-cta-content) {
  border-color: var(--color-border-soft) !important;
}

/* The editor's default black CTA button takes the theme's button colours; a
   button given any other colour keeps it. */
.post-content .kg-cta-button[style*="background-color: #000000"] {
  background-color: var(--color-fg) !important;
  color: var(--color-bg) !important;
}

.post-content .kg-callout-card-yellow {
  background: var(--callout-yellow-bg);
}

/* Dropcap: [data-dropcap] on .post from the #drop-cap internal tag; the
   design layer styles the letter. */
[data-dropcap] .post-content > p:first-of-type::first-letter {
  /* Physical, not logical: Chrome ignores inline/block padding on
     ::first-letter, so the letter sat flush against the text. */
  float: left;
  line-height: 0.8;
  font-size: var(--dropcap-size, 3.5em);
  /* Inherits until the design layer names a face. */
  font-family: var(--dropcap-font, inherit);
  padding-right: var(--space-3);
  padding-top: var(--space-1);
}

/* Gated content: [data-gated] lets the design layer add a fade or divider. */
[data-gated] .post-content {
  position: relative;
}
