/*
 * The book's pages (docs/design-book-site.md, "Typography and look").
 *
 * Set like a technical manual of the 1970s and 1980s, but for reading:
 * body text in Source Serif 4 at a comfortable measure; headings, numbers,
 * captions and the furniture of the page (running header, contents,
 * labels) in IBM Plex Mono; ink on paper from the site's tokens, thin
 * square rules and no fills, one restrained accent for the current place.
 * The colors come from tokens.css; this file declares none.
 */

:root {
  --serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --rail: 17rem;
  --measure: 40rem;
  --column: 52rem;
  --hang: 5.5rem;
}

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

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

body.book {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.6 var(--serif);
  font-optical-sizing: auto;
  overflow-wrap: break-word;
}

@media (min-width: 60rem) {
  body.book {
    font-size: 19px;
  }
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  color: var(--signal);
}

a:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

/* ---- Running header ---------------------------------------------------- */

.running {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 16px;
  border-bottom: 1px solid var(--rule);
  font: 0.72rem/1.4 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.running a {
  text-decoration: none;
}

.running-label::after {
  content: " \00b7  ";
}

/* ---- Frame and contents rail ------------------------------------------- */

.frame {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  max-width: calc(var(--rail) + var(--column) + 6rem);
  margin: 0 auto;
}

.rail {
  display: none;
}

.toc-narrow {
  margin: 0 16px;
  border-bottom: 1px solid var(--hair);
  font: 0.8rem/1.5 var(--mono);
}

.toc-narrow summary {
  padding: 0.6rem 0;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

@media (min-width: 72rem) {
  .frame {
    grid-template-columns: var(--rail) minmax(0, 1fr);
    gap: 3rem;
    padding: 0 1.5rem;
  }

  .rail {
    display: block;
    position: sticky;
    top: 0;
    align-self: start;
    max-height: 100vh;
    overflow-y: auto;
    padding: 2.2rem 0 2rem;
    border-right: 1px solid var(--hair);
    font: 0.74rem/1.45 var(--mono);
  }

  .toc-narrow {
    display: none;
  }
}

.rail-list,
.rail-sections {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rail-list > li {
  margin: 0 0 0.35rem;
}

.rail-list a {
  display: grid;
  grid-template-columns: 2.4em 1fr;
  padding-right: 1rem;
  text-decoration: none;
}

.rail-list a[aria-current="page"] {
  color: var(--signal);
}

.rail-sections {
  margin: 0.35rem 0 0.6rem 2.4em;
  color: var(--muted);
}

.rail-sections li {
  margin: 0.15rem 0;
}

.rail-sections a {
  grid-template-columns: 3.4em 1fr;
}

/* ---- Text -------------------------------------------------------------- */

main {
  min-width: 0;
  padding: 0 16px 4rem;
}

.page {
  max-width: var(--column);
  margin: 0 auto;
}

.page > p,
.page > ul,
.page > ol,
.page > blockquote,
.page > aside,
.page > h1,
.page > h2,
.page > h3,
.page > h4 {
  max-width: var(--measure);
}

p {
  margin: 0 0 1em;
  hyphens: auto;
}

ul,
ol {
  padding-left: 1.4em;
}

li {
  margin: 0.2em 0;
}

code {
  font-family: var(--mono);
  font-size: 0.84em;
}

/* Headings: mono, regular weight, decimal numbers set apart, generous
   space above, a thin full-width rule over chapter and section heads. */

h1,
h2,
h3,
h4 {
  font-family: var(--mono);
  font-weight: 400;
  line-height: 1.3;
  hyphens: manual;
}

h1 {
  margin: 2.6rem 0 2rem;
  padding-top: 1.1rem;
  border-top: 2px solid var(--rule);
  font-size: 1.7rem;
  letter-spacing: 0.01em;
}

h1 .label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

h2 {
  margin: 3.2rem 0 1rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--rule);
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

h3 {
  margin: 2.2rem 0 0.7rem;
  font-size: 1rem;
}

h4 {
  margin: 1.8rem 0 0.6rem;
  font-size: 0.92rem;
}

.num {
  display: inline-block;
  min-width: 3.6em;
  font-weight: 500;
}

@media (min-width: 90rem) {
  /* The numbers hang left of the text, so the column keeps room for them
     clear of the contents rail. */
  .frame {
    max-width: calc(var(--rail) + var(--column) + var(--hang) + 6rem);
  }

  main {
    padding-left: var(--hang);
  }

  h2 .num,
  h3 .num,
  h4 .num {
    margin-left: -4.6em;
    min-width: 4.6em;
    padding-right: 1em;
    text-align: right;
  }
}

/* ---- Boxes ------------------------------------------------------------- */

blockquote {
  margin: 1.4em 0;
  padding: 0 0 0 1.2em;
  border-left: 1px solid var(--rule);
}

aside {
  margin: 1.6em 0;
  padding: 0.9em 1.1em 0.1em;
  border: 1px solid var(--rule);
}

aside.status {
  font-size: 0.92em;
}

aside.status strong:first-child {
  display: block;
  margin-bottom: 0.4em;
  font: 500 0.72rem/1.4 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

aside.status p > strong:not(:first-child) {
  font: 500 0.78em var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

aside.background {
  border-width: 1px 0;
  border-color: var(--hair);
  padding-left: 0;
  padding-right: 0;
  font-size: 0.9em;
  color: var(--muted);
}

aside.background strong:first-child {
  font: 500 0.78em var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
}

.draft {
  border: 1px dashed var(--signal);
  padding: 0.2em 0.4em;
  font: 0.8em var(--mono);
  color: var(--signal);
  background: none;
}

/* ---- Code, tables and figures ------------------------------------------ */

pre {
  margin: 1.4em 0;
  padding: 0.9em 1em;
  border: 1px solid var(--rule);
  overflow-x: auto;
  font: 0.8rem/1.5 var(--mono);
  white-space: pre;
}

pre code {
  font-size: inherit;
}

.co,
.st {
  color: var(--muted);
}

.co {
  font-style: italic;
}

.table {
  margin: 1.6em 0;
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  border-top: 2px solid var(--rule);
  border-bottom: 2px solid var(--rule);
  font-size: 0.88em;
  line-height: 1.45;
}

th,
td {
  padding: 0.45em 0.9em 0.45em 0;
  vertical-align: top;
  text-align: left;
}

th {
  border-bottom: 1px solid var(--rule);
  font: 500 0.78rem/1.4 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

tbody tr + tr td {
  border-top: 1px solid var(--hair);
}

figure {
  margin: 2em 0;
}

figure > pre,
figure > .table,
figure > p {
  margin: 0;
}

figcaption {
  margin-top: 0.6em;
  max-width: var(--measure);
  font: 0.76rem/1.5 var(--mono);
}

figcaption .label {
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-right: 0.6em;
}

/* A drawing keeps the size the layout gave it, capped at the column. */
figure.diagram svg {
  display: block;
  max-width: 100%;
  height: auto;
}

p.image img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--rule);
}

hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 2.4em 0;
}

/* ---- Contents page and pager -------------------------------------------- */

.outline-link {
  font: 0.8rem var(--mono);
}

.toc-part h2 {
  margin-top: 2.4rem;
}

.toc {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: var(--measure);
  font: 0.86rem/1.5 var(--mono);
}

.toc li,
.toc a {
  display: flex;
  align-items: baseline;
  gap: 0.6em;
}

.toc li {
  margin: 0.35em 0;
}

.toc a {
  flex: 1;
  text-decoration: none;
}

.toc .toc-number {
  min-width: 2em;
}

.toc-leader {
  flex: 1;
  border-bottom: 1px dotted var(--muted);
  transform: translateY(-0.3em);
}

.toc li.unwritten {
  color: var(--muted);
}

.toc-note {
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pager {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  max-width: var(--column);
  margin: 4rem auto 0;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font: 0.8rem/1.45 var(--mono);
}

.pager a {
  display: flex;
  flex-direction: column;
  text-decoration: none;
}

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

.pager-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Glossary: hanging terms. */

.a-glossary .page > ul,
.a-glossary ul {
  list-style: none;
  padding-left: 0;
}

.a-glossary li {
  padding-left: 1.6em;
  text-indent: -1.6em;
}

/* ---- Print --------------------------------------------------------------- */

@media print {
  body.book {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  .rail,
  .toc-narrow,
  .pager {
    display: none;
  }

  .frame {
    display: block;
    max-width: none;
  }

  .page {
    break-before: page;
  }

  figure,
  pre,
  .table,
  aside {
    break-inside: avoid;
  }

  a {
    text-decoration: none;
  }
}
