@import url('https://api.fontshare.com/v2/css?f[]=crimson-pro@2&display=swap');

:root {
    --color-bg: #282c34;
    --color-text: #c6d0f5;
    /* --color-blue: #8caaee; */
    --color-blue: rgb(148, 177, 255);
    --color-green: #a6d189;
    /* --color-purple: #babbf1; */
    --color-purple: #aaabee;
    --color-yellow: #e5c890;
    --color-red: #e78284;
    --color-orange: #ef9f76;
    --color-math: var(--color-yellow);
    --color-link: var(--color-green);
    --color-accent: var(--color-blue);
    --color-highlight-bg: var(--color-accent);
    --color-highlight: black;

    --buffer-width: 30px;
    --editor-width: min(700px, 90vw);
    --font-size: calc(var(--editor-width) / 25);
    --linenum-font-size: 18px;
    --tab-full-width: calc(2 * var(--font-size));
    --font-face: 'author';
    --font-weight: 200;
    --text-decoration-thickness: 0.07rem;
    --shadow: 2px 4px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0px 1.8px 7.3px rgba(0, 0, 0, 0.071), 0px 6.3px 24.7px rgba(0, 0, 0, 0.112), 0px 30px 90px rgba(0, 0, 0, 0.2);

    --bold-weight: 400;
    --Bold-weight: 600;
    --math-font-size: 0.8;
    --link-font-size: 1;
    --small-font-size: 0.7;
    --large-font-size: 1.4;
    --DM-font-size: 0.85;
    --line-height: 1.1;
    --line-padding: 0;
    --IM-font-size: 0.9;
    --IM-editing-font-size: 0.8;
}

@font-face {
    font-family: 'tex';
    src: url("../fonts/ligatures/normal.woff2");
    font-weight: 200;
    /* src: url("./fonts/mathjax/mjx-tex-n.woff2"); */
    /* unicode-range: U+2190, U+2192, U+2194, U+21A4, U+21A6, U+21D0, U+21D2, U+21D4; */
}

@font-face {
    font-family: 'tex';
    src: url("../fonts/ligatures/bold.woff2");
    font-weight: 400;
    /* src: url("./fonts/mathjax/mjx-tex-n.woff2"); */
    /* unicode-range: U+2190, U+2192, U+2194, U+21A4, U+21A6, U+21D0, U+21D2, U+21D4; */
}

/* @font-face { */
/*     font-family: 'feijoa'; */
/*     src: url("../fonts/Feijoa-Font/Feijoa Medium.otf"); */
/* } */

@font-face {
    font-family: 'author';
    src: url("../fonts/author/Author-Extralight.otf");
    font-weight: 100;
}

@font-face {
    font-family: 'author';
    src: url("../fonts/author/Author-Light.otf");
    font-weight: 200;
}

@font-face {
    font-family: 'author';
    src: url("../fonts/author/Author-Regular.otf");
    font-weight: 300;
}

@font-face {
    font-family: 'author';
    src: url("../fonts/author/Author-Medium.otf");
    font-weight: 400;
}

@font-face {
    font-family: 'author';
    src: url("../fonts/author/Author-Semibold.otf");
    font-weight: 600;
}

@font-face {
    font-family: 'author';
    src: url("../fonts/author/Author-Bold.otf");
    font-weight: 900;
}

/* *:not(.dcg-dom-change-wrapper *) { */
#alerts *,
#prompts *,
.editor .textarea,
.editor .info,
.modal {
    user-select: text;
    touch-action: manipulation;
    -webkit-user-select: text;
    font-weight: var(--font-weight);
    color: var(--color-text);
    text-decoration-thickness: var(--text-decoration-thickness);
    scrollbar-width: thin;
}

*:not(.DM *, .IM *, .dcg-dom-change-wrapper *) {
    /* font-family: 'tex', var(--font-face); */
    font-family: var(--font-face);
}

html,
body {
    margin: 0;
    /* animation: 3s spin-border-offset linear infinite; */
}

html {
    background-color: var(--color-bg);
    position: relative;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: hidden;
}

html.lineNumbers {
    counter-reset: lineNumber var(--firstRenderedLine);
}

html.relNumbers {
    counter-reset: relLineNumber calc(abs(var(--caretLineNum) - var(--firstRenderedLine)));
}

.noisy::before {
    content: "";
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%0A%3Csvg xmlns='http://www.w3.org/2000/svg' width='500' height='500'%3E%3Cfilter id='noise' x='0' y='0'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3CfeBlend mode='screen'/%3E%3C/filter%3E%3Crect width='500' height='500' filter='url(%23noise)' opacity='0.5'/%3E%3C/svg%3E");
    mix-blend-mode: soft-light;
    pointer-events: none;
    border-radius: inherit;
}

.editor {
    overflow-y: scroll;
    overflow-x: hidden;
    position: absolute;
    inset: 0;
    padding-top: 10vh;
    overflow-anchor: none;
}

.textarea {
    font-size: var(--font-size);
    max-width: var(--editor-width);
    margin: 0 auto;
    white-space: pre-wrap;
    text-shadow: var(--shadow);
}

.textarea p {
    margin: 0;
    line-height: calc(var(--line-height) * var(--font-size));
    padding-top: var(--line-padding);
    padding-bottom: var(--line-padding);
    position: relative;
    padding-left: calc(var(--tab-full-width) * var(--tabs));
}

html.lineNumbers .textarea p,
html.lineNumbers .DM,
html.relNumbers .textarea p,
html.relNumbers .DM {
    position: relative;
    margin-left: var(--buffer-width);
}

html.lineNumbers .textarea p::before,
html.relNumbers .textarea p::before {
    color: inherit;
    /* filter: brightness(80%); */
    /* color: var(--color-accent); */
    opacity: 0.8;
    font-size: var(--linenum-font-size);
    position: absolute;
    left: -30px;
    transform: translate(-100%, 0);
    font-weight: var(--font-weight);
}

html.lineNumbers .textarea p::before {
    counter-increment: lineNumber;
    content: counter(lineNumber);
}

html.relNumbers .textarea p::before {
    counter-increment: relLineNumber sign(var(--firstRenderedLine) - var(--caretLineNum));
    content: counter(relLineNumber);
    opacity: 0.5;
}

html.relNumbers .textarea p.caretInside::before {
    opacity: 1;
    content: attr(lineNum);
    /* left: calc(-25px - var(--buffer-width)); */
    /* transform: none; */
}

html.relNumbers .textarea p.caretInside+* {
    counter-reset: relLineNumber 0;
}

html.relNumbers .textarea p.caretInside~p::before {
    counter-increment: relLineNumber 1;
    content: counter(relLineNumber);
}

/* html.lineNumbers .textarea p.hidden+.DM::before { */
/*     content: counter(lineNumber); */
/*     color: inherit; */
/*     opacity: 0.8; */
/*     font-size: var(--font-size); */
/*     position: absolute; */
/*     left: -30px; */
/*     transform: translate(-100%, 0); */
/*     font-weight: var(--font-weight); */
/* } */

html.lineNumbers .textarea p.math::before,
html.relNumbers .textarea p.math::before {
    color: var(--color-math);
}

.textarea p:has(> .bullet) {
    display: flex;
}

.textarea p .bullet {
    flex: 0 0 auto;
}

.placeholder {
    width: 100vw;
    height: 90vh;
}

.caret {
    color: white;
    position: absolute;
    background-color: currentColor;
    pointer-events: none;
    mix-blend-mode: exclusion;
    border: 0px solid currentColor;
    border-radius: 1px;
}

.smooth {
    transition: left 0.1s, top 0.1s, width 0.1s, height 0.1s;
}

.info {
    background-color: var(--color-bg);
    font-size: 16pt;
    position: fixed;
    bottom: 0;
    padding: 0;
}

.leftInfo {
    left: 10px;
    padding-right: 10px;
    border-top-right-radius: 10px;
}

.rightInfo {
    right: 10px;
    padding-left: 10px;
    border-top-left-radius: 10px;
}

.textarea p * {
    pointer-events: none;
    color: inherit;
    font-weight: inherit;
}

.math {
    color: var(--color-math) !important;
    font-size: calc(var(--font-size) * var(--math-font-size));
}

.link {
    color: var(--color-link) !important;
    font-size: calc(var(--font-size) * var(--link-font-size));
}

p .link {
    text-decoration: underline;
    pointer-events: initial;
    cursor: pointer;
}

p .link:active,
.imgWrapper .editButton:active {
    filter: brightness(80%);
}

.imgWrapper {
    text-align: center;
    position: relative;
    margin: 1rem 0;
}

img {
    border-radius: 10px;
}

.editor .imgWrapper[url="undefined"] img {
    max-width: min(max(80%, 400px), 100%);
    max-height: 400px;
}

.editor .imgWrapper:not([url="undefined"]) img {
    width: min(max(80%, 400px), 100%);
}

.imgWrapper.notReady img {
    display: none;
}

#attachmentEditor {
    --width: min(90vw, 1200px, 120vh);
    width: var(--width);
    height: calc(3/4*var(--width));
    max-height: unset;
    top: calc(50vh - 3/8*var(--width));
}

#attachmentEditor .attachmentEditor {
    width: 100%;
    height: 100%;
}

.imgWrapper .editButton {
    color: white;
    font-size: 12pt;
    font-weight: inherit;
    position: absolute;
    right: 0;
    bottom: 0;
    pointer-events: initial;
    background-color: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 3px;
}

.imgWrapper[url="undefined"] .editButton {
    display: none;
}

.underline .content,
.wrapper .underline {
    text-decoration: underline;
}

.small {
    font-size: calc(var(--font-size) * var(--small-font-size));
}

.large {
    font-size: calc(var(--font-size) * var(--large-font-size));
}

.center {
    text-align: center;
}

.Bold {
    font-weight: var(--Bold-weight) !important;
}

.bold {
    font-weight: var(--bold-weight) !important;
}

/* TODO: decide about this */
.italic {
    font-style: italic;
    font-family: 'Crimson Pro', serif;
    font-size: 1.1em;
}

.highlight {
    /* background: var(--color-accent); */
    /* color: var(--color-bg) !important; */
    color: var(--color-accent) !important;
}

.capital {
    /* font-variant: small-caps; */
    text-transform: uppercase;
}

.selectionWrapper {
    position: absolute;
    top: 0;
}

.selection {
    background-color: var(--color-highlight-bg);
    color: var(--color-highlight);
    position: absolute;
    pointer-events: none;
}

.hidden {
    height: 0;
    transform: scaleY(0);
}

.DM {
    font-size: calc(var(--font-size) * var(--DM-font-size));
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
}

.DM * {
    pointer-events: none;
}

.DM mjx-container[display] {
    margin-top: 0.5em;
}

.textarea .DM mjx-container[display] {
    /* not last display math */
    margin-bottom: 1em;
}

.textarea .DM:has(+ p + .DM) mjx-container[display] {
    /* not last display math */
    margin-bottom: 0;
}

@property --border-offset-angle {
    syntax: "<angle>";
    initial-value: 0deg;
    inherits: true;
}

@keyframes spin-border-offset {
    from {
        --border-offset-angle: 0deg;
    }

    to {
        --border-offset-angle: 360deg;
    }
}

.spin_border .content,
.wrapper .spin_border {
    --border-width: 1px;
    /* --background-color: var(--color-background-secondary); */
    border: 1px solid transparent;
    border-radius: 6px;
    background-image: linear-gradient(var(--color-bg), var(--color-bg)),
        conic-gradient(from var(--border-offset-angle), transparent, transparent, var(--color-accent), transparent, transparent, var(--color-accent), transparent);
    background-origin: border-box;
    background-clip: padding-box, border-box;
    padding: 2px;
}

.wrapper:not(.editingSource) .math {
    display: none !important;
    /* height: 0; */
    /* transform: scaleY(0); */
    /* opacity: 0; */
    /* position: absolute; */
}

.wrapper.editingSource {
    position: relative;
}

.IM {
    pointer-events: all !important;
    vertical-align: baseline;
    font-size: calc(var(--IM-font-size) * 1em);
}

.wrapper.editingSource .IM {
    position: absolute;
    border-radius: 6px;
    left: 50%;
    top: 0;
    transform: translate(-50%, -100%);
    padding: 5px;
    width: max-content;
    font-size: calc(var(--IM-editing-font-size) * var(--font-size));
    text-shadow: 2px 4px 3px rgba(0, 0, 0, 0.3);
    color: white;
}

.opaque,
.wrapper.editingSource .IM {
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    box-shadow: var(--shadow);
}

.wrapper.editingSource .math {
    font-size: inherit;
    font-weight: inherit !important;
    color: var(--color-math) !important;
    text-decoration: none;
}

#modalBg {
    display: none;
    position: fixed;
    inset: 0;
    backdrop-filter: brightness(60%) blur(3px);
}

.modal {
    background-color: var(--color-bg);
    backdrop-filter: blur(5px);
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    position: fixed;
    /* min-width: max(40vw, 300px); */
    border-radius: 20px;
    left: 50vw;
    top: 10vw;
    transform: translate(-50%, 0);
    padding: 10px;
    padding-bottom: 0;
    max-height: calc(100vh - 20vw);
    overflow-y: hidden;
}

.modal input {
    background: transparent;
    outline: none;
    border: none;
    display: block;
    box-sizing: border-box;
    width: 100%;
    font-size: var(--font-size);
    font-weight: inherit;
    color: var(--color-text);
    padding: 5px 10px;
    margin: 0;
    margin-bottom: calc(var(--font-size) / 2);
    border-bottom: 1px solid #ffffff33;
}

.nodisplay {
    display: none;
}

.modal .list {
    border-radius: 10px;
    padding: 5px;
    overflow-y: auto;
    flex: 1;
}

.modal .list div {
    font-size: var(--font-size);
    padding: 5px 10px;
    border-radius: 10px;
    border: 1px solid transparent;
    transition: border 0.1s, background-color 0.1s;
}

.modal .list div.active {
    border: 1px solid var(--color-accent);
    background-color: #fff1;
    box-shadow: var(--shadow-lg);
}

#curMode,
#curCommand {
    position: fixed;
    bottom: 0;
}

#curMode {
    left: 0;
}

#curCommand {
    right: 0;
}

.lineWrapper {
    display: inline;
}

#alerts {
    position: fixed;
    top: 10px;
    right: 10px;
    max-width: 90vw;
    width: 300px;
}

.alert {
    width: 100%;
    border: 1px solid var(--color-accent);
    border-radius: 20px;
    padding: 20px;
    box-sizing: border-box;
    font-size: calc(0.9 * var(--font-size));
    background-color: #0002;
    backdrop-filter: blur(3px);
    box-shadow: var(--shadow);
    text-shadow: 2px 4px 3px rgba(0, 0, 0, 0.3);
    margin-bottom: 10px;
}

.alert .title {
    font-weight: 500;
    font-size: var(--font-size);
    margin-bottom: 5px;
}

.prompt {
    background-color: var(--color-bg);
    backdrop-filter: blur(5px);
    box-shadow: var(--shadow-lg);
    position: fixed;
    min-width: max(40vw, 300px);
    width: 400px;
    max-width: 96vw;
    box-sizing: border-box;
    border-radius: 20px;
    left: 50vw;
    top: 10vw;
    transform: translate(-50%, 0);
    padding: 20px;
    font-size: var(--font-size);
    color: white;
}

.prompt .title {
    text-align: center;
    font-size: calc(1.4 * var(--font-size));
    font-weight: 500;
}

.prompt .description {
    margin: 5px 0;
}

.prompt .grid {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.5rem 0.75rem;
    margin-top: 1rem;
}

.prompt label {
    grid-column: 1;
    align-content: center;
}

.prompt input {
    grid-column: 2;
    background: transparent;
    outline: none;
    font-size: var(--font-size);
    padding: 5px 10px;
    border: 1px solid #ffffff33;
    border-radius: 5px;
    min-width: 0;
}

.prompt .submit {
    text-align: center;
    font-size: calc(1.2 * var(--font-size));
    background-color: #fff1;
    padding: 5px;
    box-sizing: border-box;
    border-radius: 5px;
    width: 100px;
    margin: 20px auto 0 auto;
    border: 1px solid var(--color-accent);
}

#attachments img {
    display: block;
    width: 100%;
}

#attachments {
    overflow-y: scroll;
    height: calc(100vh - 20vw);
    width: min(90vw, 600px);
    max-width: 90vw;
    padding: min(10%, 50px);
    box-sizing: border-box;
    flex-direction: column;
    gap: 20px;
}
