/* @import url('https://fonts.googleapis.com/css?family=Open+Sans:300,700|Quattrocento:700'); */

:root {
    --editor-neutral-color: black;
    --editor-neutral-bgcolor: white;

    @media screen and (prefers-color-scheme: dark) {
        --editor-neutral-color: white;
        --editor-neutral-bgcolor: black;
    }
}

body {
    font-family: 'Open Sans', sans-serif;
    font-weight: lighter;
    color: var(--editor-neutral-color);
    background: var(--editor-neutral-bgcolor);
    width: 100vw;
    height: 100vh;
    margin: 0;
    /* overflow: hidden; */

    @media screen and (prefers-reduced-motion: no-preference) {
        transition: color 0.6s, background-color 0.6s;
    }
    /* 
        Dark Theme (Added in Inky 0.10.0)
        # theme: dark
    */

    &.dark {
        --editor-neutral-color: white;
        --editor-neutral-bgcolor: black;
    }
    &.light {
        --editor-neutral-color: black;
        --editor-neutral-bgcolor: white;
    }
}

.editor {
    --editor-lines-count-max: 30;
    display: grid;
    grid-template-areas: "controls controls" "code preview" "errors errors";
    grid-auto-columns: 1fr;
    column-gap: 1rem;
    font-weight: lighter;
    color: var(--editor-neutral-color);

    & & {
        border: 0.1rem solid var(--editor-neutral-color);
        border-radius: 0.4rem;
        padding: 0 0.5rem 0.5rem;
        margin: 0 0.5rem;
        box-sizing: border-box;
    }

    @media screen and (max-width: 980px) {
        grid-template-areas: "controls" "code" "preview" "errors";
    }

    &:has(>.editor-code-wrapper):not(:has(>.editor-preview)) {
        grid-template-areas: "controls" "code" "errors";
    }

    &:has(>.editor-preview):not(:has(>.editor-code-wrapper)) {
        grid-template-areas: "controls" "preview" "errors";
    }

    .controls {
        grid-area: controls;
    }

    .editor-code-wrapper {
        grid-area: code;
    }

    .editor-preview {
        grid-area: preview;
    }

    .editor-errors {
        grid-area: errors;
    }

    /* position: absolute; */
    margin: 0;
    /* padding: 0 0.5em; */
    /* -webkit-overflow-scrolling: touch;
    overflow-y: scroll;
    overflow-x: hidden; */
    height: 100%;
    width: 100%;
    /* top: 0;
    left: 0; */
    /* margin-top: 1em; */
    /* background-size: cover;
    background-repeat: no-repeat; */

    /* @media screen and (max-width: 980px) {
        margin-top: 1.5em;
    } */

    blockquote.note {
        color: var(--editor-neutral-color);
        background-color: hsl(202, 58%, 96%);
        border-left: 0.4rem solid hsl(204, 70%, 53%);
        line-height: 1.7em;
        padding: 0.5rem;
        text-align: start;
        &::before {
            content: attr(data-type) ": ";
            font-weight: bold;
            text-transform: capitalize;
        }

        .dark & {
            background-color: hsl(202, 58%, 40%);
        }
    }

    blockquote.note.note-info {
        background-color: hsl(232, 58%, 80%);
        border-left: 0.4rem solid hsl(234, 70%, 53%);

        .dark & {
            background-color: hsl(232, 58%, 30%);
        }
    }

    blockquote.note.note-error {
        background-color: hsl(352, 59%, 80%);
        border-left: 0.4rem solid hsl(354, 70%, 53%);

        .dark & {
            background-color: hsl(352, 58%, 30%);
        }
    }

    blockquote.note.note-warning {
        background-color: hsl(42, 59%, 80%);
        border-left: 0.4rem solid hsl(44, 70%, 53%);

        .dark & {
            background-color: hsl(42, 58%, 50%);
        }
    }
}

.editor-preview {
    display: block;
    max-width: 140ch;
    max-height: calc(1lh + var(--editor-lines-count-max, 0) * 1lh);
    width: inherit;
    margin: 0 auto;
    padding: 4rem 1.25rem 1.25rem;
    background: var(--editor-neutral-bgcolor);
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
    overflow-y: scroll;
    overflow-x: hidden;

    .hide {
        opacity: 0.0;
    }

    .invisible {
        display: none;
    }

    > * {
        opacity: 1.0;

        @media screen and (prefers-reduced-motion: no-preference) {
            transition: opacity 1.0s;
        }
    }

    h1,
    h2 {
        text-align: center;
        font-family: "Quattrocento", Georgia, 'Times New Roman', Times, serif;
        margin: 0;
        padding: 0;
    }

    h1 {
        font-size: 30pt;
        margin-bottom: 10px;
    }

    h2 {
        font-size: 14pt;
        font-style: italic;
        font-family: sans-serif;
        font-weight: lighter;
        color: #BBB;

        .dark & {
            color: #666;
        }
    }

    @media screen and (prefers-reduced-motion: no-preference) {
        transition: background-color 0.6s;
    }

    p {
        font-size: 13pt;
        color: #888;
        line-height: 1.7em;
        font-weight: lighter;
    }

    strong {
        color: var(--editor-neutral-color);
        font-weight: bold;
    }

    /* pre {
        display: inline-block;
    } */

    /*
        Class applied to all choices
        (Will always appear inside <p> element by default.)
    */
    .choice {
        text-align: center;
        line-height: 1.7em;
    }

    /* 
        Class applied to first choice
    */
    :not(.choice) + .choice {
        padding-top: 1rem;
    }

    /*
        Class applied to choice links
    */
    .choice > a, .choice > span {
        font-size: 15pt;
    }

    .tag {
        display: block;
        text-align: center;
        font-weight: bold;
        color: #444;
    }

    /* 
        Built-in class:
        The End # CLASS: end
    */
    .end {
        text-align: center;
        font-weight: bold;
        color: var(--editor-neutral-color);
        padding-top: 20px;
        padding-bottom: 20px;
    }
}

.controls {
    font-size: 9pt !important;
    text-align: right;
    padding: 0.5rem 1.2rem;
    margin: auto 0;
    user-select: none;
    background: var(--editor-neutral-bgcolor);

    @media screen and (prefers-reduced-motion: no-preference) {
        transition: color 0.6s, background 0.6s;
    }

    [disabled] {
        color: #ccc;
        .dark & {
            color: #444;
        }
    }

    &:not(:has(> :first-child)) {
        /* display: none; */
        padding-bottom: 0;
    }

    > *:not(:last-child):after {
        content: " | ";
    }

    > a {
        cursor: pointer;
    }
}

.editor-preview > * > a, .controls > a {
    font-weight: 700;
    color: #b97c2c;
    font-family: sans-serif;
    text-decoration: none;
    &::after {
        color: #b97c2c !important;
    }
    &:hover {
        color: var(--editor-neutral-color);
    }

    @media screen and (prefers-reduced-motion: no-preference) {
        transition: color 0.6s;
        &:hover {
            transition: color 0.1s;
        }
    }

    .dark & {
        color: #cc8f1a;

        &::after {
            color: #cc8f1a !important;
        }
    }
}

.editor-preview .unclickable, .controls .unclickable {
    font-weight: 700;
    color: #4f3411;
    font-family: sans-serif;
    text-decoration: none;
    cursor: not-allowed;

    .dark & {
        color: #c4af87;
    }
}


.editor-code {
    counter-reset: line;
    list-style: none;
    height: fit-content;
    padding-left: 0;
    margin: 0;
    border: 0.1rem solid #ddd;
    border-radius: 0.5rem;
    outline: none;
    text-align: start;
    font-family: 'SpaceMono', monospace;

    max-height: calc(1lh + var(--editor-lines-count-max, 0) * 1lh);
    overflow-y: scroll;
    overflow-wrap: anywhere;

    display: grid;
    grid-template-columns: minmax(2.5rem, auto) 1fr;
    grid-template-rows: 1.5lh repeat(auto-fit, minmax(1lh, auto)) [repeat-end];

    &.max-fill {
        grid-template-rows: 1.5lh repeat(auto-fill, minmax(1lh, auto)) [repeat-end];
    }

    &:not([contenteditable]), &:not([contenteditable="true"]) {
        user-select: none;
    }
}

.editor-code > * {
    counter-increment: line;
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: subgrid;
    column-gap: 0.5rem;
}

.editor-code > * > br:only-child {
    margin-top: 1rem;
}

.editor-code > *::before {
    content: counter(line);
    display: inline-block;
    border-right: 0.1rem solid #ddd;
    padding: 0 0.5rem;
    color: #888;
    text-align: right;
    user-select: none;
    -webkit-user-select: none;
}

.editor-code > *:first-child, .editor-code > *:first-child::before {
    padding-top: 0.5lh;
}

.editor-code > *:first-child::before {
    margin-top: -0.5lh;
}

.editor-code > *:last-child, .editor-code > *:last-child::before {
    padding-bottom: 0.5lh;
}

.editor-code > *:last-child::before {
    margin-bottom: -0.5lh;
}

.editor-code > *:last-child {
    grid-row: var(--sibling-index) / span repeat-end;
}

.sibling-index > * {
    --si1: 0;
    --si2: 0;

    /* --sibling-index works between 0 and 99 */
    --sibling-index: calc(10 * var(--si2) + var(--si1));

    &:nth-child(10n+1) {
        --si1: 1;
    }
    &:nth-child(10n+2) {
        --si1: 2;
    }
    &:nth-child(10n+3) {
        --si1: 3;
    }
    &:nth-child(10n+4) {
        --si1: 4;
    }
    &:nth-child(10n+5) {
        --si1: 5;
    }
    &:nth-child(10n+6) {
        --si1: 6;
    }
    &:nth-child(10n+7) {
        --si1: 7;
    }
    &:nth-child(10n+8) {
        --si1: 8;
    }
    &:nth-child(10n+9) {
        --si1: 9;
    }

    &:nth-child(n + 10):nth-child(-n + 19) {
        --si2: 1;
    }
    &:nth-child(n + 20):nth-child(-n + 29) {
        --si2: 2;
    }
    &:nth-child(n + 30):nth-child(-n + 39) {
        --si2: 3;
    }
    &:nth-child(n + 40):nth-child(-n + 49) {
        --si2: 4;
    }
    &:nth-child(n + 50):nth-child(-n + 59) {
        --si2: 5;
    }
    &:nth-child(n + 60):nth-child(-n + 69) {
        --si2: 6;
    }
    &:nth-child(n + 70):nth-child(-n + 79) {
        --si2: 7;
    }
    &:nth-child(n + 80):nth-child(-n + 89) {
        --si2: 8;
    }
    &:nth-child(n + 90):nth-child(-n + 99) {
        --si2: 9;
    }
    &:nth-child(n + 100) {
        --si2: unset;
    }
}