/* ── Placeholder ─────────────────────────────────────────────────────── */
.ProseMirror .is-editor-empty::before {
  content: attr(data-placeholder);
  float: left;
  color: var(--text-muted);
  pointer-events: none;
  height: 0;
}

.ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  color: var(--text-muted);
  pointer-events: none;
  height: 0;
  font-style: italic;
}

/* ── Headings ────────────────────────────────────────────────────────── */
.ProseMirror h1,
.ProseMirror h2,
.ProseMirror h3,
.ProseMirror h4,
.ProseMirror h5,
.ProseMirror h6 {
  font-family: var(--ed-heading-font);
  color: var(--ed-text);
}

.ProseMirror h1,
.ProseMirror h2 {
  text-wrap: var(--ed-heading-balance-wrap);
}

.ProseMirror h3,
.ProseMirror h4,
.ProseMirror h5,
.ProseMirror h6 {
  text-wrap: pretty;
}

.ProseMirror h1 {
  font-size: var(--ed-h1-size);
  font-weight: var(--ed-h1-weight);
  line-height: var(--ed-h1-line-height);
  letter-spacing: var(--ed-h1-letter-spacing);
  margin-top: var(--ed-h1-margin-top);
  margin-bottom: var(--ed-h1-margin-bottom);
}
.ProseMirror h1.is-editor-empty::before {
  font-style: normal;
  color: color-mix(in srgb, var(--text-muted) 88%, transparent);
}

.ProseMirror > :first-child:is(h1, h2, h3, h4, h5, h6) {
  margin-top: 0;
}

.ProseMirror > :is(h1, h2, h3, h4, h5, h6) + :is(h1, h2, h3, h4, h5, h6) {
  margin-top: 0.52em;
}
.ProseMirror h2 {
  font-size: var(--ed-h2-size);
  font-weight: var(--ed-h2-weight);
  line-height: var(--ed-h2-line-height);
  letter-spacing: var(--ed-h2-letter-spacing);
  margin-top: var(--ed-h2-margin-top);
  margin-bottom: var(--ed-h2-margin-bottom);
}
.ProseMirror h3 {
  font-size: var(--ed-h3-size);
  font-weight: var(--ed-h3-weight);
  line-height: var(--ed-h3-line-height);
  letter-spacing: var(--ed-h3-letter-spacing);
  margin-top: var(--ed-h3-margin-top);
  margin-bottom: var(--ed-h3-margin-bottom);
}
.ProseMirror h4 {
  font-size: var(--ed-h4-size);
  font-weight: var(--ed-h4-weight);
  line-height: var(--ed-h4-line-height);
  letter-spacing: var(--ed-h4-letter-spacing);
  margin-top: var(--ed-h4-margin-top);
  margin-bottom: var(--ed-h4-margin-bottom);
}
.ProseMirror h5 {
  font-size: var(--ed-h5-size);
  font-weight: var(--ed-h5-weight);
  line-height: var(--ed-h5-line-height);
  letter-spacing: var(--ed-h5-letter-spacing);
  margin-top: var(--ed-h5-margin-top);
  margin-bottom: var(--ed-h5-margin-bottom);
}
.ProseMirror h6 {
  font-size: var(--ed-h6-size);
  font-weight: var(--ed-h6-weight);
  line-height: var(--ed-h6-line-height);
  letter-spacing: var(--ed-h6-letter-spacing);
  margin-top: var(--ed-h6-margin-top);
  margin-bottom: var(--ed-h6-margin-bottom);
  color: var(--ed-h6-color);
}


/* ── Paragraphs ──────────────────────────────────────────────────────── */
.ProseMirror p {
  margin-bottom: var(--ed-paragraph-gap);
  text-wrap: pretty;
}
.ProseMirror p:last-child { margin-bottom: 0; }

.ProseMirror > :where(p, ul, ol, blockquote, pre, hr) {
  margin-top: 0;
  margin-bottom: var(--ed-block-gap);
}

.ProseMirror > :where(h1, h2, h3, h4, h5, h6) + :where(p, ul, ol) {
  margin-top: 0;
}

.ProseMirror :is(p[data-style-variant="caption"], .prose-image-caption, .table-data-block__caption, .table-data-block__footer) {
  width: min(100%, var(--ed-caption-max-width));
  margin-left: auto;
  margin-right: auto;
  font-size: var(--ed-caption-size);
  line-height: var(--ed-caption-line-height);
  letter-spacing: var(--ed-caption-letter-spacing);
  color: var(--ed-caption-color);
  font-style: normal;
}

.ProseMirror p[data-style-variant="caption"] {
  margin-top: var(--ed-caption-margin-top);
  margin-bottom: var(--ed-caption-margin-bottom);
  text-align: var(--ed-caption-align);
}

.ProseMirror > :is(.prose-image, p[data-style-variant="caption"]) + p[data-style-variant="caption"] {
  margin-top: calc(var(--ed-caption-margin-top) * 0.5);
}

.ProseMirror p[data-style-variant="caption"] + :where(p, ul, ol) {
  margin-top: 0.14rem;
}

.ProseMirror p[data-style-variant="note"] {
  margin-top: var(--ed-note-margin-top);
  margin-bottom: var(--ed-note-margin-bottom);
  padding: var(--ed-note-pad-y) var(--ed-note-pad-x);
  font-size: var(--ed-note-size);
  line-height: var(--ed-note-line-height);
  letter-spacing: var(--ed-note-letter-spacing);
  color: var(--ed-note-color);
  background: var(--ed-note-bg);
  border: 0;
  border-radius: var(--ed-note-radius);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ed-note-border) 26%, transparent);
  text-wrap: pretty;
}

.ProseMirror p[data-style-variant="note"] + p[data-style-variant="note"] {
  margin-top: calc(var(--ed-note-margin-top) * 0.5);
}

.ProseMirror p[data-style-variant="note"] + :where(p, ul, ol) {
  margin-top: 0.24rem;
}

/* ── Lists ───────────────────────────────────────────────────────────── */
.ProseMirror ul,
.ProseMirror ol {
  padding-left: 1.6em;
  margin-bottom: var(--ed-block-gap);
}

.ProseMirror li { margin-bottom: 0.3em; }
.ProseMirror li p { margin-bottom: 0.2em; }

/* ── Blockquote ──────────────────────────────────────────────────────── */
.ProseMirror blockquote {
  margin-top: var(--ed-quote-margin-top);
  margin-bottom: var(--ed-quote-margin-bottom);
  padding: var(--ed-quote-pad-y) var(--ed-quote-pad-right) var(--ed-quote-pad-y) var(--ed-quote-pad-left);
  font-size: var(--ed-quote-size);
  line-height: var(--ed-quote-line-height);
  letter-spacing: var(--ed-quote-letter-spacing);
  color: var(--ed-quote-color);
  background: var(--ed-quote-bg);
  border-left: var(--ed-quote-border-width) solid var(--ed-quote-accent);
  border-radius: 0 var(--ed-quote-radius) var(--ed-quote-radius) 0;
  font-style: normal;
  text-wrap: pretty;
}

.ProseMirror blockquote > :first-child {
  margin-top: 0;
}

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

.ProseMirror blockquote p {
  margin-bottom: 0.72em;
}

.ProseMirror blockquote + blockquote {
  margin-top: calc(var(--ed-quote-margin-top) * 0.5);
}

.ProseMirror blockquote + :where(p, ul, ol) {
  margin-top: 0.28rem;
}

/* ── Code ────────────────────────────────────────────────────────────── */
.ProseMirror code {
  font-family: var(--font-mono);
  font-size: var(--ed-code-inline-size);
  line-height: var(--ed-code-inline-line-height);
  background: var(--ed-code-inline-bg);
  border: 1px solid var(--ed-code-inline-border);
  border-radius: var(--ed-code-inline-radius);
  padding: var(--ed-code-inline-pad-y) var(--ed-code-inline-pad-x);
}

.ProseMirror pre {
  margin-top: var(--ed-code-block-margin-top);
  margin-bottom: var(--ed-code-block-margin-bottom);
  font-family: var(--font-mono);
  font-size: var(--ed-code-block-size);
  line-height: var(--ed-code-block-line-height);
  color: var(--ed-code-block-color);
  background: var(--ed-code-block-bg);
  border: 1px solid var(--ed-code-block-border);
  border-radius: var(--ed-code-block-radius);
  padding: var(--ed-code-block-pad-y) var(--ed-code-block-pad-x);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  tab-size: var(--ed-code-block-tab-size);
}

.ProseMirror pre + pre {
  margin-top: calc(var(--ed-code-block-margin-top) * 0.6);
}

.ProseMirror pre + :where(p, ul, ol) {
  margin-top: 0.32rem;
}

.ProseMirror pre code {
  display: block;
  background: none;
  border: none;
  border-radius: 0;
  padding: 0;
  font-size: inherit;
  line-height: inherit;
  color: inherit;
  white-space: pre;
}

/* ── Horizontal rule ─────────────────────────────────────────────────── */

/* ── Styled block integration ───────────────────────────────────────── */
.ProseMirror > :is(p[data-style-variant="note"], blockquote, pre) + :is(p[data-style-variant="note"], blockquote, pre) {
  margin-top: 0.52rem;
}

.ProseMirror > p[data-style-variant="caption"] + :is(p[data-style-variant="note"], blockquote, pre) {
  margin-top: 0.38rem;
}

.ProseMirror > :is(p[data-style-variant="note"], blockquote, pre) + p[data-style-variant="caption"] {
  margin-top: 0.42rem;
}

.ProseMirror > :is(h1, h2, h3, h4, h5, h6) + :is(p[data-style-variant="note"], blockquote, pre) {
  margin-top: 0.24rem;
}

.ProseMirror > :is(h1, h2, h3, h4, h5, h6) + p[data-style-variant="caption"] {
  margin-top: 0.08rem;
}

.ProseMirror hr {
  border: none;
  border-top: 1px solid color-mix(in srgb, var(--border-strong) 88%, transparent);
  margin: calc(var(--ed-block-gap) * 1.35) 0;
}

/* ── Links ───────────────────────────────────────────────────────────── */
.ProseMirror a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 4px;
  border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ProseMirror a:hover,
.ProseMirror a:focus-visible,
.ProseMirror a.is-context-target {
  background: color-mix(in srgb, rgba(var(--accent-rgb), .12) 78%, transparent);
  text-decoration-thickness: 2px;
  outline: none;
}

/* ── Strong / em ─────────────────────────────────────────────────────── */
.ProseMirror strong { font-weight: 700; }
.ProseMirror em { font-style: italic; }
.ProseMirror s { text-decoration: line-through; color: var(--text-sec); }
.ProseMirror u { text-decoration: underline; text-underline-offset: 4px; }

/* ── Highlight ───────────────────────────────────────────────────────── */
.ProseMirror mark {
  /* Fallback for marks without an explicit colour */
  background: var(--mark-yellow);
  color: var(--mark-yellow-text-light);
  border-radius: 2px;
  padding: 0.05em 0.1em;
  /* TipTap writes style="background-color:…" which overrides the background above */
}

/* In dark mode the highlight backgrounds are dark, so text must be light */
[data-theme="dark"] .ProseMirror mark {
  color: var(--mark-yellow-text-dark);
}
/* ── Images ──────────────────────────────────────────────────────────── */
.ProseMirror .prose-image {
  display: block;
  max-width: 100%;
  height: auto !important;  /* override any height HTML attribute from the doc */
  border-radius: var(--r-md);
  margin: 1.2em auto;
  cursor: pointer;
}

.ProseMirror .prose-image[data-show-caption="true"] {
  display: inline-flex;
  flex-direction: column;
  gap: var(--ed-caption-image-gap);
}

.ProseMirror .prose-image-media {
  display: block;
  width: 100%;
  height: auto !important;
  border-radius: var(--r-md);
}

.ProseMirror .prose-image-caption {
  display: block;
  text-align: var(--ed-caption-image-align);
}

/* Float non-full left/right images so text wraps alongside them. */
.ProseMirror .prose-image.align-left[style*="max-width"] {
  float: left;
  margin: 0.4em 1.4em 0.8em 0;
  display: inline-block;
}
.ProseMirror .prose-image.align-right[style*="max-width"] {
  float: right;
  margin: 0.4em 0 0.8em 1.4em;
  display: inline-block;
}
/* Center is always block */
.ProseMirror .prose-image.align-center {
  float: none;
  margin: 1.2em auto;
  display: block;
}
/* Full-width left/right: no float */
.ProseMirror .prose-image.align-left:not([style*="max-width"])  { float: none; margin-right: auto; margin-left: 0; }
.ProseMirror .prose-image.align-right:not([style*="max-width"]) { float: none; margin-left: auto; margin-right: 0; }
/* Clearfix */
.ProseMirror::after { content: ''; display: table; clear: both; }
/* Selected image ring */
.ProseMirror .ProseMirror-selectednode .prose-image,
.ProseMirror .prose-image.ProseMirror-selectednode {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.citation-ref.is-context-target::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(var(--accent-rgb), 0.12);
  pointer-events: none;
}

.ProseMirror .prose-image.is-context-target,
.ProseMirror img.is-context-target {
  outline: 2px solid color-mix(in srgb, var(--accent) 72%, transparent);
  outline-offset: 3px;
}

.ProseMirror td, .ProseMirror th { position: relative; }

.ProseMirror .column-resize-handle {
  position: absolute;
  right: -3px;
  top: 0;
  bottom: 0;
  width: 6px;
  background-color: color-mix(in srgb, var(--accent) 72%, transparent);
  cursor: col-resize;
  z-index: 10;
}

@media (pointer: coarse) {
  .ProseMirror th,
  .ProseMirror td {
    padding: 0.68em 0.82em;
  }

  .ProseMirror .column-resize-handle {
    right: -8px;
    width: 16px;
    background-color: color-mix(in srgb, var(--accent) 40%, transparent);
  }

  .citation-ref,
  .ProseMirror a {
    min-height: 1.8em;
  }
}

/* ── Citation nodes ──────────────────────────────────────────────────── */
.citation-ref {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.45em;
  padding: 0 .22em;
  margin-inline: .04em;
  color: var(--accent);
  font-size: 0.75em;
  vertical-align: super;
  line-height: 1;
  cursor: pointer;
  font-family: var(--font-ui);
  border-radius: 999px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.citation-ref:hover,
.citation-ref:focus-visible,
.citation-ref.is-context-target {
  background: color-mix(in srgb, rgba(var(--accent-rgb), .14) 82%, transparent);
  text-decoration: underline;
  outline: none;
}
.ProseMirror h1 + p,
.ProseMirror h1 + h2,
.ProseMirror h2 + h3,
.ProseMirror h3 + h4 {
  margin-top: 0;
}

.ProseMirror ::selection {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.ProseMirror p {
  font-weight: 400;
}

