@import "variables.scss";
@import "mixins.scss";
@import "toc.scss";
@import "modes.scss";

body {
    @include var(background-color, background-color);
    @include var(color, text-color);
    font-family: $font-body;
    font-size: 1.0rem;
    line-height: 1.5;
    margin-bottom: 1rem;
    text-align: justify;

    @include below-container-width {
        text-align: left;
    }
}

h1, h2, h3, h4, h5, h6 {
    margin-bottom: .1rem;
    margin-top: .5rem;
    font-family: $font-heading;
    font-weight: normal;
    text-align: center;

    &:target {
        @include var(background-color, target-background-color);
        border-radius: 1rem;
    }

    a {
        border-bottom: none;

        &:hover {
            color: $primary-color;
        }
    }
}

p {
    &:target {
        @include var(background-color, target-background-color);
        border-radius: 0.25rem;
    }
}

.container {
    position: relative;
    margin: auto;
    width: 100%;
    max-width: $container-width;
    box-sizing: border-box;

    @include below-container-width {
        padding: 0 $container-min-padding 0 $container-min-padding;
        margin: 0;
        max-width: $container-width + 2 * $container-min-padding;
    }

    @include below-two-margins {
        left: -($margin-width + $margin-inner-offset + $margin-outer-offset) / 2;
    }

    @include below-one-margin {
        left: 0;
    }
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.25rem;
    justify-content: center;
}

.tag {
    @include var(color, text-color);
    padding: 0.5rem;
    border: 1px solid $primary-color;
    transition: color 0.25s, background-color 0.25s;
    text-align: left;
    display: block;

    &:focus {
        outline: none;
    }

    &:hover, &:focus {
        background-color: rgba($primary-color, 0.2);
        @include var(color, text-color);
    }
}

.input[type="text"], textarea {
    @include textual-input;
}

nav {
    width: 100%;
    margin: 0rem 0rem 1rem 0rem;

    .container {
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
    }

    a {
        padding: 0.25rem 0.75rem 0.25rem .75rem;
        text-decoration: none;
        @include var(color, text-color);
        display: inline-block;
        border-bottom: none;
        white-space: nowrap;
    }
}

.post-subscript {
    text-align: center;
}

.post-content {
    margin-top: .5rem;
}

h1 {
    font-size: 3.0rem;
}

h2 {
    font-size: 2.6rem;
}

h3 {
    font-size: 2.2rem;
}

h4 {
    font-size: 1.8rem;
}

h5 {
    font-size: 1.4rem;
}

h6 {
    font-size: 1.0rem;
}

a {
    @include var(color, text-color);
    text-decoration: none;
    border-bottom: .2rem solid $primary-color;

    &:hover {
        color: $primary-color;
        transition: color 0.25s;
    }

    &.external-link, &.same-page-link {
        .feather {
            fill: none;
            margin-left: 0.25rem;
            position: relative;
            top: 0.125em;
        }
    }
}

.draft-link {
    border-bottom: .2rem solid $border-color;
}

img {
    max-width: 100%;
    background-color: white;
}

table {
    @include bordered-block;
    margin: auto;
    padding: 0.5rem;
}

.fold-table + table {
    tr {
        @include below-container-width {
            display: flex;
            flex-direction: column;
        }
    }
}

td {
    @include below-container-width {
        overflow-x: auto;
    }
}

td, th {
    padding: 0.5rem;
}

div.highlight tr {
    display: table-row;
}

hr.header-divider {
    background-color: $primary-color;
    height: 0.3rem;
    border: none;
    border-radius: 0.15rem;
}

hr.footer-divider {
    margin: auto;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
    border: none;
    border-bottom: $standard-border;
    max-width: $container-width;

    @include below-container-width {
        max-width: 80%;
    }
}

ul.post-list {
    list-style: none;
    padding: 0;

    li {
        @include bordered-block;
        margin-bottom: 1rem;
        padding: 1rem;
    }

    p {
        margin: 0;
    }

    a.post-title {
        border-bottom: none;
        font-size: 1.4rem;
        font-family: $font-heading;
        text-align: center;
        display: block;
    }

    p.post-status {
        margin-bottom: 0.2rem;
        margin-top: 0.2rem;
    }

    p.post-wordcount, p.post-status {
        text-align: center;
        margin-bottom: 1rem;
    }

    .series-link {
        display: flex;
        align-items: center;

        margin-top: 1rem;
        font-size: 1.1rem;
        border-top: $standard-border;
        padding-top: 1rem;

        .feather {
            fill: none;
            flex-shrink: 0;
            width: 1em;
            height: 1em;
            margin-right: 0.5em;
        }
    }
}

.katex-html {
    white-space: nowrap;
}

figure {
    break-inside: avoid;

    img {
        border: $standard-border;
        border-radius: 0.5rem;
        max-width: 70%;
        display: block;
        margin: auto;

        @include below-container-width {
            max-width: 100%;
        }
    }

    figcaption {
        text-align: center;
    }

    &.fullwide img {
        max-width: 100%;
    }

    &.tiny img {
        max-height: 15rem;
    }

    &.small img {
        max-height: 20rem;
    }

    &.medium img {
        max-height: 30rem;
    }

    &.fullwide {
        margin-left: 0;
        margin-right: 0;
    }
}

.twitter-tweet {
    margin: auto;
}

.warning {
    @include bordered-block;
    padding: 0.5rem;
    @include var(background-color, warning-background-color);
    @include var(border-color, warning-border-color);
}

/*
 Note: by absolute default (via inline CSS) feather icons are hidden.
 That's because firefox reader mode doesn't play nice with them, and
 it seems to ignore all styles in <head>. Then, the inline style
 in <head> uses !important to restore the display of icons, but provides
 limited styling. Here, we finally apply the full extent of the feather styles.
 */
.feather {
    width: 1rem;
    height: 1rem;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: currentColor;
}

.katex * {
    font-family: unset;
}

.block {
    @include bordered-block;
    margin: auto;
    padding: 0.5rem;
    width: fit-content;
}

.dialog {
    .message {
        max-width: 0.8 * $container-width;
        margin-top: 0.5rem;
        display: flex;
        flex-direction: row;

        .message-sender {
            width: 4rem;
            margin: 0.75rem;

            .feather {
                width: 2rem;
                height: 1.6rem;
            }
        }

        .message-text {
            @include bordered-block;
            display: block;
            padding: 0.75rem;
        }

        &.side-answer {
            margin-left: auto;
            flex-direction: row-reverse;
        }
    }
}

.series-navigation {
    margin-top: 1em;
    display: flex;
    flex-wrap: wrap;

    .wrapper {
        flex-grow: 1;
        display: flex;

        &.previous {
            justify-content: left;
        }

        &.next {
            justify-content: right;
        }
    }

    a, .ongoing-placeholder {
        @include bordered-block;
        padding: 0.5em 1em 0.5em 1em;
        font-size: 1.1em;
        display: flex;
        align-items: center;
        margin-top: 1em;

        .feather {
            height: 1.25em;
            width: 1.25em;
            fill: none;
            &:first-child { margin-right: 0.5em; }
            &:last-child { margin-left: 0.5em; }
        }
    }

    .ongoing-placeholder {
        border-style: dashed;
    }

    div.title {
        font-weight: bold;
    }
}

.series-status {
    &.suspended { --status-color: #f9b005; }
    &.complete { --status-color: #3dc60b; }
    &.ongoing { --status-color: #46a0ff; }

    .series-status-keyword {
        display: inline-block;
        border-bottom: .2rem solid var(--status-color);
        margin: 0 0.25rem 0 0.25rem;
    }
}

details {
    @include bordered-block;
    padding: 0.5rem 0.5rem 0 0.5rem;

    &[open] {
        padding-bottom: 0.5rem;

        summary {
            border-bottom: $standard-border;
            margin-bottom: 0.5rem;
        }
    }
}

summary {
    margin: 0 -0.5rem 0 -0.5rem;
    padding: 0.5rem;
    padding-top: 0;
}

blockquote {
    border-left: (3 * $standard-border-width) solid $primary-color;
    margin-left: 0;
    padding-left: 1rem;
}

.early-navigation-wrapper {
    margin-bottom: 3rem;
}

.side-by-side {
    display: flex;
}

.side-by-side-item {
    flex-basis: 0;
}

.internal-ref {
    text-decoration: underline;
    break-inside: avoid;

    &:target {
        @include var(background-color, target-background-color);
        border-radius: 1rem;

        .internal-ref-counter {
            @include var(background-color, target-background-color);
        }
    }
}

.internal-ref-counter {
    display: inline-block;
    border: $standard-border;
    border-radius: 0.5rem;
    padding: 0 0.25rem 0 0.25rem;
}
