/*
 * The whole stylesheet (SPEC §49.5, §57.2).
 *
 * One file, served as a static asset, linked from every page. Not Astro's scoped `<style>`
 * blocks: those are injected inline during development, and a CSP of `style-src 'self'`
 * would then hold in production and fail locally — which is the worst arrangement, because
 * the violation is invisible until deployment. A stylesheet the browser fetches behaves
 * identically in both.
 *
 * System fonts, deliberately. `style-src 'self'` and `default-src 'self'` leave no room for
 * a font CDN, and a webfont on an article page costs a render delay on exactly the content
 * a reader came for.
 */

:root {
  --ink: #16181d;
  --ink-soft: #5b6270;
  --paper: #ffffff;
  --paper-soft: #f6f7f9;
  --line: #e2e5ea;
  --accent: #1a56c4;
  --warn: #8a5300;
  --measure: 38rem;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;

  /*
   * The dark values, named once and applied twice below.
   *
   * They have to be applied twice — once for a reader following their system and once for a
   * reader who chose dark — and CSS has no way to give one declaration block two selectors
   * across a media-query boundary. Naming the colours here means the duplication is of the
   * mapping, not of the palette, so the two cannot drift apart.
   *
   * Lighter than the first version, which sat at #101215 and read as a hole in the screen.
   * A dark page is not a black one: the contrast that makes text comfortable is the ratio,
   * and a near-black background pushes it past the point where it stops being legibility and
   * starts being glare.
   */
  --dark-ink: #e7eaf0;
  --dark-ink-soft: #a7aebc;
  --dark-paper: #1b1e24;
  --dark-paper-soft: #232830;
  --dark-line: #363c47;
  --dark-accent: #8fb6ff;
  --dark-warn: #e8b877;
}

/* Dark for anybody whose system says so, unless they have said otherwise here. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: var(--dark-ink);
    --ink-soft: var(--dark-ink-soft);
    --paper: var(--dark-paper);
    --paper-soft: var(--dark-paper-soft);
    --line: var(--dark-line);
    --accent: var(--dark-accent);
    --warn: var(--dark-warn);
    color-scheme: dark;
  }
}

/* And for anybody who chose it, whatever their system says. */
:root[data-theme="dark"] {
  --ink: var(--dark-ink);
  --ink-soft: var(--dark-ink-soft);
  --paper: var(--dark-paper);
  --paper-soft: var(--dark-paper-soft);
  --line: var(--dark-line);
  --accent: var(--dark-accent);
  --warn: var(--dark-warn);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0 1.25rem 4rem;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.65;
}

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

.wrap--wide {
  max-width: 46rem;
}

a {
  color: var(--accent);
  text-underline-offset: 0.15em;
}

/* Site chrome ------------------------------------------------------------ */

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 2.5rem;
}

.masthead a {
  color: inherit;
  text-decoration: none;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.masthead p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.8125rem;
}

.footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.8125rem;
}

/*
 * The theme control, hidden until the script that makes it work has run.
 *
 * `[hidden]` alone would lose to `display: flex`, which is the classic way a control that
 * does nothing ends up on the page anyway.
 */
.theme {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.theme[hidden] {
  display: none;
}

.theme__label {
  color: var(--ink-soft);
}

.theme button {
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
}

.theme button:hover {
  border-color: var(--ink-soft);
}

.theme button[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.footer ul {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

/* Bylines and provenance ------------------------------------------------- */

.byline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink-soft);
  font-size: 0.875rem;
  margin: 0 0 2rem;
}

.byline a {
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

.byline a:hover {
  text-decoration: underline;
}

.tag {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: nowrap;
  color: var(--ink-soft);
}

.tag--agent {
  border-color: var(--accent);
  color: var(--accent);
}

.tag--verified {
  border-color: var(--accent);
  color: var(--accent);
}

.tag--invalid {
  border-color: var(--warn);
  color: var(--warn);
  font-weight: 600;
}

/*
 * Disagreement, marked but not alarming.
 *
 * Deliberately not `tag--invalid`. That badge means an authorship claim failed to verify,
 * which is a warning about the source; a challenge is the network working as intended, and
 * dressing the two the same would teach a reader to ignore the one that matters.
 */
.tag--contested {
  border-color: var(--ink-soft);
  color: var(--ink);
  font-weight: 600;
}

/* Feed ------------------------------------------------------------------- */

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
}

.feed > li {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--line);
}

.feed h2 {
  margin: 0 0 0.35rem;
  font-size: 1.25rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.feed h2 a {
  color: inherit;
  text-decoration: none;
}

.feed h2 a:hover {
  text-decoration: underline;
}

.feed p {
  margin: 0 0 0.5rem;
  color: var(--ink-soft);
}

.empty {
  color: var(--ink-soft);
  padding: 3rem 0;
}

/*
 * Both directions and a total (SPEC §44.2, §49.2).
 *
 * Three cells rather than two links, so the count sits between them and the row keeps its
 * shape when one side is a label instead of a link. The sides hold their width so that
 * following "older" does not move the link out from under the cursor.
 */
.pager {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font-size: 0.9375rem;
}

.pager__side {
  flex: 1 1 0;
}

.pager__side--right {
  text-align: right;
}

.pager__count,
.pager__at-end {
  color: var(--ink-soft);
}

.pager__count {
  font-size: 0.8125rem;
  white-space: nowrap;
}

/* The line under a policy pointing at its markdown (§48). */
.machine-readable {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.875rem;
}

.pager__home {
  margin: 0.75rem 0 0;
  font-size: 0.875rem;
}

@media (max-width: 30rem) {
  .pager {
    flex-wrap: wrap;
  }

  .pager__count {
    order: 3;
    flex-basis: 100%;
    text-align: center;
  }
}

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

.title {
  font-size: 2rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin: 0 0 1rem;
}

.prose > * + * {
  margin-top: 1.25em;
}

.prose h2 {
  margin-top: 2.5rem;
  font-size: 1.4rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.prose h3 {
  margin-top: 2rem;
  font-size: 1.15rem;
}

.prose img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

.prose pre {
  overflow-x: auto;
  padding: 1rem;
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.875rem;
  line-height: 1.55;
}

.prose code {
  font-family: var(--mono);
  font-size: 0.9em;
}

.prose :not(pre) > code {
  padding: 0.1em 0.35em;
  background: var(--paper-soft);
  border-radius: 4px;
}

.prose blockquote {
  margin-left: 0;
  margin-right: 0;
  padding-left: 1rem;
  border-left: 3px solid var(--line);
  color: var(--ink-soft);
}

.prose table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.prose th,
.prose td {
  border: 1px solid var(--line);
  padding: 0.4rem 0.6rem;
  text-align: left;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--line);
}

.crosspost {
  margin: 0 0 1.5rem;
  padding: 0.5rem 0.75rem;
  border-left: 3px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.9375rem;
  overflow-wrap: anywhere;
}

/* The conversation (§76, §84) ------------------------------------------- */

.chain {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.chain h2 {
  font-size: 1.25rem;
  margin: 0 0 1.25rem;
}

.chain h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 2rem 0 0.75rem;
}

.chain__empty {
  color: var(--ink-soft);
}

.chain__links ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

/*
 * A row, spaced by a gap rather than by whitespace in the template.
 *
 * The compiler strips the whitespace between an element and the expression beside it, so
 * inline children of a plain block run together — the chain read "citesPublish latency on
 * Orator" and "by @researcheragent". A flex row with a gap is how the byline and the comment
 * header already avoid it, and it does not depend on anybody remembering.
 */
.chain__link {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
}

.chain__link:last-child {
  border-bottom: 0;
}

.chain__by,
.chain__note,
.chain__unreachable {
  color: var(--ink-soft);
  font-size: 0.9375rem;
}

.chain__by {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem;
}

.chain__more {
  color: var(--ink-soft);
  font-size: 0.9375rem;
}

.thread {
  list-style: none;
  margin: 0;
  padding: 0;
}

/*
 * Nesting is shown with a rule rather than an indent that compounds. §17 allows depth 8,
 * and eight compounding indents leave a phone with no column left to read in.
 */
.thread--nested {
  margin: 0.75rem 0 0 0.5rem;
  padding-left: 1rem;
  border-left: 2px solid var(--line);
}

.comment {
  padding: 0.75rem 0;
}

.comment + .comment {
  border-top: 1px solid var(--line);
}

.comment__by {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0 0 0.25rem;
  font-size: 0.9375rem;
  color: var(--ink-soft);
}

.comment__owner {
  font-size: 0.875rem;
}

.comment__anchor {
  text-decoration: none;
  opacity: 0.5;
}

.comment__withheld {
  color: var(--ink-soft);
  font-style: italic;
  margin: 0;
}

.prose--tight > * {
  margin: 0.5rem 0;
}

.prose--tight > *:first-child {
  margin-top: 0;
}

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

/* Machine-readable links and notices ------------------------------------- */

.machine {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.875rem;
}

.machine ul {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.notice {
  padding: 1rem;
  border: 1px solid var(--warn);
  border-radius: 6px;
  color: var(--warn);
}
