$pdf-base-typography: true !default;
$convert-images-to-color-profile: false !default;
@if $pdf-base-typography {

    // Base typography

    @page {
        background-color: $color-background;
    }

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

    body {
        margin: 0;
        padding: 0;
        font-family: $font-text-main;
        font-size: $font-size-default;
        color: $color-text-main;
        line-height: $line-height-default;
        orphans: $orphans;
        widows: $widows;
    }
    h1, h2, h3, h4, h5, h6 {
        font-family: $font-text-secondary;
        font-size: $font-size-default;
        line-height: $line-height-default;
        font-weight: bold;
        margin: $line-height-default 0 0 0;
        page-break-after: avoid;
        page-break-inside: avoid;
    }
    h1 {
        font-family: $font-display-main;
        font-size: $font-size-default * $font-size-bigger;
        line-height: $line-height-default * $font-size-bigger;
        margin: ($line-height-default * 2) 0 ($line-height-default * 10) 0;
        text-align: center;
    }
    h2 {
        font-size: $font-size-default * ($font-size-bigger * 0.75);
        margin: ($line-height-default * 2) 0 $line-height-default 0;
    }
    h3 {}
    h4 {
        font-style: italic;
        font-weight: inherit;
    }
    h5 {
        font-family: $font-text-main;
        font-style: italic;
        font-weight: inherit;
    }
    h6 {
        font-family: $font-text-main;
        font-weight: inherit;
    }
    p, ul, ol, dl {
        text-align: $text-align;
        letter-spacing: $letter-spacing-text;
    }
    p {
        margin: 0;
        & + p {
            text-indent: $paragraph-indent;
        }
    }

    // Indent paragraphs that are visually subsequent,
    // but separated by floated elements in the DOM.
    // We allow for up to three floated elements between
    // paragraphs. After that, editors should use `.pdf-indent`
    // as a page-refinment override.

    @if not $spaced-paras {
        @if $floated-element-classes {
            @each $class in $floated-element-classes {
                p + .#{$class} + p {
                    text-indent: $paragraph-indent;

                    &.first,
                    &.box {
                        text-indent: 0;
                    }
                }

                @each $second-sibling-class in $floated-element-classes {
                    p + .#{$class} + .#{$second-sibling-class} + p {
                        text-indent: $paragraph-indent;

                        &.first,
                        &.box {
                            text-indent: 0;
                        }
                    }

                    // Don't indent paras visually after headings,
                    // separated in the DOM by floated elements.
                    h1, h2, h3, h4, h5, h6 {
                        & + .#{$class} + .#{$second-sibling-class} + p {
                            text-indent: 0;
                        }
                    }

                    @each $third-sibling-class in $floated-element-classes {
                        p + .#{$class} + .#{$second-sibling-class} + .#{$third-sibling-class} + p {
                            text-indent: $paragraph-indent;

                            &.first,
                            &.box {
                                text-indent: 0;
                            }
                        }

                        h1, h2, h3, h4, h5, h6 {
                            & + .#{$class} + .#{$second-sibling-class} + .#{$third-sibling-class} + p {
                                text-indent: 0;
                            }
                        }
                    }
                }
            }
        }
    }

    a {
        text-decoration: none;
        color: $color-links;
        // Let long urls break over lines
        // (See https://css-tricks.com/snippets/css/prevent-long-urls-from-breaking-out-of-container/)
        overflow-wrap: break-word;
        word-wrap: break-word;
        word-break: break-word;
    }
    em, strong {

        // Prevent some fonts from expanding/contracting
        // a line's line height when em, strong present
        line-height: 100%;
    }

    // Lists
    // For detail on styling lists, see https://www.princexml.com/doc/lists/

    ul, ol {
        margin: 0 0 $line-height-default 0;
    }
    ol {
        list-style: decimal;
        ol {
            list-style-type: lower-alpha;
            ol {
                list-style-type: lower-roman;
            }
        }
    }
    ul {
        list-style-type: disc;
    }
    ul ul, ol ol, blockquote ul ul, blockquote ol ol {
        margin-bottom: 0; // See '@if spaced-paras' below
    }
    li > ul {
        margin-bottom: 0; // manages line space after sublists in lists
    }
    li {
        list-style-position: outside;
        margin-left: $paragraph-indent;
        &::marker {
            width: $paragraph-indent;
            text-align: left;
        }
    }
    li:first-of-type {
        page-break-after: avoid;
    }
    li:last-of-type {
        page-break-before: avoid;
    }
    li li:first-of-type {
        page-break-before:avoid;
    }

    // Blockquotes

    blockquote {
        margin: $line-height-default 0;
        padding: 0 $paragraph-indent;
        p {
            margin: 0;
            padding: 0;
        }
        p:first-of-type {
            text-indent: 0;
        }
        p:last-child, & ol:last-child, & ul:last-child {
            margin-bottom: 0;
        }
    }

    // Definition lists

    dl {
        margin: $line-height-default 0;
    }
    dt {
        page-break-after: avoid;
        font-weight: bold;
    }
    dd {
        margin: 0 0 $line-height-default $paragraph-indent;
    }

    // Super and subscripts

    // Prevent them from increasing line height in print output
    sup, sub {
        line-height: 0;
        font-size: 1em * $font-size-smaller;
    }
    sup {
        vertical-align: super;
    }
    sub {
        vertical-align: sub;
    }

    // Horizontal rules
    // Using <hr> as a divider (in markdown created with ***)

    $text-divider-text: "" !default;
    $text-divider-image: "" !default;
    $text-divider-image-height: $line-height-default !default;

    hr {
        content: $text-divider-text;
        border: 0;
        font-family: $font-display-main;
        text-align: center;
        margin: $line-height-default auto;
        @if $text-divider-image != "" {
            content: $text-divider-image;
            height: $text-divider-image-height;
        }
        & + p {
            text-indent: 0;
        }
    }

    // Forms

    select {
        padding: ($line-height-default / 2) ($paragraph-indent / 2);
        font-family: $font-text-secondary;
        font-size: inherit;
        color: inherit;
        border: $rule-thickness solid $color-mid;
        margin: $line-height-default 0;
        box-sizing: border-box;
        // Inline
        p > &,
        li > &,
        dd > &,
        td > &,
        th > &,
        span > & {
            font-family: inherit;
            line-height: 1;
            margin: 0;
            padding: 0;
        }
    }

    // Images
    // Also see figures partial

    img {
        max-width: 100%;
        // Control colorspace conversion. See:
        // https://www.princexml.com/forum/topic/3831/dont-convert-images
        -prince-image-magic: none;

        @if $ignore-embedded-image-color-profiles {
            // Ignores the image's own ICC profile in favour
            // of the profile for the PDF as a whole.
            -prince-image-magic: ignore-icc-profile;
        }

        @if $convert-images-to-color-profile == false {
            -prince-pdf-color-conversion: none;
        }
    }

    // Paragraphs that contain only an image.
    // This class is created by mark-parents.js.
    .p-img-only-child-parent {
        margin: $line-height-default 0;
        text-indent: 0;

        & + p {
            text-indent: 0;
        }
    }

    // An option to change the default text-indented paragraphs
    // and close-up lists etc. to have space-between instead.
    @if $spaced-paras {
        p, p + p {
            margin-bottom: $line-height-default;
            text-indent: 0;
        }
        ul ul, ol ol, blockquote ul ul, blockquote ol ol {
            // Disabled, because on most real projects we remove this.
            // margin-top: $line-height-default;
            // margin-bottom: $line-height-default;
        }
    }
}
