:root {
    --bg: white;
    --fg: hsl(35, 0%, 12%);
    --link: hsl(215, 100%, 45%);
    --input-border: hsla(0, 0%, 0%, 20%);
    --code-border: hsla(0, 0%, 0%, 15%);
    --code-bg: hsla(0, 0%, 0%, 4%);
    --button-bg: hsl(195, 100%, 50%);
    --button-border: 1px solid hsl(210, 100%, 50%);
    --success-color: hsl(130, 100%, 35%);
    --focused-bg: hsl(250, 100%, 85%);
    --focused-fg: hsl(260, 100%, 75%);
    --error-color: hsl(0, 100%, 45%);
    --disabled-fg: hsl(0, 0%, 55%);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: hsl(215, 15%, 8%);
        --fg: hsl(0, 0%, 95%);
        --link: hsl(215, 100%, 65%);
        --input-border: hsla(0, 0%, 90%, 40%);
        --code-border: hsla(0, 0%, 100%, 25%);
        --code-bg: hsla(0, 0%, 100%, 6%);
        --button-bg: hsl(210, 100%, 50%);
        --button-border: hsl(210, 100%, 75%);
        --success-color: hsl(130, 75%, 60%);
        --focused-bg: hsl(250, 35%, 45%);
        --focused-fg: hsl(260, 55%, 60%);
        --error-color: hsl(0, 100%, 70%);
        --disabled-fg: hsl(0, 0%, 45%);
    }

    * {
        /* Scrollbars and other native UI */
        color-scheme: dark;
    }
}

html {
    /* Prevent font scaling in landscape while allowing user zoom */
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: system-ui, sans-serif;
    line-height: 140%;
    background-color: var(--bg);
    color: var(--fg);
    display: flex;
    justify-content: center;
}

.article-container {
    max-width: 40em;
    padding: 1em;
    box-sizing: border-box;
}

p {
    line-height: 150%;
}

img {
    max-width: 100%;
}

.article-container pre {
    border: 1px solid var(--code-border);
    padding: 0.8em 1.1em;
    border-radius: 0.6em;
    background-color: var(--code-bg);
}

.article-container code {
    border: 1px solid var(--code-border);
    padding: 0.1em 0.3em;
    border-radius: 0.35em;
    background-color: var(--code-bg);
}

.article-container pre>code {
    border: none;
    padding: initial;
    background: none;
}

.article-container h1,
.article-container h2,
.article-container h3,
.article-container h4,
.article-container h5,
.article-container h6 {
    line-height: 130%;
}

.container {
    width: calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right));
    height: calc(100vh - env(safe-area-inset-bottom) - env(safe-area-inset-top));

    /* Don't overflow the window with over-sized texts. Subtract paddings */
    margin-left: env(safe-area-inset-left);
    margin-right: env(safe-area-inset-right);
    margin-bottom: calc(env(safe-area-inset-bottom));

    display: flex;
    flex-direction: row-reverse;
}

.container>div {
    flex: 1;
}

#editor-container,
#output-container {
    padding: 1em;
    display: flex;
    flex-direction: column;
}

#output-container {
    height: calc(100vh - env(safe-area-inset-bottom));
    box-sizing: border-box;
}

#editor-container h2,
#output-container h2 {
    margin-top: 0;
}

#editor {
    border: 1px solid var(--fg);
    padding: 10px;
    font-family: monospace;
    font-size: 1.3em;
    line-height: 170%;

    /* height: fill parent */
    flex: 1;

    /* but do not exceed */
    overflow: auto;

    /* hide focus ring because this is the only text input on the page */
    outline: none;

    /* https://stackoverflow.com/questions/69296163/contenteditable-removes-trailing-whitespaces-on-firefox-but-not-on-chrome */
    /* https://github.com/ueberdosis/tiptap/issues/2120 */
    /* https://developer.mozilla.org/en-US/docs/Web/CSS/white-space */
    white-space: pre-wrap;
}

#output {
    flex: 1;
    border: 1px solid var(--fg);
    width: 100%;
    overflow: hidden;
    cursor: pointer;
}

/* for narrow screens */
@media (max-width: 700px) {
    .container {
        display: block;
    }

    #output {
        width: calc(100% + 2em);
        margin-left: -1em;
    }

    #editor,
    #output {
        border: none;
    }
}

#output.fullscreen {
    border: none;
    cursor: none;
}

#presentation {
    display: flex;
    align-self: center;
    justify-content: center;
    font-size: 3vw;
}

.editor-header {
    display: flex;
    place-items: baseline;
}

.spacer {
    margin: 0 0.3em;
}

input {
    /* Prevent iOS zoom on focus */
    font-size: 16px;
}

a,
a:visited {
    text-decoration: none;
    color: var(--link);
}

a:hover {
    text-decoration: underline;
}

input[type=text],
input[type=number],
textarea {
    font-family: -apple-system, sans-serif;
    line-height: 120%;
    background-color: var(--bg);
    color: var(--fg);
    border: 1px solid var(--input-border);
    padding: 0.2em 0.5em;
    border-radius: 1em;
}

/* Wrap <textarea> in a div to get border-radius without glitching scrollbars */
/* <div class="textarea-border-radius"><textarea></textarea></div> */
.textarea-border-radius {
    border-radius: 1em;
    overflow: hidden;
    display: flex;
    border: 1px solid var(--input-border);
}

.textarea-border-radius>textarea {
    margin: -1px !important;
    border: none;
    flex: 1;
}

input[type=number] {
    width: 5em;
}

input[type=text]:focus,
input[type=number]:focus,
textarea:focus {
    outline: none;
}

textarea {
    resize: none;
    height: auto;
    padding: 0.3em 0.7em;
    font-size: 1em;
}

.disabled {
    color: var(--disabled-fg);
}

.focused {
    box-shadow: inset 0 0 0 2px var(--focused-fg);
}

.error {
    color: var(--error-color);
}

.hidden {
    display: none !important;
}
:root {
    --code-command: hsl(155, 100%, 29%);
    --code-control-flow: hsl(240, 80%, 65%);
    --code-numeric: hsl(340, 70%, 60%);
    --code-comment: hsl(0, 0%, 60%);
}

@media (prefers-color-scheme: dark) {
    :root {
        --code-command: hsl(155, 90%, 45%);
        --code-control-flow: hsl(240, 100%, 75%);
        --code-numeric: hsl(340, 90%, 70%);
        --code-comment: hsl(0, 0%, 55%);
    }
}

.command {
    color: var(--code-command);
}

.control-flow {
    color: var(--code-control-flow);
}

.numeric {
    color: var(--code-numeric);
}

.comment {
    color: var(--code-comment);
}
