/* =============================================================================
   Content pages (articles, archive, projects, about, 404)

   Every page except the landing page uses this layout. They load base.css for
   shared tokens, typography, and components, plus this file.

   Structure every content page follows:

     body.page-article (+ optional post-<name> hook)
       #wrapper
         .site-header        persistent brand + nav
         .breadcrumb
         #main
           article
             .article-hero   category, title, meta
             .article-toc    generated by article-utils.js
             ...content...
         .site-footer
   ============================================================================= */

/* --- Page shell ---------------------------------------------------------- */

/* Background.
   The landing page paints this with a fixed <div id="bg">; content pages do not
   have that element, so the same three layers are painted here as a fixed
   pseudo-element on <body>, keeping the look consistent across the site
   without extra markup. A fixed element rather than `background-attachment:
   fixed` -- the latter janks badly on iOS, especially with three layers.

   z-index -1 keeps it behind content; #wrapper is position:relative z-index:3. */
body.page-article:before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  z-index: -1;
  background-image:
    linear-gradient(to top, var(--bg-overlay), var(--bg-overlay)),
    url("../../images/overlay.png"),
    radial-gradient(circle at 30% 20%, rgba(55, 85, 135, 0.45), rgba(14, 16, 20, 0.88));
  background-size: auto, 256px 256px, cover;
  background-repeat: no-repeat, repeat, no-repeat;
  background-position: center, center, center;
}

body.page-article #wrapper {
  padding: 0 0 2em 0;
}

/* Entry animation -- deliberately absent.
   There used to be an `article-enter` keyframe here fading the article in on
   load. It fought the cross-document view transition in base.css and caused a
   visible flicker:

     1. the browser snapshots the incoming page for the crossfade
     2. article-enter has fill-mode `both`, so at snapshot time the article is
        pinned at its `from` state -- opacity 0
     3. so the crossfade faded TO a blank page
     4. only then did article-enter run, fading the content in separately

   The view transition already provides the entry fade, in both directions and
   without a second animation on top. Browsers without it (Firefox) just swap
   pages instantly, which is ordinary web behaviour. Do not reintroduce a
   page-load animation here without removing the view transition first. */

/* Layout tokens (defaults live in base.css :root).
     --page-gutter  space between the viewport edge and #main's content
     --article-pad  the article's own inline padding
     --article-max  the article's max width, padding included
   The breadcrumb and footer are siblings of #main, not children, so they
   derive their width and padding from the same three values. That is what
   keeps their left edge on the text column at EVERY width, instead of only at
   the one breakpoint someone hand-tuned. */
@media screen and (max-width: 1080px) {
  body.page-article { --article-pad: 1.25rem; }
}

@media screen and (max-width: 736px) {
  body.page-article { --page-gutter: 0.75rem; }
}

body.page-article #main {
  width: 100%;
  padding: 0 var(--page-gutter);
}

/* No card, and the article's inner width IS the reading measure (~36rem, about
   62-68 characters). Prose, headings and furniture simply fill that inner box,
   so they all share one left edge and one right edge with no per-element
   centring -- which is what killed the earlier version, where left-aligned
   paragraphs and auto-centred headings drifted apart. Margin collapse and the
   vertical rhythm are untouched because nothing here fights the flow.

   36rem measure + 2rem padding each side = 40rem. Because the measure is in rem
   it tracks the root font size, so it stays ~65 characters at every breakpoint,
   including the 16pt root on >1680px screens. */
body.page-article #main article {
  width: 100%;
  max-width: var(--article-max);
  margin-left: auto;
  margin-right: auto;
  padding: 2.5rem var(--article-pad) 3.5rem;
  background: none;
}

@media screen and (max-width: 1080px) {
  body.page-article #main article {
    padding-top: 2rem;
    padding-bottom: 3rem;
  }
}

/* Archive (/articles/). A grid of cards needs more room than the 36rem reading
   measure, so the archive widens --article-max; the breadcrumb and footer follow
   automatically because they are sized from the same token. */
body.page-archive {
  --article-max: 68rem;
}

body.page-archive .site-header {
  padding-inline: max(1.5rem, calc((100% - 64rem) / 2));
}

/* The archive's cards reuse the landing-page .post-card component from
   base.css. The article typography rules below are deliberately strong
   (1-2-3), so the card's own spacing has to be restated at that strength. */
body.page-article #main article .posts-grid {
  margin-top: 0;
}

body.page-article #main article .post-card__title {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  line-height: 1.3;
}

body.page-article #main article .post-card p {
  margin: 0 0 0.75rem;
}

body.page-article #main article .post-card p:last-child {
  margin-bottom: 0;
}

/* Breakout. Screenshots and tables are wider than the
   prose measure. They cannot exceed a normal-flow parent, so each is pulled to
   the column's centre line and shifted back by half its own width -- a
   wrapper-free full-bleed that stays centred on the text column. width is capped
   at the viewport minus a gutter so it never triggers a horizontal scrollbar.

   Code blocks deliberately do NOT break out: a command belongs with the
   instruction paragraph above it, so <pre> stays at the text measure and shares
   the prose left edge. Long lines wrap (white-space: pre-wrap in
   article-code.css) rather than forcing a wider block. */
body.page-article #main article > .image,
body.page-article #main article > .table-scroll,
body.page-article #main .article-body > .image,
body.page-article #main .article-body > .table-scroll {
  width: min(var(--breakout-max), 100vw - 3rem);
  max-width: none;
  margin-left: 50%;
  transform: translateX(-50%);
}

/* Tables sit in a .table-scroll wrapper (role="region", tabindex="0", and an
   aria-label in the markup). On a narrow screen the table keeps a readable
   minimum width and the wrapper scrolls sideways -- by touch, trackpad, or
   arrow keys once focused -- instead of the table being clipped. */
body.page-article #main article > .table-scroll,
body.page-article #main .article-body > .table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 2rem;
}

body.page-article #main .table-scroll > table {
  min-width: 40rem;
  margin: 0;
}

/* --- Site header --------------------------------------------------------- */
/* Sticky on every content page, so you always know whose site you are on and
   how to get back. */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  width: 100%;
  margin-bottom: 1.5rem;
  /* The bar spans the viewport, but its content is held to a 52rem band centred
     on the page so the brand and nav do not fly to opposite corners on a wide
     (e.g. 4K) screen. The max() falls back to a 1.5rem gutter once the viewport
     is narrower than the band. */
  padding-block: 1rem;
  padding-inline: max(1.5rem, calc((100% - 52rem) / 2));
  background: rgba(19, 21, 25, 0.92);
  backdrop-filter: blur(0.5rem);
  -webkit-backdrop-filter: blur(0.5rem);
  border-bottom: solid 1px var(--border-bg);
}

.site-header__brand {
  border-bottom: 0;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: var(--tracking);
  text-transform: uppercase;
  white-space: nowrap;
}

.site-header__nav {
  display: flex;
  gap: 1.5rem;
}

.site-header__nav a {
  border-bottom: 0;
  font-size: 0.7rem;
  letter-spacing: var(--tracking);
  text-transform: uppercase;
  opacity: 0.7;
  transition: opacity var(--duration) ease-in-out;
}

.site-header__nav a:hover,
.site-header__nav a:focus-visible {
  opacity: 1;
}

@media screen and (max-width: 480px) {
  .site-header {
    padding: 0.75rem 1rem;
  }

  .site-header__nav {
    gap: 1rem;
  }
}

/* --- Breadcrumb ---------------------------------------------------------- */

/* Aligns with the article's text column, not the container. The breadcrumb and
   the article are both centred on the viewport axis, so giving them the same
   content-box width lines up their left edges. Sized from the layout tokens:
   the article's outer width plus the page gutter, minus both paddings. */
.breadcrumb {
  width: 100%;
  max-width: calc(var(--article-max) + 2 * var(--page-gutter));
  margin: 0 auto 0.75rem auto;
  padding: 0 calc(var(--page-gutter) + var(--article-pad));
}

/* Navigation lists opt out of the markers and indentation used by prose. */
.breadcrumb li,
.article-toc li {
  padding: 0;
}

.breadcrumb ol {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.65rem;
  letter-spacing: var(--tracking);
  text-transform: uppercase;
  opacity: 0.6;
}

.breadcrumb li + li:before {
  content: '\203A';
  margin-right: 0.5rem;
  opacity: 0.6;
}

.breadcrumb a {
  border-bottom: 0;
}

.breadcrumb a:hover {
  border-bottom: dotted 1px var(--fg-light);
}

.breadcrumb [aria-current="page"] {
  opacity: 0.85;
}


/* --- Article hero -------------------------------------------------------- */

.article-hero {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: solid 1px var(--border-bg);
}

.article-hero h1 {
  margin: 0 0 0.75rem 0;
  font-size: 1.85rem;
  line-height: 1.25;
  /* Sentence case, not the theme's spaced caps -- this is a headline to read,
     not a UI label. */
  text-transform: none;
  letter-spacing: -0.01em;
}

/* Scoped, not a bare class: `body.page-article #main article p` is 1-1-3 and
   would otherwise win the margin and leave this rule silently inert. */
body.page-article #main article .article-hero__category {
  margin: 0 0 0.5rem 0;
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: var(--tracking);
  text-transform: uppercase;
}

/* Scoped rather than !important: the competing `#main article p` rule is in
   this same file at 1-1-3, so a bare class would lose. */
body.page-article #main article .article-hero__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.1rem;
  text-transform: uppercase;
  /* Colour, not opacity: opacity on the parent creates a group the status pill
     cannot escape, which would mute it to 65% no matter what colour it sets. */
  color: var(--fg-light);
}

.article-hero__meta > * + *:before {
  content: '\00B7';
  margin-right: 0.75rem;
}

/* Reading time is filled in by article-utils.js. With JS off the slot stays
   empty. Hiding it is not enough -- it is still a DOM sibling, so the element
   after it would keep its separator dot and render a leading "· ". */
.article-hero__meta [data-reading-time]:empty {
  display: none;
}

.article-hero__meta [data-reading-time]:empty + *:before {
  content: none;
  margin-right: 0;
}

/* --- Table of contents ---------------------------------------------------
   Generated from the article's <h2>s by article-utils.js, and inserted INSIDE
   <article> -- so every selector here needs the same
   `body.page-article #main article` prefix as the typography rules further
   down, or those win on specificity and put a 1.5rem list indent back.
   -------------------------------------------------------------------------- */

body.page-article #main article .article-toc {
  margin: 0 0 2.25rem 0;
  padding: 1.125rem 1.375rem;
  border: solid 1px var(--border-bg);
  border-radius: var(--radius);
  background: var(--bg-raised);
}

body.page-article #main article .article-toc__summary {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: var(--tracking);
  text-transform: uppercase;
  opacity: 0.75;
  cursor: pointer;
  list-style: none;
}

.article-toc__summary::-webkit-details-marker {
  display: none;
}

.article-toc__summary:before {
  content: '\25B8';
  display: inline-block;
  margin-right: 0.5rem;
  transition: transform var(--duration) ease-in-out;
}

.article-toc[open] .article-toc__summary:before {
  transform: rotate(90deg);
}

body.page-article #main article .article-toc ol {
  margin: 1rem 0 0 0;
  padding: 0;
  list-style: none;
}

body.page-article #main article .article-toc li {
  margin: 0;
  padding: 0;
  list-style: none;
}

body.page-article #main article .article-toc li + li {
  margin-top: 0.55rem;
}

body.page-article #main article .article-toc a {
  display: block;
  border-bottom: 0;
  font-size: 0.85rem;
  line-height: 1.4;
  opacity: 0.8;
  transition: opacity var(--duration) ease-in-out, color var(--duration) ease-in-out;
}

body.page-article #main article .article-toc a:hover,
body.page-article #main article .article-toc a:focus-visible {
  opacity: 1;
}

body.page-article #main article .article-toc a.is-current {
  color: var(--accent);
  opacity: 1;
}

/* --- Site footer --------------------------------------------------------- */

.site-footer {
  width: 100%;
  max-width: calc(var(--article-max) + 2 * var(--page-gutter));
  margin: 2rem auto 0 auto;
  padding: 1.5rem calc(var(--page-gutter) + var(--article-pad)) 0;
  border-top: solid 1px var(--border-bg);
  text-align: center;
  font-size: 0.65rem;
  letter-spacing: var(--tracking);
  text-transform: uppercase;
  opacity: 0.6;
}

.site-footer p {
  margin: 0;
}



/* --- Article typography --------------------------------------------------

   Vertical rhythm. These are long-form reading documents and need room to
   breathe.

   The scale, loosely a 0.5rem grid:

     2.75rem   above an h2 -- separates one section from the last
     1.75rem   above an h3, and around images
     1rem      below a heading, between paragraphs, after a list
     0.4rem    between list items

   Headings carry their space ABOVE them, so a section always leads with a gap
   rather than trailing one. Margins collapse (the article is a normal block,
   not flex), so an <hr /> before an h2 does not stack with it.
   -------------------------------------------------------------------------- */

body.page-article #main article {
  line-height: 1.6;
}

/* Sentence case for section headings. The base theme sets uppercase + 0.2rem
   tracking on all h1-h6, which is a label treatment -- fine for the landing
   hero, wrong for article prose and harder to scan. h3 also needs to be
   bigger than body text, which the base 1rem does not give it. */
body.page-article #main article h2 {
  margin: 2.75rem 0 1rem;
  font-size: 1.45em;
  text-transform: none;
  letter-spacing: 0;
  scroll-margin-top: 5rem;   /* clears the sticky header on anchor jumps */
}

body.page-article #main article h3 {
  margin: 1.75rem 0 0.6rem;
  font-size: 1.15em;
  text-transform: none;
  letter-spacing: 0;
  scroll-margin-top: 5rem;
}

body.page-article #main article h4 {
  text-transform: none;
  letter-spacing: 0;
}

body.page-article #main article p {
  margin: 0 0 1rem;
}

/* Markers sit OUTSIDE the text box, in the list's left padding, so a bullet
   that wraps onto a second line lines up under its own text rather than under
   the marker (a hanging indent). */
body.page-article #main article ul,
body.page-article #main article ol {
  margin: 0 0 1rem;
  padding-left: 1.4rem;
}

body.page-article #main article ul li,
body.page-article #main article ol li {
  padding-left: 0.2rem;
}

body.page-article #main article ul li {
  list-style: square outside;
}

body.page-article #main article ul li + li,
body.page-article #main article ol li + li {
  margin-top: 0.4rem;
}

body.page-article #main article blockquote {
  margin: 0 0 1.75rem;
}

body.page-article #main article hr {
  margin: 2.75rem 0;
}

/* Anchor affordance on headings, so a step in a long guide is linkable. */
body.page-article #main article h2 .heading-anchor {
  margin-left: 0.5rem;
  border-bottom: 0;
  font-size: 0.7em;
  opacity: 0;
  transition: opacity var(--duration) ease-in-out;
}

body.page-article #main article h2:hover .heading-anchor,
body.page-article #main article h2 .heading-anchor:focus-visible {
  opacity: 0.5;
}

/* --- Note block ---------------------------------------------------------- */

body.page-article #main article .note {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 1.25rem 0;
  padding: 0.75rem 0.875rem;
  border-left: 3px solid var(--accent);
  background: rgba(var(--accent-rgb), 0.08);
  border-radius: var(--radius);
  color: inherit;
}

body.page-article #main article .note svg {
  width: 1em;
  height: 1em;
  flex: none;
  margin-top: 0.15em;
  color: var(--accent);
}

body.page-article #main article ul li.note {
  list-style: none;
  margin-left: 0;
  padding-left: 0;
}

/* --- Images -------------------------------------------------------------- */

/* Horizontal size and centring come from the breakout rule above; only the
   vertical margin lives here (a `margin: ... auto` shorthand would clobber the
   breakout's margin-left). */
body.page-article #main article .image {
  display: block;
  border-bottom: 0;
  margin-top: 1.75rem;
  margin-bottom: 1.75rem;
}

/* These guides read as "here is the step, here is what it looks like", so a
   screenshot belongs to the list or paragraph directly above it. Tighten the
   gap above to keep that pairing, and keep the full gap below to separate it
   from the next step. */
body.page-article #main article ul + .image,
body.page-article #main article ol + .image,
body.page-article #main article p + .image {
  margin-top: 0.75rem;
}

/* Consecutive screenshots are one sequence, not separate points. */
body.page-article #main article .image + .image {
  margin-top: 0.75rem;
}

body.page-article #main article .image img {
  display: block;
  width: 100%;
  height: auto;
}

/* --- Image lightbox ------------------------------------------------------ */

.article-image-modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 20, 0.95);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 10000;
  cursor: zoom-out;
}

.article-image-modal.is-visible {
  display: flex;
}

body.is-image-modal-open {
  overflow: hidden;
}

.article-image-modal__inner {
  position: relative;
  max-width: min(96vw, 1600px);
  max-height: 92vh;
  cursor: default;
}

.article-image-modal__inner img {
  display: block;
  width: auto;
  max-width: 96vw;
  height: auto;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  margin: 0 auto;
}

.article-image-modal__close {
  position: absolute;
  top: -2.75rem;
  right: -0.75rem;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: var(--fg);
  font-size: 1.35rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  cursor: pointer;
  transition: background var(--duration) ease, transform var(--duration) ease;
}

.article-image-modal__close:hover {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(1.05);
}

.article-image-modal__caption {
  margin-top: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.95rem;
  text-align: center;
}

/* --- Wide-screen reading layout ------------------------------------------
   Laptop widths (1081-1680px) get larger body text, and the column grows with
   it so line length stays the same (~36 text-widths, about 85 characters).
   Above 1680px the root font size already steps up in base.css.

   From 1320px, articles with a contents list (article-utils.js wraps them in
   .article-layout) show that list as a sticky sidebar in the left margin, and
   images, tables, and code blocks widen into the right margin. The text column
   itself does not move, so the hero, breadcrumb, and footer stay aligned.
   -------------------------------------------------------------------------- */

@media screen and (min-width: 1081px) and (max-width: 1680px) {
  body.page-article:not(.page-archive) {
    --article-max: calc(36 * 1.125rem + 2 * var(--article-pad));
  }

  body.page-article:not(.page-archive) #main article {
    font-size: 1.125rem;
  }
}

@media screen and (min-width: 1320px) {
  /* The rail hangs off the left of the text column via a negative margin, so
     the text column keeps exactly the position it has without a rail. */
  body.page-article #main .article-layout {
    display: grid;
    grid-template-columns: var(--rail-width) minmax(0, 1fr);
    column-gap: var(--rail-gap);
    align-items: start;
    margin-left: calc(-1 * (var(--rail-width) + var(--rail-gap)));
  }

  body.page-article #main .article-body {
    min-width: 0;
  }

  /* First section heading sits level with the top of the rail. */
  body.page-article #main .article-body > :first-child {
    margin-top: 0;
  }

  body.page-article #main article .article-toc {
    position: sticky;
    top: 5rem;
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
    margin: 0;
    padding: 0 0 0 0.25rem;
    border: 0;
    background: none;
    font-size: 1rem;
  }

  body.page-article #main article .article-toc ol {
    margin-top: 0.85rem;
    border-left: solid 1px var(--border-bg);
  }

  body.page-article #main article .article-toc__summary {
    font-size: 0.75rem;
  }

  body.page-article #main article .article-toc li + li {
    margin-top: 0.2rem;
  }

  body.page-article #main article .article-toc a {
    margin-left: -1px;
    padding: 0.3rem 0 0.3rem 1rem;
    border-left: solid 2px transparent;
    font-size: 0.9rem;
  }

  body.page-article #main article .article-toc a.is-current {
    border-left-color: var(--accent);
  }

  /* The site header's content band widens to match, so the brand lines up
     with the rail's left edge instead of floating inside it. Band = text
     column + rail + gap on each side, keeping it centred on the page. */
  body.page-article:has(.article-layout) .site-header {
    padding-inline: max(1.5rem, calc((100% - (var(--article-max) - 2 * var(--article-pad) + 2 * (var(--rail-width) + var(--rail-gap)))) / 2));
  }

  /* Wide content extends only to the RIGHT here: centring it on the text
     column, as narrower layouts do, would run it under the rail. The width is
     capped by the space actually left between the column and the viewport. */
  body.page-article #main .article-body > .image,
  body.page-article #main .article-body > .table-scroll,
  body.page-article #main .article-body > pre {
    width: min(var(--breakout-max), 100% + (100vw - 100%) / 2 - 3rem);
    max-width: none;
    margin-left: 0;
    transform: none;
  }
}
