/* This file was generated with the assistance of an AI coding tool. */

/* A stylesheet for reading. The guide is thirty thousand words of prose with
   almost no pictures, so everything here serves the paragraph: a serif at a
   comfortable size, a measure that stops around seventy characters, and a
   chapter list that gets out of the way of the text.

   Light by default, dark for readers whose system asks for it. No web fonts,
   no JavaScript, no external requests. */

/* Body type: XCharter, Michael Sharpe's extension of Bitstream Charter, cut
   down to the characters this site uses and served from here. Four faces,
   about 17k each. See `/fonts/LICENCE.txt` - Bitstream's 1989 grant is what
   makes self-hosting it legitimate. Everything else on the page is a font the
   reader already has. */

@font-face {
  font-family: "XCharter";
  src: url("/fonts/xcharter-regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "XCharter";
  src: url("/fonts/xcharter-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "XCharter";
  src: url("/fonts/xcharter-bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "XCharter";
  src: url("/fonts/xcharter-bolditalic.woff2") format("woff2");
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}

:root {
  color-scheme: light dark;

  --serif: "XCharter", Charter, "Bitstream Charter", "Sitka Text", Cambria,
    Georgia, "Noto Serif", "Liberation Serif", serif;
  --sans: system-ui, "Inter", -apple-system, "Segoe UI", Cantarell,
    "Noto Sans", "Liberation Sans", sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "DejaVu Sans Mono", "Liberation Mono",
    "SFMono-Regular", Menlo, monospace;

  /* Warm off-white rather than paper white: less glare over long reading. */
  --bg: #fbfaf8;
  --surface: #fff;
  --text: #1c1b19;
  --muted: #5c5850;
  --rule: #e3ded4;
  --link: #14479e;
  --link-visited: #6b3d99;
  --mark: #fdf0a8;
  --code-bg: #f2efe8;
  --code-text: #3a352c;

  /* The column, in one place. Change these two and the whole page follows. */
  --measure: 35rem;
  --sidebar: 15rem;
  --gutter: 3rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Not black on white inverted - a soft grey on charcoal, which is what
       stops the text glowing at night. */
    --bg: #16171a;
    --surface: #1d1f23;
    --text: #dbdcdf;
    --muted: #9b9da3;
    --rule: #303338;
    --link: #a3bcff;
    --link-visited: #cfa8f0;
    --mark: #55491a;
    --code-bg: #22252b;
    --code-text: #cfd1d6;
  }
}

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

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

body {
  margin: 0;
  padding: 2rem clamp(1.1rem, 4vw, 2.5rem) 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  /* Grows a little with the viewport, then stops. */
  font-size: clamp(1.0625rem, 1rem + 0.35vw, 1.1875rem);
  line-height: 1.65;
  font-kerning: normal;
  text-rendering: optimizeLegibility;

  /* Narrow screens: title, article, chapter list, footer, in that order. */
  display: grid;
  justify-content: center;
  grid-template-columns: minmax(0, var(--measure));
  grid-template-areas:
    "header"
    "main"
    "nav"
    "footer";
  column-gap: var(--gutter);
}

/* Wide screens: the chapter list becomes a sidebar and leaves the text alone.
   It sits after the article in the source, so a screen reader, a terminal
   browser and the tab key all reach the writing first. */
@media (min-width: 64em) {
  body {
    grid-template-columns: var(--sidebar) minmax(0, var(--measure));
    grid-template-areas:
      "header header"
      "nav    main"
      "footer footer";
  }
}

.skip-link {
  position: absolute;
  left: -9999px;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
  z-index: 10;
  padding: 0.5em 0.9em;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
}

/* Links ---------------------------------------------------------------- */

a {
  color: var(--link);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

a:visited {
  color: var(--link-visited);
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 2px;
}

::selection {
  background: var(--mark);
  color: var(--text);
}

/* Masthead -------------------------------------------------------------- */

.site-header {
  grid-area: header;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3em 0.9em;
  margin-bottom: 2.5rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid var(--rule);
}

.site-header .site-title {
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
  text-decoration: none;
}

.site-header .site-title:hover {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.site-header .tagline {
  font-family: var(--sans);
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--muted);
}

/* The article ----------------------------------------------------------- */

main {
  grid-area: main;
  min-width: 0;
}

.content-inner > :first-child {
  margin-top: 0;
}

h1,
h2,
h3 {
  font-family: var(--sans);
  font-weight: 600;
  line-height: 1.2;
  text-wrap: balance;
}

h1 {
  font-size: clamp(1.7rem, 1.4rem + 1.5vw, 2.3rem);
  letter-spacing: -0.02em;
  margin: 0 0 1.5rem;
}

/* Headings need room above and very little below, so a section reads as one
   block rather than as a label floating between two. */
h2 {
  font-size: 1.2rem;
  letter-spacing: -0.005em;
  margin: 2.8rem 0 0.6rem;
}

h3 {
  font-size: 1.05rem;
  margin: 2rem 0 0.5rem;
}

p,
ul,
ol,
blockquote,
pre,
table {
  margin: 0 0 1.15rem;
}

/* Prose lists sit close to the paragraph they belong to. */
main ul,
main ol {
  padding-left: 1.4em;
}

main li + li {
  margin-top: 0.4em;
}

main li > ul,
main li > ol {
  margin: 0.4em 0 0;
}

strong {
  font-weight: 700;
}

blockquote {
  padding-left: 1.1em;
  border-left: 3px solid var(--rule);
  color: var(--muted);
  font-style: italic;
}

hr {
  height: 0;
  margin: 2.5rem 0;
  border: 0;
  border-top: 1px solid var(--rule);
}

/* Code ------------------------------------------------------------------ */

code,
kbd,
samp {
  font-family: var(--mono);
  /* Mono faces run large next to a serif; ch keeps it in proportion whatever
     the reader's font size. */
  font-size: 0.88em;
}

:not(pre) > code {
  padding: 0.1em 0.35em;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 3px;
  overflow-wrap: break-word;
}

pre {
  padding: 0.9em 1.1em;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 5px;
  line-height: 1.45;
  /* Long command lines scroll inside the block, never the page. */
  overflow-x: auto;
}

pre code {
  font-size: 0.85em;
}

/* Tables ---------------------------------------------------------------- */

.content-inner table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.9rem;
}

.content-inner th,
.content-inner td {
  padding: 0.45em 0.7em 0.45em 0;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--rule);
}

.content-inner th {
  font-weight: 600;
}

/* Previous and next ----------------------------------------------------- */

/* A reader following the guide in order should not have to go back to the
   list to carry on. Two cards, side by side where there is room. */
.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  margin-top: 3rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
}

.pager a {
  flex: 1 1 11rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--rule);
  border-radius: 5px;
  color: var(--link);
  text-decoration: none;
}

.pager a:hover {
  border-color: var(--link);
}

/* Keeps `next` on the right when it is the only one there. */
.pager-next {
  margin-left: auto;
  text-align: right;
}

/* The first and last chapters have only one of the two, and a card the width
   of the whole column reads as something more important than it is. */
.pager a:only-child {
  max-width: 24rem;
}

.pager-label {
  display: block;
  margin-bottom: 0.15rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.pager-prev .pager-label::before {
  content: "\2190\00a0";
}

.pager-next .pager-label::after {
  content: "\00a0\2192";
}

.pager-title {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.3;
}

/* The dateline at the foot of a page. */
.dateline {
  margin: 2rem 0 0;
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--muted);
}

/* Front page chapter index ---------------------------------------------- */

.is-home main dl {
  margin: 2.5rem 0 0;
}

.is-home main dt {
  margin-top: 1.6rem;
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.3;
}

.is-home main dd {
  margin: 0.25em 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* The chapter list ------------------------------------------------------ */

nav.chapters {
  grid-area: nav;
  font-family: var(--sans);
}

/* On the front page the whole list is already there, with descriptions, so
   the sidebar goes away and the article keeps the middle of the page. */
.is-home nav.chapters {
  display: none;
}

body.is-home {
  grid-template-columns: minmax(0, var(--measure));
  grid-template-areas:
    "header"
    "main"
    "footer";
}

nav.chapters h2 {
  margin: 0 0 0.7rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

nav.chapters ol {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.85rem;
  line-height: 1.35;
}

nav.chapters li {
  margin-bottom: 0.55em;
}

nav.chapters a {
  color: var(--muted);
  text-decoration: none;
}

nav.chapters a:visited {
  color: var(--muted);
}

nav.chapters a:hover {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

/* Where you are now, marked without colour alone. */
nav.chapters [aria-current="page"] {
  color: var(--text);
  font-weight: 600;
}

/* Below the article on a narrow screen, so give it a rule of its own. */
nav.chapters {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}

@media (min-width: 64em) {
  nav.chapters {
    margin-top: 0;
    padding-top: 0.4rem;
    border-top: 0;
    /* Follows you down a long page, and scrolls itself if it has to. */
    position: sticky;
    top: 2rem;
    align-self: start;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
  }
}

/* Footer ---------------------------------------------------------------- */

footer.site-footer {
  grid-area: footer;
  margin-top: 3.5rem;
  padding: 1.2rem 0 3rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--muted);
}

footer.site-footer p {
  margin: 0;
}

footer.site-footer a {
  color: var(--muted);
}

/* Paper ----------------------------------------------------------------- */

@media print {
  body {
    display: block;
    max-width: none;
    padding: 0;
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  nav.chapters,
  .pager,
  .skip-link {
    display: none;
  }

  a {
    color: #000;
  }

  /* Links are no use on paper unless they say where they go. */
  .content-inner a[href^="http"]::after {
    content: " <" attr(href) ">";
    font-family: var(--mono);
    font-size: 0.8em;
    word-break: break-all;
  }

  h2,
  h3 {
    break-after: avoid;
  }

  pre,
  blockquote {
    break-inside: avoid;
  }
}
