// TODO: add vars and process them
$eccgui-size-typography-whitespace-regular: $eccgui-size-typo-base !default;

// lib requisites
@import "reset";

// basics

html {
    font-size: $eccgui-size-typo-base;
    line-height: $eccgui-size-typo-base-lineheight;
}

body {
    font-family: $eccgui-font-family-default;

    // User-facing text may contain Unicode symbols (e.g. "★") that fall outside the primary font stack.
    // Browsers pick different system fallback fonts for such characters, causing glyphs to render at
    // different optical sizes (smaller in Firefox). font-size-adjust normalises the fallback font size
    // by matching the primary font's x-height, reducing the visual size discrepancy across browsers.
    font-size-adjust: from-font;
    font-weight: $eccgui-font-weight-regular;
    text-rendering: optimizelegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

code {
    font-family: $eccgui-font-family-monospace;
    font-size: 0.9em;

    .#{$eccgui}-typography__contentblock &,
    &.#{$eccgui}-typography__text {
        background-color: $eccgui-color-workspace-background;
    }
}

strong {
    font-weight: $eccgui-font-weight-bold;
}

em {
    font-family: $eccgui-font-family-cursive;
    font-style: italic;
}

sup {
    vertical-align: super;
}

sub {
    vertical-align: sub;
}

a {
    color: $eccgui-color-accent;
}

mark {
    color: $eccgui-color-info-text !important;

    /*
        we need to use important keyword overwrite here to prevent problems with
        styles from other stylesheets we cannot control here
        TODO: need to reevaluated when it is not used together with MDL anymore
    */
    background-color: eccgui-color-rgba($eccgui-color-info-background, 1) !important;
}

// HtmlContentBlock

.#{$eccgui}-typography__contentblock,
.#{$eccgui}-typography__text {
    line-height: $eccgui-size-typo-text-lineheight;
}

.#{$eccgui}-typography__contentblock.#{$eccgui}-typography--small,
.#{$eccgui}-typography--small {
    font-size: $eccgui-size-typo-caption;
    line-height: $eccgui-size-typo-caption-lineheight;
}

.#{$eccgui}-typography__contentblock.#{$eccgui}-typography--large,
.#{$eccgui}-typography--large {
    font-size: $eccgui-size-typo-subtitle;
    line-height: $eccgui-size-typo-subtitle-lineheight;
}

h1 {
    .#{$eccgui}-typography__contentblock &,
    &.#{$eccgui}-typography__text {
        font-size: $eccgui-size-typo-headline;
        font-weight: $eccgui-font-weight-light;
        line-height: $eccgui-size-typo-headline-lineheight;
    }
}

h2 {
    .#{$eccgui}-typography__contentblock &,
    &.#{$eccgui}-typography__text {
        font-size: $eccgui-size-typo-title;
        font-weight: $eccgui-font-weight-light;
        line-height: $eccgui-size-typo-title-lineheight;
    }
}

h3 {
    .#{$eccgui}-typography__contentblock &,
    &.#{$eccgui}-typography__text {
        font-size: $eccgui-size-typo-subtitle;
        font-weight: $eccgui-font-weight-regular;
        line-height: $eccgui-size-typo-subtitle-lineheight;
    }
}

h4 {
    .#{$eccgui}-typography__contentblock &,
    &.#{$eccgui}-typography__text {
        font-size: $eccgui-size-typo-text;
        font-weight: $eccgui-font-weight-bold;
        line-height: $eccgui-size-typo-text-lineheight;
    }
}

h5 {
    .#{$eccgui}-typography__contentblock &,
    &.#{$eccgui}-typography__text {
        font-size: $eccgui-size-typo-caption;
        font-style: italic;
        font-weight: $eccgui-font-weight-bold;
        line-height: $eccgui-size-typo-caption-lineheight;
    }
}

h6 {
    .#{$eccgui}-typography__contentblock &,
    &.#{$eccgui}-typography__text {
        font-size: $eccgui-size-typo-caption;
        font-weight: $eccgui-font-weight-bold;
        line-height: $eccgui-size-typo-caption-lineheight;
    }
}

ul {
    .#{$eccgui}-typography__contentblock &,
    &.#{$eccgui}-typography__text {
        list-style: disc;
    }
}

ol {
    .#{$eccgui}-typography__contentblock &,
    &.#{$eccgui}-typography__text {
        list-style: decimal;
    }
}

h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
ul,
ol,
table {
    .#{$eccgui}-typography__contentblock &,
    &.#{$eccgui}-typography__text {
        &:not(:last-child) {
            margin-bottom: $eccgui-size-block-whitespace;
        }
    }
}

li {
    .#{$eccgui}-typography__contentblock &,
    &.#{$eccgui}-typography__text {
        margin-top: $eccgui-size-block-whitespace * 0.25;
        margin-bottom: $eccgui-size-block-whitespace * 0.25;
        margin-left: $eccgui-size-block-whitespace * 2;
    }
}

blockquote {
    .#{$eccgui}-typography__contentblock &,
    &.#{$eccgui}-typography__text {
        margin: $eccgui-size-block-whitespace * 2;
        font-style: italic;

        &:last-child {
            margin-bottom: 0;
        }
    }
}

pre {
    .#{$eccgui}-typography__contentblock &,
    &.#{$eccgui}-typography__text {
        padding: $eccgui-size-block-whitespace * 0.5;
        overflow-x: auto;
        background-color: $eccgui-color-workspace-background;

        & > div[style]:has(.#{$eccgui}-markdown__syntaxhighlighter) {
            // remove styles like padding and font from prism div
            padding: 0 !important;
            margin: 0 !important;
            font-family: inherit !important;
            font-size: inherit !important;
            line-height: inherit !important;
            background-color: transparent !important;
        }
    }
}

table {
    .#{$eccgui}-typography__contentblock & {
        @extend .#{$prefix}--data-table;
    }
}

.#{$eccgui}-typography__contentblock {
    audio,
    canvas,
    iframe,
    img,
    svg,
    video {
        max-width: 100%;
    }
}

// OverflowText

.#{$ns}-text-overflow-ellipsis,
.#{$eccgui}-typography__overflowtext,
.#{$eccgui}-typography__overflowtext--passdown * {
    // display: inherit;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
    overflow-wrap: normal;
    white-space: nowrap;
}

.#{$eccgui}-typography__overflowtext--inline {
    display: inline-block;

    &.#{$eccgui}-typography__overflowtext--passdown * {
        display: inline;
    }
}

.#{$eccgui}-typography__overflowtext--ellipsis-none {
    text-overflow: clip;
}

.#{$eccgui}-typography__overflowtext--ellipsis-reverse {
    text-overflow: ellipsis;
    text-align: left;
    direction: rtl;
    unicode-bidi: embed;

    &::after {
        /*
            hex value for &lrm;
            @see https://stackoverflow.com/questions/20798667/#comment98304322_42551367
        */
        content: "\200e";
    }

    &::before {
        /*
            hex value for &lrm;
            @see https://stackoverflow.com/questions/20798667/#comment98304322_42551367
        */
        content: "\200e";
    }
}

// InlineText

.#{$eccgui}-typography__inlinetext {
    display: inline;

    * {
        display: inline;

        & + * {
            &::before {
                content: " ";
            }
        }
    }
}

// helpers

.#{$eccgui}-typography--nooverflow {
    overflow: hidden;
}

.#{$eccgui}-typography--forcelinebreak {
    word-break: normal;
    overflow-wrap: anywhere;
}

.#{$eccgui}-typography--preventlinebreak {
    word-break: keep-all;
    white-space: nowrap;
}

.#{$eccgui}-typography--noscrollbarsonchildren * {
    overflow: visible;

    pre {
        width: fit-content;
    }
}

// white spaces
@each $whitespacePlace in ("margin", "padding") {
    @each $whitespaceDirection in ("top", "right", "bottom", "left") {
        @each $whitespaceSizeName,
            $whitespaceSizeValue
                in (
                    "tiny": $eccgui-size-typography-whitespace-regular * 0.25,
                    "small": $eccgui-size-typography-whitespace-regular * 0.5,
                    "regular": $eccgui-size-typography-whitespace-regular,
                    "large": $eccgui-size-typography-whitespace-regular * 1.5,
                    "xlarge": $eccgui-size-typography-whitespace-regular * 2
                )
        {
            .#{$eccgui}-typography__whitespace-#{$whitespacePlace}#{$whitespaceDirection}-#{$whitespaceSizeName} {
                #{$whitespacePlace}-#{$whitespaceDirection}: $whitespaceSizeValue;
            }
        }
    }
}

// Highlight spots in text bodies

:is(#{$eccgui-selector-text-spot-highlight}) {
    position: relative;
    text-decoration: none;
    transition: text-decoration 2s allow-discrete;

    &::before {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        overflow: hidden;
        content: " ";
        background-color: $eccgui-color-primary;
        opacity: 1;
        transition: all 1s ease-in;
    }

    &:empty {
        &::before {
            border-radius: 100%;
        }
    }

    &:target,
    &.#{$eccgui}-typography--spothighlight {
        text-decoration: underline;
        text-decoration-style: dotted;
        text-decoration-color: $eccgui-color-accent;

        &::before {
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            opacity: 0;
        }

        &:empty {
            &::before {
                top: -2.5 * $eccgui-size-block-whitespace;
                left: -2.5 * $eccgui-size-block-whitespace;
                width: 5 * $eccgui-size-block-whitespace;
                height: 5 * $eccgui-size-block-whitespace;
            }
        }
    }
}
