/* A book, not a landing page: one readable column, quiet chrome, system fonts only (no third-party request). */

:root {
  --paper: #f7f2e8;
  --paper-deep: #efe8da;
  --ink: #1c1a17;
  --ink-soft: #4f483e;
  --rule: #d9cfbd;
  --accent: #8b2e1f;
  --ask-bg: #fbecc8;
  --ask-rule: #b7791f;
  --ask-ink: #5c3b05;
  --focus: #1d4ed8;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --measure: 66ch;
  --gutter: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #17150f;
    --paper-deep: #211e17;
    --ink: #ebe4d6;
    --ink-soft: #b9ae9b;
    --rule: #3a342a;
    --accent: #e7a389;
    --ask-bg: #3a2c0e;
    --ask-rule: #e0a43a;
    --ask-ink: #f6dfae;
    --focus: #8ab4ff;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #17150f;
  --paper-deep: #211e17;
  --ink: #ebe4d6;
  --ink-soft: #b9ae9b;
  --rule: #3a342a;
  --accent: #e7a389;
  --ask-bg: #3a2c0e;
  --ask-rule: #e0a43a;
  --ask-ink: #f6dfae;
  --focus: #8ab4ff;
  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--paper);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.6;
  font-kerning: normal;
  font-variant-numeric: oldstyle-nums proportional-nums;
  overflow-wrap: break-word;
}

@media (min-width: 768px) {
  body {
    font-size: 1.125rem;
    line-height: 1.65;
  }
}

@media (min-width: 1280px) {
  body {
    font-size: 1.1875rem;
  }
}

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

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

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

.skip {
  position: absolute;
  left: var(--gutter);
  top: -100px;
  z-index: 10;
  padding: 0.6rem 1rem;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
}

.skip:focus {
  top: 0.5rem;
}

.preview-banner {
  margin: 0;
  padding: 0.5rem var(--gutter);
  background: var(--ask-bg);
  color: var(--ask-ink);
  border-bottom: 2px solid var(--ask-rule);
  font: 600 0.8125rem/1.4 var(--sans);
  text-align: center;
}

/* Top bar: slim and typographic, it should never compete with the text. */

.bar {
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.875rem;
}

.bar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0 1rem;
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.bar-name {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.8125rem;
}

.bar-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bar-links a,
.theme-toggle {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0 0.6rem;
  color: var(--ink-soft);
  text-decoration: none;
}

.bar-links a:hover {
  color: var(--accent);
}

.theme-toggle {
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
}

.theme-toggle::before {
  content: "";
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  margin-right: 0.45em;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  background: linear-gradient(90deg, currentColor 50%, transparent 50%);
}

/* Layout: one column on phones and tablets, a margin column for "On this page" on wide screens. */

.layout {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

main {
  outline: none;
}

.chapter,
.title-page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2.5rem 0 3rem;
}

@media (min-width: 1100px) {
  .chapter {
    display: grid;
    grid-template-columns: minmax(0, var(--measure)) 15rem;
    column-gap: 4rem;
    max-width: none;
    justify-content: center;
  }

  .chapter-head {
    grid-column: 1;
    grid-row: 1;
  }

  .chapter .prose {
    grid-column: 1;
    grid-row: 2;
  }

  .toc {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: start;
    position: sticky;
    top: 1.5rem;
    margin-top: 0.5rem;
  }

  .pager {
    max-width: calc(var(--measure) + 19rem);
  }
}

.chapter-no {
  margin: 0 0 0.75rem;
  color: var(--accent);
  font-variant-caps: all-small-caps;
  letter-spacing: 0.14em;
  font-size: 1.05em;
}

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

h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(2rem, 1.4rem + 3vw, 3rem);
  font-weight: 500;
  letter-spacing: -0.01em;
}

h2 {
  margin: 2.6em 0 0.7em;
  font-size: 1.45em;
}

h3 {
  margin: 2em 0 0.5em;
  font-size: 1.15em;
}

h4 {
  margin: 1.6em 0 0.4em;
  font-size: 1em;
}

.lead {
  margin: 0 0 1rem;
  color: var(--ink-soft);
  font-size: 1.2em;
  line-height: 1.45;
  font-style: italic;
}

.page-meta {
  margin: 0;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.8125rem;
  line-height: 2.2;
}

.page-meta a {
  display: inline-block;
  padding: 0.35rem 0;
}

.prose p,
.prose ul,
.prose ol,
.prose blockquote,
.prose pre,
.prose .table-wrap {
  margin: 0 0 1.1em;
}

.prose p {
  hyphens: auto;
}

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

.prose li + li {
  margin-top: 0.3em;
}

.prose blockquote {
  margin-left: 0;
  padding-left: 1.2em;
  border-left: 2px solid var(--rule);
  color: var(--ink-soft);
  font-style: italic;
}

code {
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 0.1em 0.3em;
  border-radius: 3px;
  background: var(--paper-deep);
}

pre {
  overflow-x: auto;
  padding: 1rem;
  border-radius: 4px;
  background: var(--paper-deep);
  line-height: 1.45;
}

pre code {
  padding: 0;
  background: none;
}

/* Tables scroll inside their own box, so the page itself never scrolls sideways. */

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.875rem;
  font-variant-numeric: lining-nums tabular-nums;
}

th,
td {
  padding: 0.55rem 0.75rem 0.55rem 0;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}

th {
  font-weight: 600;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.al-r {
  text-align: right;
}

.al-c {
  text-align: center;
}

/* Reference markers: small, numeric, never shifting the line height. */

.ref {
  font-family: var(--sans);
  font-size: 0.72em;
  vertical-align: 0.35em;
  line-height: 0;
  text-decoration: none;
  font-variant-numeric: lining-nums;
  padding: 0 0.08em;
}

.ref:target,
.sources-list li:target {
  background: var(--ask-bg);
}

/* Sources: smaller type, hanging numbers in the margin. */

.sources {
  margin-top: 3.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--rule);
  font-size: 0.875em;
  line-height: 1.5;
}

.sources h2 {
  margin-top: 1em;
  font-size: 1.1em;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.12em;
}

.sources-list {
  margin: 0;
  padding: 0 0 0 2.8em;
  list-style: none;
}

.sources-list li {
  position: relative;
  margin: 0 0 0.7em;
  overflow-wrap: anywhere;
}

.src-num {
  position: absolute;
  left: -2.8em;
  width: 2.4em;
  text-align: right;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-variant-numeric: lining-nums tabular-nums;
}

.backref {
  text-decoration: none;
  padding: 0 0.2em;
}

.legend {
  margin-top: 1.2em;
  color: var(--ink-soft);
  font-style: italic;
}

/* "On this page": a collapsible list on narrow screens, a quiet margin column on wide ones. */

.toc {
  margin: 1.5rem 0 2rem;
  font-family: var(--sans);
  font-size: 0.875rem;
}

.toc summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
  color: var(--ink-soft);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

/* Below 1100px the script folds "On this page": a sign after the label says it opens (+) and closes (−). The
   browser's own marker is hidden there so only one sign shows; on wide screens the list stays open and unmarked. */
@media not all and (min-width: 1100px) {
  .toc summary {
    list-style: none;
  }

  .toc summary::-webkit-details-marker {
    display: none;
  }

  .toc summary::after {
    content: "+";
    content: "+" / "";
    margin-left: 0.6em;
    font-size: 1.25rem;
    font-weight: 400;
    line-height: 1;
    letter-spacing: 0;
    color: var(--accent);
  }

  .toc details[open] > summary::after {
    content: "\2212";
    content: "\2212" / "";
  }
}

.toc ol {
  margin: 0;
  padding: 0 0 0 1em;
  border-left: 1px solid var(--rule);
  list-style: none;
}

.toc a {
  display: block;
  padding: 0.45rem 0;
  color: var(--ink-soft);
  text-decoration: none;
  line-height: 1.35;
}

.toc a:hover {
  color: var(--accent);
}

/* ASK passages exist only in preview builds: a left rule and a label with the reason. */

.ask,
mark.ask {
  background: var(--ask-bg);
  color: var(--ask-ink);
}

div.ask {
  margin: 0 0 1.1em;
  padding: 0.6rem 1rem;
  border-left: 4px solid var(--ask-rule);
}

mark.ask {
  padding: 0.05em 0.2em;
  box-shadow: inset 3px 0 0 var(--ask-rule);
}

.ask-label {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

p.ask-label {
  margin: 0 0 0.4rem;
}

/* Home: a title page, then the table of contents. */

.title-page {
  padding-top: 4rem;
}

.title-head h1 {
  font-size: clamp(2.4rem, 1.6rem + 4vw, 3.75rem);
}

/* A quiet home page (first_screen "quiet" in site.json): the title, the description and the language links fill the
   first screen, centred in it; the whole text follows below, reached by scrolling or by the skip link. Nothing is
   hidden or loaded later, and nothing moves: the only scrolling effect is the smooth scroll that
   prefers-reduced-motion already turns off. The height leaves room for the bar above and the page's top padding;
   svh keeps a phone's browser bar out of the count, and the block grows with its content on a small screen. */
.first-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - 8rem);
  min-height: calc(100svh - 8rem);
  margin-bottom: 2.5rem;
  padding-bottom: 2.5rem;
  border-bottom: 1px solid var(--rule);
}

.first-screen .title-head {
  margin: 0;
}

.prose:focus {
  outline: none;
}

#page_text {
  scroll-margin-top: 1.5rem;
}

.contents {
  margin-top: 3rem;
}

.contents h2 {
  font-size: 1em;
  font-family: var(--sans);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.contents-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--rule);
}

.contents-list li {
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--rule);
}

.contents-list a {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  min-height: 44px;
  color: var(--ink);
  text-decoration: none;
  font-size: 1.15em;
}

.contents-list a:hover .contents-title {
  color: var(--accent);
}

.contents-no {
  flex: 0 0 2.2em;
  color: var(--accent);
  font-variant-caps: all-small-caps;
  font-variant-numeric: lining-nums tabular-nums;
  letter-spacing: 0.1em;
}

.contents-desc {
  display: block;
  margin-left: calc(2.2em + 1rem);
  color: var(--ink-soft);
  font-size: 0.9em;
  line-height: 1.45;
}

/* Previous and next chapter. */

.pager {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  max-width: var(--measure);
  margin: 0 auto 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}

.pager a {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 44px;
  max-width: 100%;
  text-decoration: none;
}

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

.pager-label {
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.foot {
  padding: 1.5rem var(--gutter) 2.5rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.8125rem;
  text-align: center;
}

.foot a {
  display: inline-block;
  padding: 0.6rem 0.2rem;
}

/* The note is prose, so it keeps the reading measure instead of the full bar width. */
.foot-note {
  max-width: var(--measure);
  margin: 0 auto;
}

.not-found {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 4rem 0;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

/* Print: the text and its sources, nothing else. */

@media print {
  :root {
    --paper: #fff;
    --ink: #000;
    --ink-soft: #333;
    --accent: #000;
    --rule: #999;
  }

  .skip,
  .preview-banner,
  .bar,
  .toc,
  .pager,
  .foot,
  .page-meta,
  .theme-toggle {
    display: none !important;
  }

  body {
    font-size: 11pt;
    line-height: 1.45;
  }

  .chapter,
  .title-page {
    display: block;
    max-width: none;
    padding: 0;
  }

  .first-screen {
    display: block;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }

  a {
    color: inherit;
    text-decoration: none;
  }

  .table-wrap {
    overflow: visible;
  }

  h2,
  h3 {
    break-after: avoid;
  }

  .sources-list li {
    break-inside: avoid;
  }
}
