@namespace epub "http://www.idpf.org/2007/ops";
@namespace svg "http://www.w3.org/2000/svg";

body {
    -webkit-locale: var(--ibooks-locale);
    -webkit-hyphens: var(--ibooks-hyphens);
    -webkit-hyphenate-character: '-';
    -webkit-hyphenate-limit-before: 3;
    -webkit-hyphenate-limit-after: 3;
    -webkit-hyphenate-limit-lines: 2;
    text-rendering: auto;
}

:root {
    /*
     This is used to insert custom fonts into the list of MATH fonts. This list is meant to match WebKit's default
     font list, minus the final `"Times New Roman", serif` at the end. It may need to be updated from time to time
     if WebKit evolves the default list.
     */
    --ibooks-math-font-family:
        "Latin Modern Math",
        "STIX Two Math",
        "XITS Math",
        "STIX Math",
        "Libertinus Math",
        "TeX Gyre Termes Math",
        "TeX Gyre Bonum Math",
        "TeX Gyre Schola",
        "DejaVu Math TeX Gyre",
        "TeX Gyre Pagella Math",
        "Asana Math",
        "Cambria Math",
        "Lucida Bright Math",
        "Minion Math",
        STIXGeneral,
        STIXSizeOneSym,
        Symbol;
}

a {
    text-decoration: none;
}

pre {
    white-space: pre-wrap;
}

table,ol,il {
    text-align: -webkit-auto;
}

h1,h2,h3,h4,h5,h6 {
    text-rendering: optimizelegibility;
}

/* -- Conditional Styles -- */

/* Fallback font */

[__ibooks_fallback_font_family] {
    font-family: var(--ibooks-fallback-font-family) !important;
}

math {
    /* Insert our fallback font in the the list of MATH fonts. */
    font-family: var(--ibooks-math-font-family), var(--ibooks-fallback-font-family);
}

/* Japanese content */

:root[__ibooks_content_is_japanese="true"] body {
    word-wrap: break-word;
    line-break: strict;
    -webkit-line-break: strict;
    -webkit-line-box-contain: block inline replaced;
}

:root:not([__ibooks_content_is_japanese="true"]) h1,
:root:not([__ibooks_content_is_japanese="true"]) h2,
:root:not([__ibooks_content_is_japanese="true"]) h3,
:root:not([__ibooks_content_is_japanese="true"]) h4,
:root:not([__ibooks_content_is_japanese="true"]) h5,
:root:not([__ibooks_content_is_japanese="true"]) h6 {
    text-align: -webkit-auto;
}

/* Chinese content */

:root[__ibooks_content_is_chinese="true"] body {
    font-family: var(--ibooks-chinese-fonts);
}

/* Overrides (V1). These attributes are applied to specific child elements */

:root[__ibooks_new_text_styling="false"] [__ibooks_override_font_family="true"] {
    font-family: var(--ibooks-font-family) !important;
}

:root[__ibooks_new_text_styling="false"] [__ibooks_override_font_family="true"] math {
    /* Insert our custom font in the the list of MATH fonts. */
    font-family: var(--ibooks-math-font-family), var(--ibooks-font-family) !important;
}

:root[__ibooks_new_text_styling="false"] [__ibooks_override_font_weight="true"] {
    font-weight: var(--ibooks-font-weight) !important;
}

:root[__ibooks_new_text_styling="false"] [__ibooks_override_text_align="true"] {
    text-align: var(--ibooks-text-align) !important;
}

:root[__ibooks_new_text_styling="false"] body {
    line-height: var(--ibooks-line-height);
    word-spacing: var(--ibooks-word-spacing);
    letter-spacing: var(--ibooks-letter-spacing);
}

:root[__ibooks_new_text_styling="false"] [__ibooks_override_font_family="true"],
:root[__ibooks_new_text_styling="false"] [__ibooks_override_text_align="true"],
:root[__ibooks_new_text_styling="false"] [__ibooks_override_font_weight="true"] {
    line-height: var(--ibooks-line-height) !important;
}

/* Overrides (v2) */

:root[__ibooks_new_text_styling="true"] [__ibooks_override_font_family] {
    font-family: var(--ibooks-font-family) !important;
}

:root[__ibooks_new_text_styling="true"] [__ibooks_override_font_family] math {
    /*
     Special case: Prefer math fonts for MATH elements. Note: This font list is meant to match WebKit's default value,
     with the final fallback switched from `"Times New Roman", serif` to `var(--ibooks-font-family)`.
     */
    /*
     Special case: Insert our custom font in the the list of MATH fonts. Note: This font list is meant
     to match WebKit's default value, with the final fallback switched from `"Times New Roman", serif`
     to `var(--ibooks-font-family)`.
     */
    font-family: var(--ibooks-math-font-family), var(--ibooks-font-family) !important;
}

:root[__ibooks_new_text_styling="true"] [__ibooks_override_font_weight] {
    font-weight: var(--ibooks-font-weight) !important;
}

:root[__ibooks_new_text_styling="true"] [__ibooks_override_text_align] {
    text-align: var(--ibooks-text-align) !important;
}

:root[__ibooks_new_text_styling="true"] [__ibooks_override_line_height] {
    line-height: var(--ibooks-line-height) !important;
}

/* For Vertical text we need to apply the line height override more aggressively to
 every element `*` so things apply consistently */
:root[__ibooks_writing_mode="vertical-rl"]
:root[__ibooks_new_text_styling="true"] [__ibooks_override_line_height] * {
    line-height: var(--ibooks-line-height) !important;
}

:root[__ibooks_new_text_styling="true"] [__ibooks_override_letter_spacing] {
    letter-spacing: var(--ibooks-letter-spacing) !important;
}

:root[__ibooks_new_text_styling="true"] [__ibooks_override_word_spacing] {
    word-spacing: var(--ibooks-word-spacing) !important;
}
