:root {
    --base-font-size: 1.5rem;
    --font-family-serif: 'EB Garamond', Geramond, Georgia, serif;
    --font-family-monospace: "IBM Plex Mono", "Courier New", monospace;
}

@media (max-width: 991.98px) {
    :root {
        --base-font-size: 1.375rem;
    }
}

@media (max-width: 600px) {
    :root {
        --base-font-size: 1.25rem;
    }
}

@media (max-width: 400px) {
    :root {
        --base-font-size: 1rem;
    }
}

p.caption {
    color: #777;
    margin-top: 10px;
}

p code {
    white-space: inherit;
}

pre {
    word-break: normal;
    word-wrap: normal;
}

pre code {
    white-space: inherit;
}

/* General style */

body,
.popover {
    font-family: var(--font-family-serif);
    font-size: var(--base-font-size);
    line-height: 1.4;

    word-break: break-word;
    hyphens: auto;
}

/* font of bs4_book.css */
.sidebar h1,
.sidebar h2,
.sidebar li,
.book-extra,
footer,
caption, p.caption,
.anchor,
.algolia-autocomplete .aa-dropdown-menu .aa-suggestion,
.form-control /* font of bootstrap.min.css */
{
    font-family: var(--font-family-serif);
    font-size: calc(0.8 * var(--base-font-size));
    line-height: 1.0;
}

.book-extra i /* font of font-awesome icons */
{
    font-size: calc(0.8 * var(--base-font-size));
    line-height: 1.0;
}

@media (max-width: 991.98px) {
    /* font of bs4_book.css */
    .sidebar h1 {
        font-family: var(--font-family-serif);
        font-size: calc(0.8 * var(--base-font-size));
        line-height: 1.0;
    }
}

/* move scrollbar of TOC to the left side */

.sidebar {
    direction: rtl;
}

.sidebar > * {
    direction: ltr;
}

/* Sidebars should be on the sides without width restriction */
@media (min-width: 1200px) {
    .container-fluid .row {
        justify-content: space-between;
    }

    .container-fluid,
    .sidebar {
        max-width: none;
    }

    #main-nav {
        width: fit-content;
        margin-right: auto;
    }
}

.header-section-number {
    font-family: var(--font-family-monospace);
    font-size: smaller;
    color: gray;
}

main a[href*='#sec-']:not(.anchor) {
    font-family: var(--font-family-monospace);
    font-size: smaller;
}

.header-section-number:after {
    content: " ";
}

.anchor {
    vertical-align: middle;
    display: inline;
    visibility: hidden;
    font-size: inherit;
    position: absolute;
    z-index: 1;
}

.anchor i {
    font-size: calc(0.8 * var(--base-font-size));
}

h1:hover .anchor, h2:hover .anchor, h3:hover .anchor, h4:hover .anchor, h5:hover .anchor, h6:hover .anchor {
    visibility: visible;
}

.popover {
    text-align: justify;
    word-break: break-word;
    hyphens: auto;
}

.popover-header {
    background: white;
    border: none;
    margin: 0;
    padding-bottom: 0;
}

.footnote-ref sup {
    font-family: var(--font-family-monospace);
    padding: 0 0.25em;
}

.sidebar h1 {
    font-family: var(--font-family-monospace);
    font-size: 1rem;
    font-weight: bold;
}

.sidebar h2 {
    margin-bottom: 1rem;
}

main p {
    text-indent: 1.2em;
    text-align: justify;
    word-break: break-word;
    hyphens: auto;

    margin-bottom: 0;
}

main p:first-child,
main h1 + p,
main h2 + p,
main h3 + p,
main h4 + p,
main h5 + p,
main h6 + p,
main ul + p {
    text-indent: 0;
}

dd {
    padding-left: 1.2em;
}

@media (min-width: 992px) {
    main p {
        text-indent: 0;
        text-align: left;
        word-break: normal;
        hyphens: none;

        margin-bottom: 1em;
    }
}

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6, .chapter-nav {
    /*font-family: sans-serif;*/
}

main li {
    margin-bottom: 0;
    padding-left: 1.2em;
    text-indent: -1.2em;
}

main ol, main ul {
    padding-left: 1.2em;
    text-align: justify;
}

@media (min-width: 992px) {
    main ol, main ul {
        margin-left: 1.2em;
        text-align: left;
    }
}

main ol, main ul, main dl {
    margin-top: 1em;
    margin-bottom: 1em;
}

h1 {
    margin-top: calc(1.618 * 2.4 * var(--base-font-size));
    margin-bottom: calc(2.4 * var(--base-font-size));
    font-size: calc(2.4 * var(--base-font-size));
}

h2 {
    margin-top: calc(1.618 * 2.0 * var(--base-font-size));
    margin-bottom: calc(2.0 * var(--base-font-size));
    font-size: calc(2.0 * var(--base-font-size));
}

h3 {
    margin-top: calc(1.618 * 1.6 * var(--base-font-size));
    margin-bottom: calc(1.6 * var(--base-font-size));
    font-size: calc(1.6 * var(--base-font-size));
}

h4 {
    margin-top: calc(1.618 * 1.2 * var(--base-font-size));
    margin-bottom: calc(1.2 * var(--base-font-size));
    font-size: calc(1.2 * var(--base-font-size));
}

h5 {
    margin-top: calc(1.618 * 1.0 * var(--base-font-size));
    margin-bottom: calc(1.0 * var(--base-font-size));
    font-size: calc(1.0 * var(--base-font-size));
}

/*.sidebar h2 {
  font-weight: bold;
}*/

nav li.book-part {
    display: none;
}

nav li.book-part + li {
    margin-top: 1rem;
}

nav li.book-part + li a {
    /*font-weight: bold;*/
    font-family: var(--font-family-monospace);
    font-size: smaller;
    /*font-style: italic;*/
    text-decoration: underline;
}

footer a,
footer a:hover {
    color: white;
}

.references p {
    margin-bottom: 1em;
}

/* Nav adjustments */

nav > h2 {
    font-size: larger;
}

.book-toc {
    padding-top: calc(2 * 0.125rem);
}

.book-toc > li {
    margin: calc(4 * 0.125rem) 0;
}

.book-toc > li > a {
    display: block;
    padding: 0.125rem 0.125rem 0.125rem 0;
}

nav[data-toggle="toc"] .nav > li {
    margin-bottom: 0;
}

nav[data-toggle="toc"] .nav > li > a {
    padding: 0.125rem 0;
    margin: calc(2 * 0.125rem) 0;
}


nav[data-toggle="toc"] .nav a.nav-link.active {
    background-color: transparent;
    font-weight: bold;
}

nav[data-toggle="toc"] .nav-link.active + ul {
    margin-top: 0;
}

.book-extra {
    border-color: #ced4da;
}

/* Adjustments for menu max-height optimization */

@media (min-width: 992px) {
    .sidebar-book {
        margin-bottom: -3rem;
    }
}

@media (min-width: 768px) {
    .sidebar-chapter {
        margin-bottom: -3rem;
    }
}

/* Bottom navigation */

.chapter-nav .prev,
.chapter-nav .next {
    padding: 0;
    border: none;
    box-shadow: none;
    margin-top: calc(1.618 * 1.0 * var(--base-font-size));
}

.chapter-nav .prev a,
.chapter-nav .next a {
    padding: 0.5rem;
    border: 1px solid #ced4da;
    border-radius: 0.2rem;
    /*box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .15);*/
    /*padding: 0.5rem 0.75rem;*/
    /*border-radius: 1.5rem;*/
}

.chapter-nav .prev a {
    border-top-left-radius: 1.5rem;
    border-bottom-left-radius: 1.5rem;
    background-color: white;
}

.chapter-nav .next a {
    border-top-right-radius: 1.5rem;
    border-bottom-right-radius: 1.5rem;
    background-color: #eee;
    border-color: #eee;
}

/* Search field */

input#search:not(:hover)::placeholder {
    opacity: 0;
}

input#search {
    border-radius: 0.25rem 1.5rem 1.5rem;
}

.algolia-autocomplete .aa-dropdown-menu {
    border-radius: 0.25rem 1.5rem 0.25rem 0.25rem;
    width: min(calc(100% - 1.5rem), 20rem);
    margin-left: 1.5rem;
}

/* GitHub links */

#book-source i,
#book-edit i {
    /* Remove some GitHub icons (build errors when removing in source code) */
    display: none;
}

.book-extra a {
    color: gray;
}

/* Images */

.figure {
    display: block; /* to eat margin top/bottom of surrounding blocks */
}
