/* =========================================================================
   Article pages — loaded after styles.css, which carries the tokens.
   ========================================================================= */

:root {
  --measure:   552px;  /* reading column */
  --figure-bg: #fafafa;
}

@media (prefers-color-scheme: dark) {
  :root { --figure-bg: #131313; }
}

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

body.article-page {
  display: block;
  padding: 80px var(--page-x) 120px;
}

.article {
  max-width: var(--measure);
  margin: 0 auto;
}

/* Flow spacing: one rule, overridden where a block needs more air. */
.article > * + * { margin-top: 20px; }

/* -------------------------------------------------------------- sidebar */

/* Pinned in the left margin on wide screens; on anything narrower it
   collapses to just the back link, above the article. */
.side {
  max-width: var(--measure);
  margin: 0 auto 48px;
}

.side-index { display: none; }

@media (min-width: 1180px) {
  .side {
    position: fixed;
    top: 80px;
    left: clamp(24px, 5vw, 80px);
    width: 200px;
    max-width: none;
    margin: 0;
  }

  .side-index {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 56px;
  }
}

.side-back,
.side-index a {
  font-size: 13px;
  line-height: normal;
  color: var(--text-3);
  text-decoration: none;
  transition: color 150ms ease;
}

.side-back {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.side-back::before {
  content: "";
  width: 12px;
  height: 12px;
  background: currentColor;
  -webkit-mask: var(--icon-back) center / contain no-repeat;
  mask: var(--icon-back) center / contain no-repeat;
}

.side-index a { align-self: flex-start; text-wrap: pretty; }
.side-index a[aria-current="true"] { color: var(--text); }

@media (hover: hover) and (pointer: fine) {
  .side-back:hover,
  .side-index a:hover { color: var(--text); }
}

/* ---------------------------------------------------------------- head */

.article-title {
  font-size: 15px;
  font-weight: 500;
  line-height: normal;
  color: var(--text);
}

.article-date {
  margin-top: 6px;
  font-size: 15px;
  line-height: normal;
  color: var(--text-3);
}

.article-head + * { margin-top: 32px; }

/* ---------------------------------------------------------------- body */

.article p {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  text-wrap: pretty;
}

.article h2 {
  margin-top: 52px;
  font-size: 15px;
  font-weight: 500;
  line-height: normal;
  color: var(--text);
  scroll-margin-top: 80px;
}

.article h2 + * { margin-top: 16px; }

.article hr {
  margin: 44px 0;
  border: 0;
  border-top: 1px solid var(--rule);
}

.article a:not(.note-back) {
  color: inherit;
  text-decoration: underline;
  text-underline-position: from-font;
  text-decoration-thickness: from-font;
  transition: opacity 150ms ease;
}

@media (hover: hover) and (pointer: fine) {
  .article a:not(.note-back):hover { opacity: 0.6; }
}

/* Footnote markers in running text. */
.note-ref {
  font-size: 0.68em;
  cursor: pointer;
  vertical-align: super;
  line-height: 0;
  padding: 0 1px 0 2px;
  color: var(--text-3);
  text-decoration: none !important;
}

/* -------------------------------------------------------------- figures */

.figure { margin: 32px 0; }
.article > .figure + * { margin-top: 32px; }

/* Framed: screenshots and mockups sit inside a tinted container so they
   read as an artefact rather than as part of the page. */
.figure-frame {
  padding: 20px;
  border-radius: 16px;
  background: var(--figure-bg);
  box-shadow: inset 0 0 0 1px var(--glass-edge);
}

.figure-frame img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

/* Bare: charts draw on the page itself — a container would fence off the
   very whitespace the chart is using. */
.figure-bare img {
  display: block;
  width: 100%;
  height: auto;
}

.figure figcaption {
  margin-top: 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-3);
  text-align: center;
  text-wrap: pretty;
}

/* ---------------------------------------------------------------- notes */

.notes-rule {
  width: 56px;
  margin: 64px 0 28px;
  border: 0;
  border-top: 1px solid var(--rule);
}

.notes {
  display: flex;
  flex-direction: column;
  gap: 16px;
  counter-reset: note;
}

/* The whole note is a way back to the line that called it. Selecting the
   text still works — script.js only follows a click that isn't one. */
.notes li {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 10px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-2);
  text-wrap: pretty;
  cursor: pointer;
  transition: color 150ms ease;
}

@media (hover: hover) and (pointer: fine) {
  .notes li:hover { color: var(--text); }
}

/* Inline links inside a note keep their own behaviour. */
.notes li a:not(.note-back) { cursor: pointer; }

.notes li::before {
  content: counter(note);
  counter-increment: note;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.note-back {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-left: 6px;
  vertical-align: -1px;
  background: currentColor;
  color: var(--text-3);
  -webkit-mask: var(--icon-back) center / contain no-repeat;
  mask: var(--icon-back) center / contain no-repeat;
  transition: color 150ms ease;
}

@media (hover: hover) and (pointer: fine) {
  .note-back:hover { color: var(--text); }
}

/* -------------------------------------------------------------- related */

.article-foot {
  margin-top: 72px;
  padding-top: 40px;
  border-top: 1px solid var(--rule);
}

.foot-heading {
  margin-top: 0; /* not a body section — skip the h2 spacing */
  font-size: 13px;
  font-weight: 400;
  line-height: normal;
  color: var(--text-3);
}

.related-list { margin-top: 14px; }

.related-list li + li { border-top: 1px solid var(--rule); }

.related-list a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 20px;
  padding: 13px 0;
  font-size: 14px;
  color: var(--text);
  text-decoration: none !important;
  transition: opacity 150ms ease;
}

.related-list span {
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

@media (hover: hover) and (pointer: fine) {
  .related-list a:hover { opacity: 0.55; }
}

/* ---------------------------------------------------------------- pager */

.pager {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-top: 48px;
  padding-top: 28px;
  border-top: 1px solid var(--rule);
}

.pager a {
  font-size: 15px;
  line-height: 1.4;
  color: var(--text);
  text-decoration: none !important;
  transition: opacity 150ms ease;
}

.pager-label {
  display: block;
  margin-bottom: 3px;
  font-size: 13px;
  color: var(--text-3);
}

.pager-next { text-align: right; margin-left: auto; }

@media (hover: hover) and (pointer: fine) {
  .pager a:hover { opacity: 0.6; }
}

/* ---------------------------------------------------------- responsive */

@media (max-width: 640px) {
  body.article-page { padding-top: 56px; padding-bottom: 80px; }
  .article h2 { margin-top: 40px; }
}
