/*
 * Reading styles: the full post, the blog-list cards and the editor's cell preview.
 *
 * - .reading-column: one centred column. Body text stays around 65-75 characters per line,
 *   the range that is comfortable to read; the blog list is a little wider for the card image.
 * - .prose: typography for rendered cells (Markdown, code, math, images).
 *
 * Colours come from the theme's CSS variables (plus its accent, --post-accent), so the page follows the theme.
 */

:root {
  --post-text: #464b60;           /* darker than the theme's body grey: long text needs contrast */
  --post-measure: 42rem;          /* text column (about 70 characters of Inter at 17px) */
  --post-measure-wide: 52rem;     /* blog list */
  --post-font-size: 1.0625rem;
  --post-accent: #e3730b;         /* theme-gc's orange; the theme hard-codes it rather than setting --bs-primary */
}

/* ---- layout ------------------------------------------------------------------------------- */

.reading-column {
  max-width: var(--post-measure);
  margin-inline: auto;
}

.reading-column-wide {
  max-width: var(--post-measure-wide);
}

.post-back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--bs-secondary-color);
  font-size: 0.875rem;
}

.post-back-link:hover {
  color: var(--post-accent);
}

.reading-column > .post-back-link {
  margin-bottom: 1.5rem;
}

/* ---- full post ---------------------------------------------------------------------------- */

.post-header {
  margin: 0 0 2.25rem;
}

.post-title {
  font-size: clamp(1.75rem, 1.3rem + 2vw, 2.5rem);
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin-bottom: 0.75rem;
  overflow-wrap: break-word;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  color: var(--bs-secondary-color);
  font-size: 0.875rem;
  margin: 0;
}

.post-author {
  color: var(--bs-heading-color);
  font-weight: 500;
}

.post-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--bs-border-color);
}

/* ---- blog list cards ---------------------------------------------------------------------- */

.post-card .card-body {
  padding: 1.5rem;
}

.post-card-title {
  font-size: 1.375rem;
  line-height: 1.3;
  margin-bottom: 0.5rem;
}

.post-card-title a {
  color: var(--bs-heading-color);
}

.post-card-title a:hover {
  color: var(--post-accent);
}

.post-card .post-meta {
  margin-bottom: 1rem;
}

.post-card .card-main-image {
  display: block;
  width: 100%;
  object-fit: cover;
}

/* Side by side: the text sets the card's height and the image covers its whole column */
@media (min-width: 768px) {
  .post-card .col-md-4 {
    position: relative;
    min-height: 12rem;
  }

  .post-card .card-main-image {
    position: absolute;
    inset: 0;
    height: 100%;
    border-radius: var(--bs-card-inner-border-radius) 0 0 var(--bs-card-inner-border-radius);
  }
}

.post-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

/* Phones: the image goes on top of the text, so round its top corners instead */
@media (max-width: 767.98px) {
  .post-card .card-main-image {
    aspect-ratio: 16 / 9;
    border-radius: var(--bs-card-inner-border-radius) var(--bs-card-inner-border-radius) 0 0;
  }

  .post-card .card-body {
    padding: 1.25rem;
  }
}

/* ---- prose: rendered cells ---------------------------------------------------------------- */

.prose {
  color: var(--post-text);
  font-size: var(--post-font-size);
  line-height: 1.75;
  overflow-wrap: break-word; /* long URLs and words wrap instead of widening the page */
}

.post-preview.prose {
  font-size: 1rem;
  line-height: 1.65;
}

/* Headings in a card preview stay below the card's own title */
.post-preview.prose :is(h1, h2, h3, h4, h5, h6) {
  font-size: 1.1em;
  margin-top: 1.25em;
}

.prose > :first-child,
.prose .markdown-cell > :first-child {
  margin-top: 0;
}

.prose .markdown-cell > :last-child {
  margin-bottom: 0;
}

/* Vertical rhythm: one consistent gap between paragraphs, lists, cells, ... */
.prose p,
.prose ul,
.prose ol,
.prose blockquote,
.prose table,
.prose pre,
.prose figure,
.prose .math-cell,
.prose .markdown-cell {
  margin-top: 0;
  margin-bottom: 1.25em;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
  color: var(--bs-heading-color);
  font-weight: 600;
  line-height: 1.3;
  margin: 2em 0 0.6em;
  scroll-margin-top: 5rem; /* below the fixed navbar when jumped to */
}

.prose h1 { font-size: 1.75em; }
.prose h2 { font-size: 1.45em; }
.prose h3 { font-size: 1.2em; }
.prose h4,
.prose h5,
.prose h6 { font-size: 1em; }

.prose a {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

.prose strong {
  color: var(--bs-heading-color);
}

.prose li + li {
  margin-top: 0.35em;
}

.prose li > ul,
.prose li > ol {
  margin-top: 0.35em;
  margin-bottom: 0;
}

.prose blockquote {
  padding: 0.25em 0 0.25em 1.25em;
  border-left: 3px solid var(--post-accent);
  color: var(--bs-secondary-color);
  font-style: italic;
}

.prose blockquote > :last-child {
  margin-bottom: 0;
}

.prose hr {
  margin: 2.5em auto;
  width: 30%;
  border-color: var(--bs-border-color);
  opacity: 1;
}

/* Tables scroll sideways on their own when too wide for the column */
.prose table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.9375em;
}

.prose th,
.prose td {
  padding: 0.5em 0.85em;
  border-bottom: 1px solid var(--bs-border-color);
  text-align: left;
}

.prose th {
  color: var(--bs-heading-color);
  font-weight: 600;
  border-bottom-width: 2px;
}

/* Inline code */
.prose :not(pre) > code {
  font-size: 0.875em;
  padding: 0.125em 0.35em;
  border-radius: 0.25rem;
  background: var(--bs-tertiary-bg, #f3f3f5);
  color: inherit;
  overflow-wrap: anywhere;
}

/* Code blocks: code cells and fenced code in Markdown */
.code-cell,
.prose pre {
  background: var(--bs-tertiary-bg, #f3f3f5);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  padding: 0.875rem 1rem;
  font-size: 0.875rem;
  line-height: 1.6;
  overflow-x: auto; /* scroll sideways, never wrap: indentation matters in code */
  scrollbar-width: thin;
}

.prose pre code {
  font-size: inherit;
  color: inherit;
  background: none;
  padding: 0;
}

.math-cell {
  margin: 1rem 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.image-cell {
  margin: 1rem 0;
}

/* Images never exceed the column, and very tall ones don't take over the screen */
.image-cell img,
.prose .markdown-cell img {
  display: block;
  max-width: 100%;
  max-height: 80vh;
  height: auto;
  margin-inline: auto;
  border-radius: var(--bs-border-radius);
}

/* A little more breathing room around blocks in the full post than on the cards */
.post-cells .image-cell,
.post-cells .math-cell {
  margin: 2em 0;
}

@media (max-width: 575.98px) {
  :root {
    --post-font-size: 1rem;
  }

  .code-cell,
  .prose pre {
    font-size: 0.8125rem;
  }
}

@media print {
  .post-back-link,
  .post-footer,
  .edit-post-button,
  #scheduled-notice {
    display: none !important;
  }

  .prose {
    color: #000;
  }
}
