@charset "UTF-8";

@page {
  @top-left {
    content: string(document-title);
    color: #756960;
    font-size: 8.5pt;
  }
}

body > section.level1:first-child > h1:first-child,
body > h1:first-child {
  string-set: document-title content();
}

body {
  counter-reset: general-chapter;
}

body > section.level1 > section.level2:not(:has(> h2.unnumbered)) {
  counter-increment: general-chapter;
  counter-reset: general-section;
}

body > section.level1 > section.level2:not(:has(> h2.unnumbered)) > h2:first-child::before {
  content: counter(general-chapter) ". ";
}

body > section.level1 > section.level2:not(:has(> h2.unnumbered)) > section.level3 {
  counter-increment: general-section;
}

body
  > section.level1
  > section.level2:not(:has(> h2.unnumbered))
  > section.level3
  > h3:first-child::before {
  content: counter(general-chapter) "." counter(general-section) " ";
}

a[data-ref="chapter"]::after {
  content: "（第" target-counter(attr(href), general-chapter) "章）";
}

a[data-ref="section"]::after {
  content: "（" target-counter(attr(href), general-chapter) "."
    target-counter(attr(href), general-section) "節）";
}

#toc {
  margin: 2rem 0;
  padding: 1.2rem 1.4rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: var(--accent-soft);
}

#toc > h2 {
  margin-top: 0;
  break-after: avoid;
}

#toc ol {
  margin: 0;
  padding-left: 0;
}

#toc li {
  margin: 0.3rem 0;
  list-style: none;
  break-inside: avoid;
}

#toc > ol > li[data-section-level="1"] {
  counter-reset: general-toc-chapter;
}

#toc > ol > li[data-section-level="1"]:only-child > a {
  display: none;
}

#toc > ol > li[data-section-level="1"]:only-child > ol {
  padding-left: 0;
}

#toc li[data-section-level="2"] {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  column-gap: 0.35em;
  counter-increment: general-toc-chapter;
  counter-reset: general-toc-section;
}

#toc li[data-section-level="3"] {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  column-gap: 0.35em;
  counter-increment: general-toc-section;
}

#toc li[data-section-level="2"]::before {
  content: counter(general-toc-chapter) ".";
}

#toc li[data-section-level="3"]::before {
  content: counter(general-toc-chapter) "." counter(general-toc-section);
}

#toc li[data-section-level="2"] > a,
#toc li[data-section-level="3"] > a {
  grid-column: 2;
}

#toc li[data-section-level="2"] > ol,
#toc li[data-section-level="3"] > ol {
  grid-column: 1 / -1;
}

#toc li[data-section-level="2"]:has(> a[href$="#terminology"]),
#toc li[data-section-level="2"]:has(> a[href$="#terminology"]) li[data-section-level="3"] {
  display: block;
  counter-increment: none;
}

#toc li[data-section-level="2"]:has(> a[href$="#terminology"])::before,
#toc li[data-section-level="2"]:has(> a[href$="#terminology"]) li[data-section-level="3"]::before {
  content: none;
}

#toc li ol {
  padding-left: 1.2rem;
}

#toc li a {
  color: currentcolor;
  text-decoration: none;
}

#toc li a:hover {
  text-decoration: underline;
}

@media print {
  body > section.level1:first-child > h1:first-child,
  body > h1:first-child {
    margin-top: 0;
  }

  #toc {
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    font-size: 9pt;
  }

  #toc li a {
    display: flex;
    width: 100%;
    align-items: baseline;
  }

  #toc li a::before {
    flex: auto;
    order: 1;
    margin: 0 0.5em;
    border-bottom: 1px dotted var(--muted);
    content: "";
  }

  #toc li a::after {
    flex: none;
    order: 2;
    align-self: flex-end;
    min-width: 2em;
    content: target-counter(attr(href), page);
    text-align: right;
  }

  .print-page-break {
    break-before: page;
  }
}
