.markdown-editor {
  position: relative;
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(145, 118, 194, .24);
  border-radius: 14px;
  background: rgba(13, 10, 22, .74);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .03);
  overflow: visible;
  transition: border-color .2s ease, box-shadow .2s ease;
}

.markdown-editor:focus-within {
  border-color: rgba(145, 99, 255, .62);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, .12), inset 0 1px 0 rgba(255, 255, 255, .04);
}

.markdown-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 48px;
  padding: 7px 9px;
  border-bottom: 1px solid rgba(145, 118, 194, .18);
  border-radius: 13px 13px 0 0;
  background: linear-gradient(180deg, rgba(32, 29, 42, .98), rgba(25, 22, 34, .98));
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: thin;
  scrollbar-color: rgba(139, 99, 255, .48) transparent;
  overscroll-behavior-x: contain;
}

.markdown-toolbar::-webkit-scrollbar { height: 4px; }
.markdown-toolbar::-webkit-scrollbar-thumb { background: rgba(139, 99, 255, .48); border-radius: 999px; }

.markdown-toolbar-group {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
}

.markdown-toolbar-group + .markdown-toolbar-group {
  margin-left: 4px;
  padding-left: 7px;
  border-left: 1px solid rgba(255, 255, 255, .08);
}

.markdown-tool {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: #c6c1d0;
  font: inherit;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: color .16s ease, background .16s ease, border-color .16s ease, transform .16s ease;
}

.markdown-tool:hover,
.markdown-tool:focus-visible,
.markdown-tool.is-active {
  color: #fff;
  background: rgba(125, 95, 255, .18);
  border-color: rgba(139, 99, 255, .38);
  outline: none;
}

.markdown-tool:active { transform: translateY(1px); }
.markdown-tool strong { font-size: 18px; }
.markdown-tool em { font-family: Georgia, serif; font-size: 20px; }
.markdown-m-icon { font-size: 11px; font-weight: 800; letter-spacing: -.04em; }
.markdown-heading-icon { position: relative; font-size: 18px; font-weight: 700; }
.markdown-heading-icon::after { content: 'A'; position: absolute; left: 10px; top: 8px; font-size: 9px; color: #6ff6e9; }
.markdown-strike-icon { text-decoration: line-through; font-weight: 700; }
.markdown-code-icon { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; font-weight: 800; }
.markdown-quote-icon { font-family: Georgia, serif; font-size: 21px; }
.markdown-preview-toggle { margin-left: 2px; }

.markdown-editor-textarea {
  display: block;
  width: 100%;
  min-height: 150px;
  margin: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: rgba(16, 11, 25, .74) !important;
  box-shadow: none !important;
  resize: vertical;
}

.markdown-editor-textarea:focus { outline: none !important; box-shadow: none !important; }
.markdown-editor--compact .markdown-editor-textarea { min-height: 105px; }

.markdown-editor-preview {
  min-height: 150px;
  max-height: 620px;
  padding: 18px 20px;
  overflow: auto;
  background: rgba(16, 11, 25, .74);
  color: var(--text, #f4f0ff);
}

.markdown-editor--compact .markdown-editor-preview { min-height: 105px; }
.markdown-preview-empty { color: var(--muted, #aaa2bb); font-style: italic; }

.markdown-editor-status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 11px;
  border-top: 1px solid rgba(145, 118, 194, .14);
  border-radius: 0 0 13px 13px;
  color: #8e879b;
  background: rgba(24, 20, 32, .96);
  font-size: 11px;
  line-height: 1.4;
}

.markdown-popover {
  position: absolute;
  z-index: 150;
  top: calc(100% + 10px);
  left: 0;
  width: min(340px, calc(100vw - 36px));
  padding: 13px;
  border: 1px solid rgba(149, 111, 255, .38);
  border-radius: 13px;
  background: rgba(17, 13, 25, .99);
  box-shadow: 0 22px 60px rgba(0, 0, 0, .44), 0 0 0 1px rgba(255, 255, 255, .025) inset;
  color: #f7f3ff;
  opacity: 0;
  transform: translateY(-5px) scale(.985);
  transform-origin: top left;
  transition: opacity .15s ease, transform .15s ease;
}

.markdown-popover.is-open { opacity: 1; transform: translateY(0) scale(1); }
.markdown-popover-title { display: flex; flex-direction: column; gap: 3px; margin-bottom: 11px; }
.markdown-popover-title strong { color: #fff; font-size: 14px; }
.markdown-popover-title small { color: #9b93a9; font-size: 11px; }

.markdown-command-menu,
.markdown-heading-menu {
  width: 210px;
  padding: 7px;
}

.markdown-command-menu > button,
.markdown-heading-menu > button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #d9d4e2;
  text-align: left;
  cursor: pointer;
}

.markdown-command-menu > button:hover,
.markdown-command-menu > button:focus-visible,
.markdown-heading-menu > button:hover,
.markdown-heading-menu > button:focus-visible {
  outline: none;
  background: rgba(127, 92, 255, .18);
  color: #fff;
}

.markdown-heading-menu > strong { display: block; padding: 8px 10px 5px; color: #8f879c; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.markdown-heading-menu > button span { width: 32px; color: #9b75ff; font: 800 12px/1 ui-monospace, monospace; }

.markdown-symbol-picker { width: min(390px, calc(100vw - 28px)); }
.markdown-symbol-grid { display: grid; grid-template-columns: repeat(8, minmax(30px, 1fr)); gap: 5px; }
.markdown-symbol-grid button {
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 8px;
  background: rgba(255,255,255,.035);
  font-size: 18px;
  cursor: pointer;
}
.markdown-symbol-grid button:hover,
.markdown-symbol-grid button:focus-visible { outline: none; border-color: rgba(139,99,255,.5); background: rgba(139,99,255,.18); }
.markdown-popover-hint { margin: 10px 0 0; color: #8f879c; font-size: 11px; }

.markdown-guide-popover { width: min(460px, calc(100vw - 28px)); }
.markdown-guide-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.markdown-guide-grid span { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 9px; border: 1px solid rgba(255,255,255,.06); border-radius: 8px; background: rgba(255,255,255,.025); }
.markdown-guide-grid code { color: #77e9dc; font-size: 11px; }
.markdown-guide-grid b,
.markdown-guide-grid i,
.markdown-guide-grid del,
.markdown-guide-grid mark { color: #e8e2f1; font-size: 12px; }

.markdown-url-dialog label { display: block; margin: 9px 0 0; }
.markdown-url-dialog label span { display: block; margin-bottom: 5px; color: #bbb3c7; font-size: 11px; font-weight: 700; }
.markdown-url-dialog input { width: 100%; min-height: 40px; }
.markdown-dialog-error { margin: 8px 0 0; color: #ff8da2; font-size: 11px; }
.markdown-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.prose blockquote,
.markdown-content blockquote {
  margin: 1.2em 0;
  padding: 14px 18px;
  border-left: 3px solid #8d65ff;
  border-radius: 0 10px 10px 0;
  background: rgba(128, 91, 255, .09);
  color: #d8d2e2;
}
.prose blockquote p,
.markdown-content blockquote p { margin: 0; }
.prose hr,
.markdown-content hr { height: 1px; margin: 1.7em 0; border: 0; background: linear-gradient(90deg, transparent, rgba(145,111,255,.5), transparent); }
.prose mark,
.markdown-content mark { padding: .08em .22em; border-radius: 4px; background: rgba(255, 194, 76, .25); color: #ffe7a4; }
.prose del,
.markdown-content del { color: #9991a5; }
.prose img,
.markdown-content img { display: block; max-width: 100%; height: auto; margin: 1.1em auto; border: 1px solid rgba(147,115,255,.2); border-radius: 12px; box-shadow: 0 14px 38px rgba(0,0,0,.28); }
.prose pre,
.markdown-content pre { position: relative; max-width: 100%; overflow: auto; }
.prose pre code,
.markdown-content pre code { white-space: pre; }
.markdown-table-wrap { width: 100%; margin: 1.2em 0; overflow-x: auto; border: 1px solid rgba(145,111,255,.2); border-radius: 11px; }
.markdown-table-wrap table { width: 100%; min-width: 480px; border-collapse: collapse; }
.markdown-table-wrap th,
.markdown-table-wrap td { padding: 10px 12px; border-bottom: 1px solid rgba(255,255,255,.07); border-right: 1px solid rgba(255,255,255,.05); }
.markdown-table-wrap th { background: rgba(131,91,255,.12); color: #fff; font-size: 12px; }
.markdown-table-wrap tr:last-child td { border-bottom: 0; }
.task-list { padding-left: 0 !important; list-style: none !important; }
.task-list li { display: flex; align-items: flex-start; gap: 9px; }
.task-list input { width: 16px; height: 16px; margin-top: .25em; accent-color: #8c64ff; }
.markdown-spoiler { padding: .08em .3em; border-radius: 4px; background: #292431; color: transparent; cursor: pointer; user-select: none; transition: color .16s ease, background .16s ease; }
.markdown-spoiler:hover,
.markdown-spoiler:focus,
.markdown-spoiler.is-revealed { color: inherit; background: rgba(139,99,255,.18); outline: none; }
.markdown-content > :first-child { margin-top: 0; }
.markdown-content > :last-child { margin-bottom: 0; }

@media (max-width: 720px) {
  .markdown-toolbar { min-height: 46px; padding: 6px 7px; }
  .markdown-tool { min-width: 32px; height: 32px; padding: 0 7px; }
  .markdown-toolbar-group + .markdown-toolbar-group { margin-left: 2px; padding-left: 4px; }
  .markdown-editor-preview { padding: 15px; }
  .markdown-guide-grid { grid-template-columns: 1fr; }
  .markdown-symbol-grid { grid-template-columns: repeat(6, minmax(31px, 1fr)); }
  .markdown-popover { position: fixed; top: 50%; left: 50% !important; right: auto !important; max-height: min(72vh, 560px); overflow-y: auto; transform: translate(-50%, calc(-50% - 5px)) scale(.985); transform-origin: center; }
  .markdown-popover.is-open { transform: translate(-50%, -50%) scale(1); }
}

@media (max-width: 390px) {
  .markdown-symbol-grid { grid-template-columns: repeat(5, minmax(30px, 1fr)); }
  .markdown-editor-status { flex-direction: column; gap: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .markdown-tool,
  .markdown-popover,
  .markdown-spoiler { transition: none; }
}

.punishment .markdown-content {
  color: var(--muted, #aaa2bb);
}
.punishment .markdown-content p {
  margin: 0;
}
.admin-support-message .markdown-content,
.support-message-body.markdown-content {
  overflow-wrap: anywhere;
}


/* Markdown editor spacing inside forms and the Support Form Builder */
.markdown-editor { margin-top: 1px; }
.markdown-toolbar { margin-bottom: 0; }
.markdown-editor-textarea { min-height: 150px; line-height: 1.6; }
.markdown-editor.is-compact .markdown-editor-textarea { min-height: 105px; }
.markdown-editor-status { padding: 8px 11px; line-height: 1.45; }
.markdown-editor-preview { line-height: 1.7; }
@media (max-width: 700px) {
  .markdown-editor-textarea { min-height: 135px; }
  .markdown-editor.is-compact .markdown-editor-textarea { min-height: 96px; }
}
