/*
 * WYSIWYG: the typography of the rich text editor, from the style reference.
 * The editor's HTML carries no classes, so its elements are styled by tag
 * inside the block (`.wysiwyg h2`); `.lead` is the one class the editor emits.
 * Sizes are desktop values; the mobile step (below 768px) is at the end.
 */

/*
 * Spacing is carried by margin-bottom: every element owns the space below it,
 * and the last one in a block owns none. A heading that needs more room above
 * it gets it from the element before it (`:has(+ h2)`), never from a top margin.
 */

.wysiwyg {
    margin-bottom: 22px;
}

/* The browser's own margins go; the rules below set every one that is wanted. */
.wysiwyg :where(p, ul, ol, blockquote, pre, table, hr, img, h2, h3, h4, h5, h6) {
    margin: 0;
}

.wysiwyg > * {
    margin-bottom: 22px;
}

.wysiwyg > :has(+ :is(h2)) { margin-bottom: 52px; }
.wysiwyg > :has(+ :is(h3)) { margin-bottom: 40px; }
.wysiwyg > :has(+ :is(h4)) { margin-bottom: 32px; }
.wysiwyg > :has(+ :is(h5, h6)) { margin-bottom: 28px; }
.wysiwyg > :has(+ hr) { margin-bottom: 36px; }
.wysiwyg > :has(+ pre),
.wysiwyg > :has(+ img) { margin-bottom: 28px; }

/* Whatever follows a heading sits close to it. */
.wysiwyg > :is(h2, h3, h4, h5, h6) {
    margin-bottom: 14px;
}

.wysiwyg > hr {
    margin-bottom: 36px;
}

.wysiwyg > :last-child {
    margin-bottom: 0;
}

.wysiwyg h2,
.wysiwyg h3,
.wysiwyg h4,
.wysiwyg h5,
.wysiwyg h6 {
    color: var(--ink);
    font-weight: 600;
    scroll-margin-top: 90px;
    text-wrap: balance;
}

.wysiwyg h2 {
    font-size: 28px;
    line-height: 1.2;
    letter-spacing: -0.03em;
}

.wysiwyg h3 {
    font-size: 22px;
    line-height: 1.3;
    letter-spacing: -0.02em;
}

.wysiwyg h4 {
    font-size: 19px;
    line-height: 1.35;
    letter-spacing: -0.015em;
}

.wysiwyg h5 {
    font-size: 16px;
    line-height: 1.4;
}

.wysiwyg h6 {
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-faint);
}

.wysiwyg p {
    text-wrap: pretty;
}

.wysiwyg .lead {
    font-size: 20px;
    line-height: 1.55;
    color: var(--ink-soft);
}

.wysiwyg small {
    font-size: 15px;
    line-height: 1.6;
    color: var(--ink-faint);
}

/* Inline */

.wysiwyg strong,
.wysiwyg b {
    font-weight: 600;
    color: var(--ink);
}

.wysiwyg s,
.wysiwyg del {
    color: var(--ink-faint);
}

.wysiwyg sub,
.wysiwyg sup {
    font-size: 12px;
}

.wysiwyg mark {
    padding: 0 3px;
    border-radius: 3px;
    background: linear-gradient(120deg, rgba(242, 160, 184, 0.35), rgba(123, 108, 246, 0.25));
    color: var(--ink);
}

.wysiwyg :not(pre) > code {
    font-family: var(--font-mono);
    font-size: 15px;
    padding: 2px 7px;
    border-radius: 6px;
    background: var(--accent-tint);
    color: var(--accent-deep);
}

.wysiwyg a {
    color: var(--accent-ink);
    text-decoration: underline;
    text-decoration-color: rgba(91, 82, 224, 0.35);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    transition: text-decoration-color 0.15s, color 0.15s;
}

.wysiwyg a:hover {
    color: var(--accent-deep);
    text-decoration-color: currentColor;
}

/* Lists */

.wysiwyg ul,
.wysiwyg ol {
    padding-left: 22px;
}

.wysiwyg ol {
    padding-left: 24px;
}

.wysiwyg li {
    padding-left: 4px;
}

.wysiwyg li:not(:last-child) {
    margin-bottom: 8px;
}

.wysiwyg li > p:not(:last-child) {
    margin-bottom: 8px;
}

.wysiwyg li ul,
.wysiwyg li ol {
    margin-top: 8px;
    color: var(--ink-soft);
}

.wysiwyg li li:not(:last-child) {
    margin-bottom: 6px;
}

.wysiwyg ul > li::marker {
    color: var(--accent);
}

.wysiwyg ol > li::marker {
    font-size: 0.85em;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

/* Quote */

.wysiwyg blockquote {
    padding: 2px 0 2px 22px;
    border-left: 2px solid #c9c2fb;
    color: #4c4956;
}

.wysiwyg blockquote > :not(:last-child) {
    margin-bottom: 8px;
}

.wysiwyg blockquote cite,
.wysiwyg blockquote footer {
    display: block;
    font-size: 14px;
    font-style: normal;
    color: var(--ink-faint);
}

/* Code block */

.wysiwyg pre {
    padding: 18px 20px;
    overflow-x: auto;
    border-radius: 16px;
    background: var(--ink);
    color: #e9e7e2;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.75;
    tab-size: 2;
}

.wysiwyg pre code {
    padding: 0;
    background: none;
    color: inherit;
    font: inherit;
}

/* Table: scrolls inside its own box, never the page */

.wysiwyg table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    font-size: 15px;
    line-height: 1.4;
}

.wysiwyg tbody {
    display: table;
    width: 100%;
    border-spacing: 0;
}

.wysiwyg th,
.wysiwyg td {
    padding: 13px 20px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid rgba(22, 21, 28, 0.06);
}

.wysiwyg th {
    padding-top: 12px;
    padding-bottom: 12px;
    border-bottom-color: rgba(22, 21, 28, 0.07);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-faint);
    white-space: nowrap;
}

.wysiwyg tr:last-child > td {
    border-bottom: 0;
}

/* Divider, disclosure, media */

.wysiwyg hr {
    height: 1px;
    border: 0;
    background: rgba(22, 21, 28, 0.1);
}

.wysiwyg details {
    padding: 14px 18px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    font-size: 16px;
    line-height: 1.6;
}

.wysiwyg summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--ink);
}

.wysiwyg details[open] > summary {
    margin-bottom: 10px;
}

.wysiwyg img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 18px;
}

@media (max-width: 767px) {
    .wysiwyg h2 { font-size: 24px; line-height: 1.22; }
    .wysiwyg h3 { font-size: 20px; }
    .wysiwyg > :has(+ h2) { margin-bottom: 44px; }
    .wysiwyg > :has(+ h3) { margin-bottom: 34px; }
    .wysiwyg h4 { font-size: 18px; }
    .wysiwyg .lead { font-size: 18px; }
    .wysiwyg small { font-size: 14px; }
    .wysiwyg pre { font-size: 12.5px; }
    .wysiwyg th, .wysiwyg td { padding-left: 14px; padding-right: 14px; }
}
