/* ============================================
   Post / recipe detail page
   ============================================ */

.post-page {
  padding-block: calc(var(--navbar-height) + clamp(2rem, 6vw, 4.5rem)) var(--space-3xl);
}

.post-article {
  max-width: var(--page-width);
  margin-inline: auto;
  padding-inline: var(--page-gutter);
}

/* Header */
.post-header {
  margin-block-end: var(--space-xl);
  padding-block-end: var(--space-xl);
  border-block-end: 1px solid var(--color-rule);
}

.post-header__back {
  display: inline-block;
  margin-block-end: var(--space-lg);
}

.post-header__title {
  max-width: 20ch;
}

.post-header__description {
  margin-block-start: var(--space-md);
}

.post-header__meta {
  margin-block-start: var(--space-md);
}

/* Lead image (astrophotography posts) */
.post-lead-media {
  margin-block: 0 var(--space-2xl);
}

.post-lead-media__frame {
  overflow: hidden;
  border-radius: var(--radius-lg);
}

.post-lead-media__image {
  display: block;
  width: 100%;
  height: auto;
}

/* Layout: contents sidebar beside the article on wider screens */
.post-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-2xl);
  align-items: start;
}

.post-body-column {
  min-width: 0;
  max-width: var(--measure);
}

/* Contents */
.post-toc__label {
  color: var(--color-headline);
  font-size: var(--text-sm);
  font-weight: 600;
}

.post-toc__list {
  display: grid;
  gap: 0.45rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.post-toc__item--depth-2 {
  padding-inline-start: 0.8rem;
}

.post-toc__item--depth-3 {
  padding-inline-start: 1.6rem;
}

.post-toc__link {
  display: block;
  color: var(--color-paragraph);
  font-size: var(--text-xs);
  line-height: 1.4;
  text-decoration: none;
  transition: color var(--transition-base);
}

.post-toc__link:hover,
.post-toc__link:focus-visible {
  color: var(--color-link);
}

/* The section being read (toc-spy.js) */
.post-toc__link[aria-current="location"] {
  color: var(--color-headline);
  font-weight: 600;
}

/* The header's own bottom rule sits just above, so only a closing rule. */
.post-toc--mobile {
  margin-block: calc(-1 * var(--space-md)) var(--space-xl);
  border-block-end: 1px solid var(--color-rule);
}

.post-toc--mobile .post-toc__summary {
  padding-block: 0.75rem;
  cursor: pointer;
}

.post-toc--mobile .post-toc__list {
  padding-block-end: var(--space-md);
}

.post-toc--desktop {
  display: none;
}

@media (min-width: 52rem) {
  .post-layout {
    grid-template-columns: minmax(0, 1fr) 11rem;
  }

  .post-body-column {
    grid-row: 1;
  }

  .post-toc--mobile {
    display: none;
  }

  .post-toc--desktop {
    display: block;
    position: sticky;
    top: calc(var(--navbar-height) + var(--space-lg));
    grid-column: 2;
    grid-row: 1;
  }

  /* A thin rail down the side of the list, with the current entry's
     segment of it drawn in the link colour. */
  .post-toc--desktop .post-toc__list {
    position: relative;
    margin-block-start: var(--space-sm);
    padding-inline-start: 0.75rem;
    border-inline-start: 1px solid var(--color-rule);
  }

  .post-toc--desktop .post-toc__link[aria-current="location"]::before {
    content: '';
    position: absolute;
    inset-inline-start: -1px;
    width: 2px;
    height: 1.4em;
    border-radius: 1px;
    background: var(--color-link);
  }
}

/* ============================================
   Article content (rendered markdown)
   ============================================ */

.post-content {
  color: var(--color-headline);
  font-family: var(--font-serif);
  font-size: var(--text-md);
  line-height: 1.85;
}

.post-content > * + * {
  margin-block-start: 1.1em;
}

.post-content :is(h1, h2, h3, h4, h5, h6) {
  margin-block: 2em 0.6em;
  color: var(--color-headline);
  font-family: var(--font-display-editorial);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  scroll-margin-top: calc(var(--navbar-height) + var(--space-lg));
}

.post-content h1 { font-size: 2em; }
.post-content h2 { font-size: 1.65em; }
.post-content h3 { font-size: 1.35em; }
.post-content h4 { font-size: 1.15em; }

/* The "#" link content/heading.go puts after each heading. It stays out of
   the way until the heading is hovered or the link focused; on touch
   screens, where there is no hover, it is always faintly there. */
.post-content .post-heading__anchor {
  position: relative;
  margin-inline-start: 0.35em;
  padding-inline: 0.1em;
  color: var(--color-muted);
  font-family: var(--font-sans);
  font-size: 0.7em;
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
  transition: opacity var(--transition-base), color var(--transition-base);
}

.post-content :is(h1, h2, h3, h4, h5, h6):hover .post-heading__anchor,
.post-content .post-heading__anchor:focus-visible,
.post-content .post-heading__anchor[data-state="copied"] {
  opacity: 1;
}

.post-content .post-heading__anchor:hover,
.post-content .post-heading__anchor:focus-visible {
  color: var(--color-link);
}

@media (hover: none) {
  .post-content .post-heading__anchor {
    opacity: 0.5;
  }
}

/* heading-links.js sets data-state while the link is on the clipboard. */
.post-content .post-heading__anchor[data-state="copied"]::after {
  content: 'Link copied';
  position: absolute;
  inset-block-end: calc(100% + 0.35rem);
  inset-inline-start: 50%;
  translate: -50% 0;
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-sm);
  background: var(--color-headline);
  color: var(--color-on-strong);
  font-size: var(--text-2xs);
  white-space: nowrap;
  pointer-events: none;
}

.post-content :is(h1, h2, h3, h4, h5, h6) + * {
  margin-block-start: 0;
}

.post-content > :first-child {
  margin-block-start: 0;
}

.post-content a {
  color: var(--color-link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.post-content a:hover,
.post-content a:focus-visible {
  color: var(--color-headline);
}

.post-content strong {
  font-weight: 600;
}

.post-content :is(ul, ol) {
  padding-inline-start: 1.5em;
}

.post-content li + li {
  margin-block-start: 0.4em;
}

.post-content li::marker {
  color: var(--color-muted);
}

.post-content blockquote {
  padding-inline-start: var(--space-lg);
  border-inline-start: 2px solid var(--color-rule);
  color: var(--color-paragraph);
  font-style: italic;
}

.post-content hr {
  margin-block: var(--space-2xl);
  border: none;
  text-align: center;
}

.post-content hr::after {
  content: '· · ·';
  color: var(--color-muted);
  letter-spacing: 0.75em;
}

.post-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
}

.post-content iframe {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: var(--radius-md);
}

/* Drop cap on the opening paragraph */
.post-content > p:first-of-type::first-letter {
  float: left;
  margin-block-start: 0.07em;
  margin-inline-end: 0.06em;
  color: var(--color-headline);
  font-family: var(--font-display-editorial);
  font-size: 3.75em;
  font-weight: 700;
  line-height: 0.82;
}

/* Inline code */
.post-content :not(pre) > code {
  padding: 0.15em 0.35em;
  border-radius: var(--radius-sm);
  background-color: var(--color-inline-code);
  font-family: var(--font-mono);
  font-size: 0.88em;
}

/* Code blocks: content.go wraps each in figure.code-block with a header
   holding the language label and the copy button (code-copy.js). */
.post-content .code-block {
  margin-block: var(--space-xl);
  overflow: hidden;
  border: 1px solid var(--color-code-rule);
  border-radius: var(--radius-md);
  background: var(--color-code-bg);
}

.post-content .code-block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: 0.45rem 0.6rem 0.45rem 1rem;
  border-block-end: 1px solid var(--color-code-rule);
  background: var(--color-code-header);
}

.post-content .code-block__label {
  color: var(--color-code-muted);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
}

.post-content .code-block__copy {
  padding: 0.3rem 0.65rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-code-muted);
  font-family: var(--font-sans);
  font-size: var(--text-2xs);
  cursor: pointer;
  transition: background-color var(--transition-base), color var(--transition-base);
}

.post-content .code-block__copy:hover,
.post-content .code-block__copy:focus-visible,
.post-content .code-block__copy[data-state="copied"] {
  background: var(--color-code-hover);
  color: var(--color-code-text);
}

.post-content pre {
  max-inline-size: 100%;
  margin-block: var(--space-xl);
  padding: 1rem 1.1rem;
  overflow-x: auto;
  border: 1px solid var(--color-code-rule);
  border-radius: var(--radius-md);
  background: var(--color-code-bg);
  line-height: 1.4;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--color-code-scrollbar) transparent;
}

.post-content .code-block pre {
  margin: 0;
  border: none;
  border-radius: 0;
}

.post-content pre code {
  display: block;
  inline-size: max-content;
  min-inline-size: 100%;
  color: var(--color-code-text);
  font-family: var(--font-mono);
  font-size: var(--text-code);
  font-variant-ligatures: none;
  tab-size: 2;
}

/* Tables. content/table.go wraps every table in .post-table so that a wide
   one scrolls sideways inside the body column instead of widening the page. */
.post-content .post-table {
  margin-block: var(--space-xl);
  overflow-x: auto;
  border: 1px solid var(--color-rule);
  border-radius: var(--radius-md);
  overscroll-behavior-x: contain;
}

.post-content .post-table:focus-visible {
  outline: var(--focus-ring-width) solid var(--color-link);
  outline-offset: var(--focus-ring-offset);
}

.post-content table {
  inline-size: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
}

.post-content :is(th, td) {
  padding: 0.65rem 0.9rem;
  text-align: start;
  vertical-align: top;
}

.post-content th {
  border-block-end: 1px solid var(--color-rule);
  background: var(--color-surface);
  color: var(--color-headline);
  font-weight: 600;
  vertical-align: bottom;
}

.post-content td {
  border-block-start: 1px solid var(--color-rule-soft);
  color: var(--color-paragraph);
}

.post-content tbody tr:first-child td {
  border-block-start: none;
}

/* A row whose first cell is empty continues the group named by the row
   above it, so it gets no rule of its own across that first column. */
.post-content td:first-child:empty {
  border-block-start-color: transparent;
}

.post-content td:first-child:not(:empty) {
  color: var(--color-headline);
  font-weight: 500;
}

.post-content :is(th, td)[align="right"] {
  text-align: end;
}

/* Figures stay on one line; their headings may wrap to keep columns narrow. */
.post-content td[align="right"],
.post-content td > code {
  white-space: nowrap;
}

.post-content :is(th, td)[align="center"] {
  text-align: center;
}

/* Callouts: "> [!NOTE]" and friends, rendered by content/callout.go */
.post-content .post-callout {
  margin-block: var(--space-xl);
  padding: var(--space-md) var(--space-lg);
  border-inline-start: 3px solid var(--color-link);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  background: var(--color-surface);
}

.post-content .post-callout--tip {
  border-inline-start-color: var(--color-tip);
}

.post-content :is(.post-callout--important, .post-callout--warning, .post-callout--caution) {
  border-inline-start-color: var(--color-warm);
}

.post-content .post-callout__heading {
  margin-block-end: var(--space-xs);
  color: var(--color-headline);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
}

.post-content .post-callout__body > * + * {
  margin-block-start: 0.75em;
}

/* Related posts, in the same list style as the posts index */
.post-related {
  margin-block-start: var(--space-3xl);
}

.post-related__title {
  padding-block-end: var(--space-md);
}
