/* colors: the preview and the swatches both read these */

[data-palette='classic'] {
    --c-red: #f44;
    --c-blue: #1e90ff;
    --c-white: #fff;
    --c-yellow: #ff0;
    --c-pink: #ffcbdb;
    --c-gray: #d3d3d3;
    --c-green: #4f4;
    --c-orange: #ffa500;
    --c-purple: #e2afff;
    --c-black: #000;
    --c-brown: #aa840c;
    --c-cyan: #0ff;
}

[data-palette='vanilla'] {
    --c-red: #f00;
    --c-blue: #06f;
    --c-white: #fff;
    --c-yellow: #ff0;
    --c-pink: #f9c;
    --c-gray: #ccc;
    --c-green: #0f0;
    --c-orange: #f60;
    --c-purple: #93f;
    --c-black: #000;
    --c-brown: #8a6d3b;
    --c-cyan: #0ff;
}

/* base */

.preview {
    --text: #dcdcdc;
    --bg: #22222b;
    --link: #8cb4e0;
    --muted: #9a9aaa;
    --panel: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.2);
    --icon-link: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.72'/%3E%3Cpath d='M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.72-1.72'/%3E%3C/svg%3E");
    --icon-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");

    background: var(--bg);
    color: var(--text);
    font-family:
        system-ui,
        -apple-system,
        'Segoe UI',
        Roboto,
        'Helvetica Neue',
        Arial,
        'Noto Sans',
        sans-serif,
        'Apple Color Emoji',
        'Segoe UI Emoji';
    font-size: 1rem;
    hyphens: auto;
    line-height: 1.5;
    overflow: auto;
    overflow-wrap: break-word;
    padding: 1rem;

    /* keeps line breaks, collapses runs of spaces */
    white-space: pre-line;
}

.preview,
.preview *,
.preview ::before,
.preview ::after {
    box-sizing: border-box;
}

/* themes: the base .preview above is the default theme. Dark and light follow
   Horizon's themes; the editor side (backdrop, swatches) never gets a theme */

.preview[data-theme='dark'] {
    --text: #ccc;
    --bg: #000;
    --link: #fff;
    --muted: #666;
}

.preview[data-theme='light'] {
    --text: #191919;
    --bg: #e5e5e5;
    --link: #007bff;
    --muted: #7f7f7f;
    --panel: rgba(0, 0, 0, 0.06);
    --border: rgba(0, 0, 0, 0.15);

    color-scheme: light;
}

/* on light, Classic's pastels wash out, so it takes Horizon's own colors (white
   and gray become the same shade); vanilla keeps its fixed colors everywhere */
[data-theme='light'][data-palette='classic'] {
    --c-red: #f00;
    --c-orange: #f60;
    --c-purple: #93f;
    --c-blue: #00f;
    --c-white: #999;
    --c-yellow: #bcab17;
    --c-pink: #da1677;
    --c-gray: #999;
    --c-green: #036603;
    --c-black: #191919;
    --c-cyan: #209898;
}

.preview a {
    color: var(--link);
    text-decoration: underline;
}

.preview a:hover {
    text-decoration: none;
}

.link-domain {
    color: var(--muted);
}

.link-icon {
    background: var(--link);
    display: inline-block;
    height: 1em;
    margin-right: 2px;
    mask: var(--icon-link) center / contain no-repeat;
    vertical-align: -0.125em;
    width: 1.25em;
    -webkit-mask: var(--icon-link) center / contain no-repeat;
}

/* text */

/* black disappears on the dark backgrounds, so it gets a soft glow */
.preview:not([data-theme='light']) [data-color='black'] {
    text-shadow:
        #777 0 1px 2px,
        #9e9e9e 0 0 2px;
}

/* vanilla white and purple disappear on light and default; Horizon outlines them */
.preview[data-theme='light'][data-palette='vanilla'] [data-color='white'] {
    text-shadow:
        #666 1px 0,
        #666 -1px 0,
        #666 0 1px,
        #666 0 -1px,
        #666 1px 1px,
        #666 -1px 1px,
        #666 1px -1px,
        #666 -1px -1px;
}

.preview[data-theme='default'][data-palette='vanilla'] [data-color='purple'] {
    text-shadow:
        #306 1px 0,
        #306 -1px 0,
        #306 0 1px,
        #306 0 -1px,
        #306 1px 1px,
        #306 -1px 1px,
        #306 1px -1px,
        #306 -1px -1px;
}

.preview .big {
    font-size: 1.4em;
}

.preview .small {
    font-size: 0.8em;
}

.preview sub,
.preview sup {
    font-size: 0.75em;
    line-height: 1.5;
    position: static;
}

.preview sub {
    vertical-align: baseline;
}

.preview sup {
    vertical-align: top;
}

.preview .heading {
    font-size: 1.17rem;
    font-weight: 700;
    line-height: 1.2;
    margin: 0 0 0.5rem;
}

.preview hr {
    border: 0;
    border-top: 1px solid currentcolor;
    margin: 5px 0;
    opacity: 0.25;
}

.preview .align-left {
    text-align: left;
}

.preview .align-center {
    text-align: center;
}

.preview .align-right {
    text-align: right;
}

.preview .align-justify {
    text-align: justify;
}

/* the indent grows with the window width, in steps */
.preview .indent {
    padding-left: 0;
}

@media (min-width: 768px) {
    .preview .indent {
        padding-left: 1%;
    }
}

@media (min-width: 992px) {
    .preview .indent {
        padding-left: 2%;
    }
}

@media (min-width: 1200px) {
    .preview .indent {
        padding-left: 5%;
    }
}

.preview blockquote {
    background: var(--panel);
    border-radius: 3px;
    margin: 0;
    padding: 1em;
}

.preview .quote-header {
    border-bottom: 1px solid;
    font-size: 80%;
    font-weight: 700;
    opacity: 0.7;
    text-transform: uppercase;
}

/* collapse, sized like a Bootstrap card */

.preview .collapse {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 0.7em;
    display: flex;
    flex-direction: column;
}

.preview .collapse-header {
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    border-radius: calc(0.7em - 1px) calc(0.7em - 1px) 0 0;
    cursor: pointer;
    font-weight: 700;
    padding: 0.4em 1.25rem;
    user-select: none;
    width: 100%;
}

.preview .collapse:not(.open) > .collapse-header {
    border-radius: calc(0.7em - 1px);
}

.preview .collapse-chevron {
    background: currentcolor;
    display: inline-block;
    height: 1em;
    margin-right: 10px;
    mask: var(--icon-chevron) center / contain no-repeat;
    vertical-align: -0.125em;
    width: 1em;
    -webkit-mask: var(--icon-chevron) center / contain no-repeat;
}

/* the chevron points down when closed and up when open */
.preview .collapse.open > .collapse-header .collapse-chevron {
    transform: scaleY(-1);
}

.preview .collapse-body {
    display: grid;
    grid-template-rows: 0fr;
    margin-left: 0.5rem;
    transition: grid-template-rows 0.2s;
}

.preview .collapse.open > .collapse-body {
    grid-template-rows: 1fr;
}

.preview .collapse-body-inner {
    min-height: 0;
    overflow: hidden;
}

.preview .collapse-content {
    padding: 1rem;
}

@media (prefers-reduced-motion: reduce) {
    .preview .collapse-chevron,
    .preview .collapse-body {
        transition: none;
    }
}

/* images */

.preview .avatar {
    height: 50px;
    vertical-align: middle;
    width: 50px;
}

.preview .avatar.icon {
    object-fit: contain;
}

.preview .avatar.broken {
    background: var(--panel);
    border: 1px dashed var(--border);
    font-size: 0.65rem;
    line-height: 1.1;
    overflow: hidden;
}

.preview .inline-image img {
    height: auto;
    max-width: 100%;
}

.preview .inline-missing {
    border: 1px dashed var(--border);
    color: var(--muted);
    font-style: italic;
    padding: 0.5em 0.75em;
}

.preview .spoiler-content[hidden] {
    display: none;
}
