/* A shared text measure keeps the editable page and the published story aligned. */
#article-form.art-writer {
  --writer-inset: clamp(22px, 4vw, 48px);
  --writer-ink: #30263f;
  display: block;
  min-width: 0;
  padding: 0;
  background: #fff;
  border: 1px solid #e4ddec;
  border-radius: 20px;
  box-shadow: 0 6px 25px #46325b09;
}
.subpage:has(.art-writer) {
  max-width: 960px;
}
#article-form .writer-title {
  display: block;
  margin: 0;
  padding: clamp(24px, 4vw, 40px) var(--writer-inset) clamp(16px, 2.5vw, 24px);
  color: #685b76;
  font-size: 0.85rem;
  font-weight: 600;
}
#article-form .writer-title #article-title {
  display: block;
  width: 100%;
  min-height: 1.65em;
  margin: 3px 0 0;
  padding: 3px 0;
  border: 0;
  border-radius: 2px;
  background: transparent;
  box-shadow: none;
  color: var(--writer-ink);
  font: 680 clamp(1.7rem, 3.1vw, 2.5rem)/1.3 var(--serif);
  letter-spacing: -0.035em;
}
#article-form .writer-title #article-title::placeholder {
  color: #827989;
  opacity: 1;
}
#article-form .writer-title #article-title:focus-visible {
  outline: 0;
  box-shadow: 0 2px #8a69bd;
}
#article-form > :is(.art-feedback, p.muted) {
  margin: 12px var(--writer-inset);
}
#article-form > .art-feedback:empty {
  display: none;
}
#article-body-editor {
  min-width: 0;
  width: 100%;
}
#article-body-editor .re-toolbar {
  position: sticky;
  z-index: 3;
  top: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px 8px;
  width: 100%;
  min-width: 0;
  padding: 7px clamp(13px, 2.6vw, 31px);
  border-block: 1px solid #e6dfed;
  background: #faf8fc;
}
.re-toolbar .re-tools {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 2px;
  min-width: 0;
}
.re-toolbar .re-tools + .re-tools {
  border-inline-start: 1px solid #ddd5e6;
  padding-inline-start: 8px;
}
#article-body-editor .re-tool,
#article-body-editor .re-style {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 32px;
  min-height: 34px;
  margin: 0;
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  box-shadow: none;
  color: #51445e;
  font-family: inherit;
  font-size: 0.83rem;
  font-weight: 550;
  line-height: 1.25;
  white-space: nowrap;
  cursor: pointer;
}
#article-body-editor select.re-style {
  display: block;
  width: auto;
  max-width: 10em;
  min-width: 5.2em;
  padding-inline: 7px;
  border-color: #dcd3e6;
  background-color: white;
}
#article-body-editor .re-tool[aria-pressed="true"] {
  border-color: #cebee5;
  background: #eee7f9;
  color: #56338c;
}
#article-body-editor .re-tool:disabled {
  opacity: 0.44;
  cursor: default;
}
#article-body-editor
  :is(
    .re-tool,
    .re-style,
    .re-node-btn,
    .re-code-language,
    .re-link-input,
    .re-link-panel button
  ):focus-visible,
#article-form .writer-settings > summary:focus-visible {
  outline: 2px solid #7650ae;
  outline-offset: 2px;
}
.re-toolbar .re-tool svg {
  display: block;
  flex-shrink: 0;
  width: 17px;
  height: 17px;
}
#article-body-editor .re-link-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px var(--writer-inset);
  border-bottom: 1px solid var(--border);
  background: #f6f1fb;
}
#article-body-editor .re-link-input {
  flex: 1 1 170px;
  width: auto;
  min-width: 0;
  margin: 0;
}
#article-body-editor .re-link-panel label {
  display: flex;
  flex: 1 1 230px;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px 8px;
  min-width: 0;
}
.re-link-error:not(:empty) { flex-basis: 100%; color: #8b3654; font-size: .83rem; }
.re-link-panel[hidden] {
  display: none;
}
.re-body,
.art-rich {
  min-width: 0;
}
#article-body-editor .re-content {
  position: relative;
  min-width: 0;
  min-height: clamp(290px, 42vh, 490px);
  margin: 0;
  padding: clamp(22px, 3.2vw, 36px) var(--writer-inset) 35px;
  border: 0;
  outline: 0;
  white-space: pre-wrap;
  white-space: break-spaces;
  overflow-wrap: break-word;
  caret-color: #613969;
}
#article-body-editor .re-content:focus-visible {
  box-shadow: inset 2px 0 #8865b5;
}
#article-body-editor .re-content {
  font-variant-ligatures: none;
}
.re-content li { position: relative; }
.re-content img.ProseMirror-separator {
  display: inline !important;
  border: 0 !important;
  margin: 0 !important;
}
.re-content [draggable][contenteditable="false"] { user-select: text; }
#article-body-editor .re-content.ProseMirror-hideselection { caret-color: transparent; }
.re-content.ProseMirror-hideselection ::selection { background: transparent; }
.re-content .ProseMirror-gapcursor {
  position: absolute;
  display: none;
  pointer-events: none;
}
.re-content.ProseMirror-focused .ProseMirror-gapcursor {
  display: block;
}
.re-content .ProseMirror-gapcursor::after {
  content: "";
  position: absolute;
  display: block;
  width: 20px;
  border-top: 2px solid var(--accent);
}
.re-content[data-empty="true"]::before,
.re-content p.is-editor-empty:first-child::before,
.re-content p[data-placeholder]:empty::before,
.re-content
  p[data-placeholder]:has(> br.ProseMirror-trailingBreak:only-child)::before {
  content: attr(data-placeholder);
  float: left;
  height: 0;
  color: #7f748a;
  pointer-events: none;
}

/* Keep the same hierarchy in the body, article reader and preview dialog. */
:is(.art-rich, .re-content) {
  color: #342d3d;
  font:
    400 clamp(1rem, 1.3vw, 1.08rem)/1.85 "DM Sans",
    "PingFang SC",
    "Microsoft YaHei",
    system-ui,
    sans-serif;
  text-align: start;
  overflow-wrap: anywhere;
  word-break: normal;
}
:is(.art-rich, .re-content) :is(p, h2, h3, blockquote, ul, ol) {
  max-width: 100%;
}
:is(.art-rich, .re-content) p {
  margin: 0 0 0.85em;
}
:is(.art-rich, .re-content) :is(h2, h3) {
  color: #30253d;
  margin: 1.45em 0 0.48em;
  letter-spacing: -0.025em;
  text-wrap: pretty;
}
:is(.art-rich, .re-content) h2 {
  font: 700 clamp(1.32rem, 2.2vw, 1.6rem)/1.4 var(--serif);
}
:is(.art-rich, .re-content) h3 {
  font-size: clamp(1.1rem, 1.65vw, 1.25rem);
  font-weight: 680;
  line-height: 1.48;
}
:is(.art-rich, .re-content) :is(ul, ol) {
  margin: 0.45em 0 1em;
  padding-inline-start: 1.65em;
}
:is(.art-rich, .re-content) ul {
  list-style: disc outside;
}
:is(.art-rich, .re-content) ol {
  list-style: decimal outside;
}
:is(.art-rich, .re-content) li {
  margin: 0.18em 0;
}
:is(.art-rich, .re-content) li::marker {
  color: #745994;
}
:is(.art-rich, .re-content) li p {
  margin: 0.15em 0;
}
:is(.art-rich, .re-content) li :is(ul, ol) {
  margin-block: 0.2em 0.3em;
}
:is(.art-rich, .re-content) blockquote {
  margin: 1.1em 0;
  padding: 0.65em 1.05em;
  border-inline-start: 3px solid #b69acf;
  border-radius: 0 8px 8px 0;
  background: #f7f3fa;
  color: #584b65;
}
:is(.art-rich, .re-content) blockquote > :last-child {
  margin-bottom: 0;
}
:is(.art-rich, .re-content) a {
  color: #66409b;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
:is(.art-rich, .re-content) strong {
  font-weight: 700;
}
:is(.art-rich, .re-content) u {
  text-underline-offset: 0.15em;
}
:is(.art-rich, .re-content) > :first-child {
  margin-top: 0;
}
:is(.art-rich, .re-content) > :last-child {
  margin-bottom: 0;
}

.re-content :is(.re-media, .re-code) {
  min-width: 0;
  max-width: 100%;
  margin: 1.05em 0;
  border: 1px solid #dbd3e5;
  border-radius: 12px;
  background: #faf8fc;
  color: var(--text);
  white-space: normal;
}
.re-content .ProseMirror-selectednode {
  outline: 2px solid #8863be;
  outline-offset: 2px;
}
.re-media :is(.re-media-preview, img, video) {
  max-width: 100%;
}
.re-media :is(img, video) {
  display: block;
  width: auto;
  max-height: 60vh;
  margin: 0 auto;
  border-radius: 10px;
  object-fit: contain;
}
.re-media .re-file-card,
.re-media .re-upload-status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 13px 15px;
  font-size: 0.88rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.re-media[data-state="failed"] {
  border-color: #d9adb9;
}
.re-media[data-state="failed"] .re-upload-status {
  color: #913655;
}
.re-node-tools,
.re-code-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 6px 10px;
}
.re-node-tools {
  justify-content: flex-end;
}
.re-code-bar {
  justify-content: space-between;
  border-bottom: 1px solid #ddd4e7;
  border-radius: 11px 11px 0 0;
  background: #f0ebf7;
}
#article-body-editor .re-node-btn,
#article-body-editor select.re-code-language {
  min-height: 32px;
  max-width: 100%;
  margin: 0;
  padding: 4px 8px;
  border: 1px solid #d7cee2;
  border-radius: 7px;
  background: white;
  color: #59466c;
  font:
    550 0.81rem/1.35 "DM Sans",
    "PingFang SC",
    system-ui,
    sans-serif;
  cursor: pointer;
}
#article-body-editor select.re-code-language {
  width: auto;
}
.re-code pre {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  padding: 12px 15px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}
.re-code pre .re-code-input {
  display: block;
  width: max-content;
  min-width: 100%;
  min-height: 1.7em;
  color: #372c47;
  font:
    0.92rem/1.65 "IBM Plex Mono",
    ui-monospace,
    SFMono-Regular,
    Consolas,
    monospace;
  font-variant-ligatures: none;
  white-space: pre;
  tab-size: 4;
}
#article-form .writer-settings {
  min-width: 0;
  margin: 0 var(--writer-inset);
  border-top: 1px solid var(--border);
}
#article-form .writer-settings > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 8px 0;
  color: #51435d;
  font-size: 0.94rem;
  font-weight: 650;
  list-style: none;
  cursor: pointer;
}
.writer-settings-summary {
  min-width: 0;
  margin-inline-start: auto;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 500;
  text-align: end;
  overflow-wrap: anywhere;
}
.writer-settings > summary::-webkit-details-marker {
  display: none;
}
.writer-settings > summary::after {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-inline-end: 4px;
  border-right: 1.5px solid #78678a;
  border-bottom: 1.5px solid #78678a;
  transform: rotate(45deg);
}
.writer-settings[open] > summary::after {
  transform: rotate(225deg);
}
.writer-settings-body {
  display: grid;
  gap: 16px;
  min-width: 0;
  padding: 2px 0 22px;
}
#article-form .writer-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 15px var(--writer-inset) 18px;
  border-top: 1px solid var(--border);
}
.writer-actions #article-draft {
  margin-inline-start: auto;
}
@media (hover: hover) {
  #article-body-editor :is(.re-tool, .re-node-btn):hover:not(:disabled) {
    background: #eee8f5;
    color: #533a77;
  }
}
@media (max-width: 650px) {
  #article-form.art-writer {
    --writer-inset: clamp(14px, 4.7vw, 25px);
    border-radius: 15px;
  }
  #article-body-editor .re-toolbar {
    position: static;
    gap: 3px 2px;
    padding: 6px 8px;
  }
  /* Let individual controls use the available row width on small screens. */
  .re-toolbar .re-tools {
    display: contents;
  }
  #article-body-editor .re-tool,
  #article-body-editor .re-style {
    min-height: 40px;
  }
  #article-body-editor .re-tool {
    min-width: 34px;
    padding-inline: 4px;
    gap: 2px;
  }
  #article-body-editor .re-content {
    min-height: max(240px, 36svh);
    padding-block: 20px 27px;
  }
  .writer-settings-body .art-two {
    grid-template-columns: minmax(0, 1fr);
  }
  #article-form .writer-actions {
    padding: 12px var(--writer-inset) 15px;
  }
  #article-form .writer-actions .btn {
    min-height: 42px;
  }
  .re-code pre {
    padding: 12px 10px;
  }
}
@media (max-width: 375px) {
  #article-body-editor .re-toolbar {
    padding-inline: 5px;
  }
  #article-form .writer-actions {
    gap: 5px;
  }
  #article-form .writer-actions .btn {
    padding-inline: 9px;
  }
}
