/* Вёрстка в духе русской технической книги: титул, оглавление, главы. */

@counter-style list-paren {
  system: extends decimal;
  suffix: ") ";
}

:root {
  --ink: #000;
  --paper: #fff;
  --serif: "Old Standard TT", "Times New Roman", serif;
  --mono: "PT Mono", ui-monospace, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.5;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}

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

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

a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.page {
  max-width: 56em;
  margin: 0 auto;
  padding: 2em 20px 5em;
}

.running-head {
  margin: 0 0 4em;
  font-size: 16px;
  font-style: italic;
  text-align: center;
}

.running-head a {
  text-decoration: none;
}

.running-head a:hover {
  text-decoration: underline;
}

/* Титул */

.title-page {
  margin: 16vh 0 4em;
  text-align: center;
}

.title-page .author {
  margin: 0 0 0.6em;
  font-style: italic;
}

.title-page h1 {
  margin: 0;
  font-size: 64px;
  font-weight: 400;
  line-height: 1;
}

.title-page p {
  margin: 0;
}

.title-page p + p {
  margin-top: 1em;
}

/*
 * Оглавление: название, отточие, дата. Отточие это float нулевой ширины
 * в конце строки: точки тянутся по последней строке названия и прячутся
 * под фоном названия и даты, поэтому длинные названия переносятся честно.
 */

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

.toc li + li {
  margin-top: 0.6em;
}

.toc a {
  display: block;
  overflow: hidden;
  text-decoration: none;
}

.toc .title {
  padding-right: 0.3em;
  background: var(--paper);
}

.toc time {
  position: relative;
  z-index: 1;
  float: right;
  padding-left: 0.3em;
  background: var(--paper);
}

.toc .leader {
  float: left;
  width: 0;
  white-space: nowrap;
}

.toc .leader::before {
  content: ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .";
}

.toc a:hover .title {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

/* Глава */

.article {
  overflow-wrap: break-word;
}

.article-head {
  margin: 0 0 3em;
}

.article h1 {
  margin: 0 0 0.4em;
  font-size: 40px;
  font-weight: 400;
  line-height: 1.15;
  text-align: center;
  text-wrap: balance;
}

.article .subtitle {
  margin: 0 0 1em;
  font-size: 22px;
  line-height: 1.4;
  text-align: center;
  text-indent: 0;
  text-wrap: balance;
}

.article .byline {
  font-size: 16px;
  font-style: italic;
  text-align: center;
  text-indent: 0;
}

.article h2 {
  margin: 2.4em 0 1em;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  text-wrap: balance;
  scroll-margin-top: 1em;
}

.article h3 {
  margin: 1.2em 0 0.3em;
  font-size: inherit;
  font-weight: 400;
  font-style: italic;
}

.article p {
  margin: 0;
  text-indent: 1.5em;
  hyphens: auto;
}

.article-head + p,
.article h2 + p,
.article h3 + p,
.article pre + p,
.article li p,
.article .callout p {
  text-indent: 0;
}

.article ol {
  list-style: list-paren;
  margin: 0.3em 0 0.5em;
  padding-left: 1.6em;
}

.article ul {
  margin: 0.3em 0 0.5em;
  padding-left: 1.6em;
}

.article li {
  margin: 0.2em 0;
  hyphens: auto;
}

.article .steps > li + li {
  margin-top: 0.7em;
}

.article em {
  hyphens: manual;
}

.article .colophon {
  margin: 3em 0 0;
  font-size: 16px;
  font-style: italic;
  text-align: center;
  text-indent: 0;
}

/* Врезка */

.callout {
  margin: 1.2em 0;
  padding: 0.8em 1.1em;
  border: 1px solid var(--ink);
}

/* Содержание главы */

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

.contents li {
  margin: 0.15em 0;
}

.contents a {
  text-decoration: none;
}

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

/* Код, листинги, формулы */

code,
pre {
  font-family: var(--mono);
}

.article :not(pre) > code {
  font-size: 0.85em;
  hyphens: manual;
}

.article details {
  margin: 0.3em 0;
}

.article summary {
  cursor: pointer;
  font-style: italic;
}

.article summary:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

.article pre {
  margin: 0.5em 0 1em;
  padding: 0.8em 0;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  overflow-x: auto;
  font-size: 15px;
  line-height: 1.45;
  tab-size: 4;
  overflow-wrap: normal;
  hyphens: none;
}

/* Таблица в книжном стиле: толстые линейки сверху и снизу, тонкая под шапкой */

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

.article table {
  width: 100%;
  min-width: 33em;
  border-collapse: collapse;
  font-size: 17px;
  line-height: 1.35;
}

.article th,
.article td {
  padding: 0.45em 0.8em 0.45em 0;
  text-align: left;
  vertical-align: top;
  hyphens: manual;
}

.article th:last-child,
.article td:last-child {
  padding-right: 0;
}

.article thead th {
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  vertical-align: bottom;
}

.article tbody tr:last-child td {
  border-bottom: 2px solid var(--ink);
}

/* Глоссарий */

.article dl {
  margin: 0;
}

.article dt {
  margin-top: 0.6em;
  font-weight: 700;
}

.article dd {
  margin: 0 0 0 1.5em;
  hyphens: auto;
}

.back {
  margin: 4em 0 0;
  font-style: italic;
  text-align: center;
}

@media (max-width: 600px) {
  body {
    font-size: 18px;
  }

  .page {
    padding-top: 1.5em;
  }

  .running-head {
    margin-bottom: 3em;
  }

  .title-page {
    margin-top: 10vh;
  }

  .title-page h1 {
    font-size: 48px;
  }

  .article h1 {
    font-size: 32px;
  }

  .article .subtitle {
    font-size: 19px;
  }

  .article h2 {
    font-size: 21px;
  }

  .article pre {
    font-size: 14px;
  }

  .article table {
    font-size: 16px;
  }
}

@media print {
  body {
    font-size: 11pt;
  }

  .page {
    max-width: none;
    padding: 0;
  }

  .running-head,
  .contents,
  .back {
    display: none;
  }

  .article h2,
  .article h3 {
    break-after: avoid;
  }

  .article pre {
    white-space: pre-wrap;
    break-inside: avoid;
    font-size: 9pt;
  }

  .table-wrap {
    overflow: visible;
  }

  .article table {
    min-width: 0;
    font-size: 10pt;
  }
}

/*
 * Раскрыть свёрнутые <details> при печати. Отдельным правилом: браузер,
 * не знающий ::details-content, отбросит только его, а не весь блок выше.
 */
@media print {
  details::details-content {
    content-visibility: visible;
  }
}
