/* ============================================================================
   The document editor (editor.js, editor-table.js, editor-diagram.js).

   The page you write on is the page people read: same measure, same type,
   same spacing as #article. Everything else — toolbar, popovers, the review
   panel — is chrome that recedes around it.
   ========================================================================= */

/* ---------- layout ---------- */

#editor-wrap.rich #editor-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, calc(var(--measure) + 48px)) minmax(0, 1fr);
  align-content: start;
  padding: 0 0 0;
  background: var(--bg);
  scroll-padding-top: 24px;
}
#editor-wrap.rich #editor-main > * { grid-column: 2; min-width: 0; }
#editor-wrap.rich[data-view='markdown'] #editor-main > #editor-card,
#editor-wrap.rich[data-view='changes'] #editor-main > #editor-card {
  grid-column: 1 / -1;
  width: min(100% - 48px, 880px);
  justify-self: center;
}
#editor-wrap.rich #editor-card {
  max-width: none;
  margin: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  overflow: visible;
}
#editor-wrap.rich.ed-writing .ed-strip { display: none; }
#editor-wrap.rich[data-view='markdown'] #editor-card,
#editor-wrap.rich[data-view='changes'] #editor-card {
  margin-top: 28px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  overflow: hidden;
}
#editor-wrap.rich #editor-preview { display: none; }
#editor-wrap.rich[data-view='markdown'] #editor { min-height: calc(100vh - 230px); }

/* The page itself. Same class, same measure, same type as the reading view. */
#editor-wrap #rich-editor {
  min-height: calc(100vh - 220px);
  max-width: var(--measure);
  margin: 0 auto;
  padding: 44px 0 96px;
  background: transparent;
  caret-color: var(--accent);
  animation: none;
  /* --breakout is computed for the reading layout's rail and panes; here the
     column is the editor's own, less the review panel when it is showing. */
  --breakout: clamp(0px, (100vw - var(--ed-side, 0px) - var(--measure)) / 2 - 32px, 96px);
}
#editor-wrap:not(.pr-mode) { --ed-side: 0px; }
#editor-wrap.pr-mode { --ed-side: 400px; }
#rich-editor:focus { outline: none; }
#rich-editor > :first-child { margin-top: 0; }
#rich-editor:empty::before { content: none; }
#rich-editor a { cursor: text; }
#rich-editor ::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* "Type / to insert" on the empty line the caret is on. */
#rich-editor [data-ed-hint]::before {
  content: attr(data-ed-hint);
  float: left;
  height: 0;
  pointer-events: none;
  color: var(--text-faint);
  opacity: 0.75;
  font-style: normal;
}

/* Task lists, here and in the reading view: a box, not a bullet. */
.markdown-body li:has(> input[type='checkbox']:first-child) {
  position: relative;
  list-style: none;
  margin-left: -1.3em;
  padding-left: 1.55em;
}
/* Hung in the margin, so a long item wraps under its words, not its box. */
.markdown-body li > input[type='checkbox']:first-child {
  position: absolute;
  left: 0;
  top: 0.42em;
  width: 1.05em;
  height: 1.05em;
  margin: 0;
  accent-color: var(--accent);
}
#rich-editor li > input[type='checkbox']:first-child { cursor: pointer; }
#rich-editor li:has(> input[type='checkbox']:checked:first-child) {
  color: var(--text-soft);
  text-decoration: line-through;
  text-decoration-color: var(--border-hover);
}

/* Images: their own width when one was chosen, never wider than the page. */
#rich-editor img { max-width: 100%; height: auto; border-radius: var(--r-sm); cursor: pointer; }
#rich-editor img[data-ed-picked],
#rich-editor hr[data-ed-picked] { outline: 2px solid var(--accent); outline-offset: 3px; }
#rich-editor hr { cursor: pointer; padding: 6px 0; background-clip: content-box; height: 13px; }

/* Code blocks you can type in. */
#rich-editor pre { white-space: pre; }
#rich-editor pre code { display: block; min-height: 1.7em; }

/* Tables you can type in: a little more room to aim at a cell. */
#rich-editor table { display: table; width: auto; min-width: min(100%, 360px); }
#rich-editor > table { max-width: calc(100% + var(--breakout)); }
#rich-editor td, #rich-editor th { min-width: 72px; vertical-align: top; }
.markdown-body th[align='center'], .markdown-body td[align='center'] { text-align: center; }
.markdown-body th[align='right'], .markdown-body td[align='right'] { text-align: right; }

/* Diagrams sit in the page as pictures, the way they read. */
#rich-editor .rich-diagram {
  position: relative;
  margin: 0 0 26px;
  padding: 14px 10px 10px;
  border: 1px solid transparent;
  border-radius: var(--r-lg);
  background: transparent;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
#rich-editor .rich-diagram:hover { border-color: var(--border); background: var(--surface-hover-card); }
#rich-editor .rich-diagram[data-ed-picked] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  background: var(--accent-wash);
}
.rich-diagram .rd-view { display: block; overflow-x: auto; min-height: 40px; }
.rich-diagram .rd-hint {
  display: block;
  margin-top: 6px;
  text-align: center;
  font-family: var(--font-ui);
  font-size: 11.5px;
  color: var(--text-faint);
  opacity: 0;
  transition: opacity 0.12s ease;
}
.rich-diagram:hover .rd-hint, .rich-diagram[data-ed-picked] .rd-hint { opacity: 1; }

/* Blocks kept exactly as written: shown, and editable as their source. */
.ed-locked {
  margin: 0 0 26px;
  border: 1px dashed var(--border-dashed);
  border-radius: var(--r-lg);
  background: var(--surface-card-foot);
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: default;
}
.ed-locked[data-ed-picked] { border-color: var(--accent); border-style: solid; }
.ed-locked-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 12px;
}
.ed-locked-label {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-quiet);
}
.ed-locked-edit {
  margin-left: auto;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--r-sm);
}
.ed-locked-edit:hover { background: var(--accent-wash); }
.ed-locked-view { padding: 0 14px 12px; font-family: var(--font-doc); font-size: 17px; }
.ed-locked-view.ed-props { display: flex; flex-wrap: wrap; gap: 6px; font-family: var(--font-ui); font-size: 12.5px; }
.ed-prop { padding: 3px 9px; border-radius: var(--r-pill); background: var(--surface-sunken); color: var(--text-mid); }
.ed-prop b { font-weight: 600; color: var(--text-quiet); margin-right: 4px; }
.ed-locked[data-kind='frontmatter'], .ed-locked[data-kind='def'] { margin-bottom: 20px; }
.ed-locked[data-kind='def'] .ed-locked-view { font-family: var(--font-mono); font-size: 12.5px; color: var(--text-quiet); overflow-wrap: anywhere; }
.ed-locked-view > :last-child { margin-bottom: 0; }
.ed-locked-src {
  display: block;
  width: calc(100% - 16px);
  margin: 0 8px 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--card);
  color: var(--text-body);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.7;
  resize: vertical;
}
.ed-locked-src:focus { outline: none; border-color: var(--accent); }

/* An image on its way up. */
[data-ed-upload] { margin: 0 0 26px; }
.ed-upload {
  position: relative;
  display: inline-block;
  max-width: 100%;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface-sunken);
}
.ed-upload img { display: block; max-width: 100%; max-height: 320px; opacity: 0.45; filter: saturate(0.6); }
.ed-upload-bar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 34px;
  height: 4px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--text) 14%, transparent);
  overflow: hidden;
}
.ed-upload-bar i { display: block; width: 4%; height: 100%; background: var(--accent); transition: width 0.15s ease; }
.ed-upload-label {
  position: absolute;
  left: 12px;
  bottom: 10px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

/* ---------- the bar above the page ---------- */

.ed-status {
  font-size: 12px;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
@media (min-width: 769px) {
  #editor-wrap.pr-mode #editor-save { display: none; }
}

/* ---------- toolbar ---------- */

#ed-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: none;
  padding: 6px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border-soft);
  overflow-x: auto;
  scrollbar-width: none;
  position: relative;
  z-index: 3;
}
#ed-toolbar::-webkit-scrollbar { display: none; }
#ed-toolbar.hidden { display: none; }
.et-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: none;
  min-width: 32px;
  height: 32px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-mid);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 550;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.et-btn .ic { width: 17px; height: 17px; flex: none; }
.et-btn:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }
.et-btn.on { background: var(--accent-wash); color: var(--accent); border-color: var(--accent-tint); }
.et-btn:disabled { opacity: 0.35; cursor: default; }
.et-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.et-labelled { padding: 0 10px 0 8px; }
.et-sep { flex: none; width: 1px; height: 20px; margin: 0 6px; background: var(--border); }
.et-spacer { flex: 0 1 28px; }

.et-style { position: relative; flex: none; }
.et-style-btn { width: 148px; justify-content: space-between; padding: 0 8px 0 10px; border-color: var(--border); background: var(--card); }
.et-style-btn .ic { width: 14px; height: 14px; color: var(--text-soft); }
.et-style-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.et-menu {
  position: fixed;
  z-index: 70;
  margin-top: 4px;
  min-width: 230px;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--e3);
}
.et-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font-family: var(--font-doc);
  text-align: left;
  cursor: pointer;
}
.et-menu-item:hover, .et-menu-item.on { background: var(--surface-hover-card); }
.et-menu-item.on { color: var(--accent); }
.et-menu-item kbd { font-family: var(--font-ui); font-size: 11px; color: var(--text-faint); }
.et-sty-p span { font-size: 15px; }
.et-sty-h1 span { font-size: 24px; font-weight: 600; }
.et-sty-h2 span { font-size: 20px; font-weight: 600; }
.et-sty-h3 span { font-size: 17px; font-weight: 600; }
.et-sty-h4 span { font-size: 15px; font-weight: 650; }
.et-sty-blockquote span { font-size: 15px; padding-left: 9px; border-left: 3px solid var(--hl-strong); color: var(--text-mid); }
.et-sty-pre span { font-family: var(--font-mono); font-size: 12.5px; }

/* ---------- popovers ---------- */

.ed-pop {
  position: fixed;
  z-index: 60;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--e3);
  font-family: var(--font-ui);
  animation: ed-pop-in 0.12s ease;
}
.ed-pop.hidden { display: none; }
@keyframes ed-pop-in {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .ed-pop, #editor-wrap { animation: none; }
  .ed-upload-bar i { transition: none; }
}
.ed-pop-head {
  padding: 8px 12px 4px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* Slash menu */
#ed-slash { width: 290px; max-height: min(380px, 60vh); overflow-y: auto; padding: 0 6px 6px; }
.ed-slash-row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.ed-slash-row.on, .ed-slash-row:hover { background: var(--surface-hover-card); }
.ed-slash-row.on { box-shadow: inset 0 0 0 1px var(--border); }
.ed-slash-ic {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--card);
  color: var(--text-mid);
}
.ed-slash-ic .ic { width: 17px; height: 17px; }
.ed-slash-txt { display: flex; flex-direction: column; min-width: 0; }
.ed-slash-txt b { font-size: 13.5px; font-weight: 600; }
.ed-slash-txt small { font-size: 12px; color: var(--text-soft); }

/* Selection bubble */
.ed-bubble { display: flex; gap: 2px; padding: 4px; }
.ed-bubble .et-btn { min-width: 30px; height: 30px; }

/* Picked image / diagram bar */
.ed-pickbar { display: flex; align-items: center; gap: 8px; padding: 6px; max-width: calc(100vw - 16px); flex-wrap: wrap; }
.ed-pickbar .ghost-btn { display: inline-flex; align-items: center; gap: 6px; }
.ed-pickbar .ghost-btn .ic { width: 14px; height: 14px; }
.ed-alt { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-soft); }
.ed-alt input {
  width: 220px;
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.ed-alt input:focus { outline: none; border-color: var(--accent); }

/* Link popover */
.ed-link { width: min(380px, calc(100vw - 16px)); padding: 12px 14px; }
.ed-link .field-label { margin-top: 8px; }
.ed-link .field-label:first-of-type { margin-top: 0; }
.ed-link input {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
}
.ed-link input:focus { outline: none; border-color: var(--accent); }
.ed-link .row { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.ed-link .row .spacer { flex: 1; }
.ed-link-hint { margin: 6px 0 0; font-size: 12px; color: var(--text-soft); }
.ed-link-hint:empty { display: none; }
.ed-link-hint code { font-family: var(--font-mono); font-size: 11.5px; }
.ed-link[data-mode='view'] { width: auto; max-width: min(440px, calc(100vw - 16px)); padding: 5px 6px 5px 12px; }
.ed-link[data-mode='view'] .ed-link-form, .ed-link[data-mode='form'] .ed-link-view { display: none; }
.ed-link-view { display: flex; align-items: center; gap: 6px; }
.ed-link-url {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}
.ed-link-url:hover { text-decoration: underline; }

/* Table size picker */
.ed-table-pick { padding: 10px; }
.etp-grid { display: grid; grid-template-columns: repeat(8, 20px); gap: 3px; }
.etp-cell {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: var(--card);
  cursor: pointer;
}
.etp-cell.on { background: var(--accent-wash); border-color: var(--accent); }
.etp-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.etp-label { margin: 8px 0 0; text-align: center; font-size: 12.5px; font-weight: 600; color: var(--text-mid); }

/* Table bar */
.ed-table-bar { display: flex; align-items: center; gap: 1px; padding: 4px; max-width: calc(100vw - 16px); overflow-x: auto; }
.ed-table-bar .et-btn { min-width: 30px; height: 30px; }
.etb-title {
  padding: 0 8px 0 6px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* ---------- restore banner, find bar, footer, outline ---------- */

.ed-restore {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 -18px;
  padding: 9px 10px 9px 14px;
  border: 1px solid var(--attn-border);
  border-radius: var(--r-lg);
  background: var(--attn-bg);
  color: var(--attn-text);
  font-size: 13px;
  line-height: 1.45;
  position: relative;
  z-index: 1;
}
.ed-restore > span { flex: 1; display: inline-flex; gap: 8px; align-items: baseline; }
.ed-restore .ic { width: 14px; height: 14px; flex: none; transform: translateY(2px); }
.ed-restore .icon-btn .ic { transform: none; }
.ed-restore.hidden { display: none; }

.ed-find {
  position: sticky;
  top: 10px;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 12px 0 -12px;
  padding: 7px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--e2);
}
.ed-find.hidden { display: none; }
.ed-find input {
  flex: 1 1 140px;
  min-width: 0;
  padding: 6px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.ed-find input:focus { outline: none; border-color: var(--accent); }
.ed-find-n { min-width: 58px; font-size: 12px; color: var(--text-soft); text-align: center; }
.ed-find .icon-btn .ic { width: 15px; height: 15px; }
::highlight(ed-find) { background-color: var(--hl); }
::highlight(ed-find-on) { background-color: var(--hl-strong); color: var(--text); }

.ed-foot {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 0 12px;
  font-size: 12px;
  color: var(--text-soft);
  pointer-events: none;
}
#ed-count:not(:empty) {
  padding: 4px 10px;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(6px);
}
#editor-wrap:not(.ed-writing) .ed-foot,
#editor-wrap:not(.ed-writing) .ed-outline { display: none !important; }
#editor-wrap.rich:not(.ed-writing) .ed-strip #md-diagram-btn,
#editor-wrap.rich:not(.ed-writing) .ed-strip #md-sketch-btn { display: none; }
#editor-wrap.rich[data-view='markdown'] .ed-strip #md-diagram-btn { display: inline-flex; }
#editor-wrap.rich[data-view='markdown'] .ed-strip #md-sketch-btn:not(.hidden) { display: inline-flex; }
#rich-editor [data-ed-cell] { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 50%, transparent); }
.ed-foot > * { pointer-events: auto; }
#editor-wrap:not(.rich) .ed-foot { display: none; }
#ed-outline-btn {
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-pill);
  background: var(--bg);
}

.ed-outline {
  grid-column: 1 !important;
  grid-row: 1 / span 8;
  position: sticky;
  top: 40px;
  align-self: start;
  justify-self: end;
  width: min(220px, calc(100% - 40px));
  margin: 52px 36px 0 0;
  max-height: calc(100vh - 240px);
  overflow-y: auto;
  font-family: var(--font-ui);
}
.ed-outline.hidden { display: none; }
.ed-outline-title {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.ed-ol-row {
  display: block;
  width: 100%;
  padding: 4px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text-quiet);
  font: inherit;
  font-size: 12.5px;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ed-ol-row:hover { background: var(--surface-hover); color: var(--text); }
.ed-ol-h1 { font-weight: 600; color: var(--text-mid); }
.ed-ol-h3 { padding-left: 20px; font-size: 12px; }
/* Docked in the left margin when there is a margin to dock in; otherwise a
   button in the footer opens it as a small panel. */
body.ed-outline-open .ed-outline:not(.hidden) {
  display: block;
  position: fixed;
  right: 16px;
  left: auto;
  top: auto;
  bottom: 52px;
  z-index: 30;
  width: min(280px, calc(100vw - 32px));
  max-height: 50vh;
  margin: 0;
  padding: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--e3);
}
@media (max-width: 1279px) {
  body:not(.ed-outline-open) .ed-outline { display: none; }
}
@media (min-width: 1280px) and (max-width: 1679px) {
  body:not(.ed-outline-open) #editor-wrap.pr-mode .ed-outline { display: none; }
}
@media (min-width: 1280px) {
  #editor-wrap:not(.pr-mode) #ed-outline-btn { display: none; }
}
@media (min-width: 1680px) {
  #ed-outline-btn { display: none; }
}

/* ---------- Changes, readable ---------- */

.diff-mode {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface-card-foot);
  font-family: var(--font-ui);
  font-size: 12.5px;
  color: var(--text-soft);
}
.rd-changes { max-width: none; padding: 20px 28px 28px; animation: none; font-size: 17px; }
.rd-row {
  position: relative;
  margin: 0 0 14px;
  padding: 10px 14px 10px 16px;
  border-radius: var(--r-md);
  border-left: 3px solid transparent;
}
.rd-row > :last-child { margin-bottom: 0; }
.rd-same { opacity: 0.6; padding-top: 0; padding-bottom: 0; }
.rd-add { background: var(--diff-add-bg); border-left-color: var(--diff-add-gutter); }
.rd-del { background: var(--diff-del-bg); border-left-color: var(--diff-del-gutter); }
.rd-del > :not(.rd-tag) { text-decoration: line-through; text-decoration-color: var(--diff-del-gutter); color: var(--diff-del-text); }
.rd-mod { background: var(--surface-card-foot); border-left-color: var(--accent); }
.rd-tag {
  display: inline-block;
  margin-bottom: 4px;
  font-family: var(--font-ui);
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.rd-words { margin: 0; }
.rd-words ins { text-decoration: none; background: var(--diff-add-bg); color: var(--diff-add-text); box-shadow: inset 0 -2px 0 var(--diff-add-gutter); border-radius: 2px; }
.rd-words del { background: var(--diff-del-bg); color: var(--diff-del-text); text-decoration-color: var(--diff-del-gutter); border-radius: 2px; }
.rd-gap {
  margin: 0 0 14px;
  text-align: center;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--text-faint);
}
.rd-gap::before, .rd-gap::after { content: '· · ·'; margin: 0 10px; letter-spacing: 2px; }

/* ---------- review panel ---------- */

.es-opt { font-weight: 450; color: var(--text-faint); margin-left: 4px; }
.es-how { margin-top: 18px; font-size: 12.5px; color: var(--text-soft); }
.es-how summary { cursor: pointer; font-weight: 600; color: var(--text-mid); list-style: none; display: inline-flex; align-items: center; gap: 6px; }
.es-how summary::-webkit-details-marker { display: none; }
.es-how summary::before { content: '›'; display: inline-block; transition: transform 0.12s ease; font-size: 14px; }
.es-how[open] summary::before { transform: rotate(90deg); }
.es-how ol { margin: 12px 0 0; padding: 0; list-style: none; }
.es-how li { position: relative; padding: 0 0 10px 18px; line-height: 1.5; }
.es-how li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 7px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-hover);
}
.es-how li:first-child::before { background: var(--accent); }
.es-how code { font-family: var(--font-mono); font-size: 0.92em; }

/* ---------- diagram studio ---------- */

#diagram-form {
  width: min(1040px, calc(100vw - 32px));
  top: 5vh;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 18px 20px 16px;
  box-shadow: var(--e4), 0 0 0 1px var(--border), 0 0 0 100vmax rgba(20, 18, 16, 0.32);
}
#diagram-form.hidden { display: none; }
.dg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.dg-head h3 { margin: 0; font-family: var(--font-doc); font-size: 20px; font-weight: 600; }
.dg-head .icon-btn { margin-left: auto; }
.dg-tabs { align-self: flex-start; margin-bottom: 14px; }
.dg-tabs .seg-btn.hidden { display: none; }
.dg-body {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 18px;
  min-height: 0;
  flex: 1;
}
.dg-left { overflow-y: auto; min-height: 0; padding-right: 4px; }
.dg-right { display: flex; flex-direction: column; min-height: 0; gap: 8px; }
.dg-preview-wrap {
  position: relative;
  flex: 1;
  min-height: 260px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background:
    radial-gradient(circle, var(--border) 1px, transparent 1.2px) 0 0 / 16px 16px,
    var(--surface-card-foot);
}
/* The picture is scaled to fit the frame, so a tall flowchart is seen whole. */
#diagram-form #dg-preview {
  position: absolute;
  inset: 18px;
  min-height: 0;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}
#diagram-form .dg-cols { grid-template-columns: minmax(0, 1fr); gap: 14px; }
.dg-error {
  margin: 0;
  padding: 9px 12px;
  border-radius: var(--r-md);
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.45;
}
.dg-error.hidden { display: none; }
.dg-note { margin: 0 0 10px; font-size: 12.5px; line-height: 1.5; color: var(--text-soft); }
#dg-desc, #dg-src {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
}
#dg-src { font-family: var(--font-mono); font-size: 12.5px; line-height: 1.7; }
#dg-desc:focus, #dg-src:focus { outline: none; border-color: var(--accent); }
.dg-ai-row { display: flex; align-items: center; gap: 12px; margin: 10px 0 0; }
.dg-ai-row .dg-note { margin: 0; }
#dg-draft { display: inline-flex; align-items: center; gap: 8px; }
.dg-ex-label { margin-top: 22px; }
.dg-examples { display: flex; flex-direction: column; gap: 6px; }
.dg-ex {
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--card);
  color: var(--text-mid);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.dg-ex:hover { border-color: var(--border-hover); color: var(--text); }
.dg-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.dg-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 8px 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--card);
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.dg-card:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.dg-thumb {
  display: block;
  height: 96px;
  margin-bottom: 6px;
  border-radius: var(--r-md);
  background: var(--surface-card-foot);
  overflow: hidden;
  pointer-events: none;
}
.dg-card-name { font-size: 13.5px; font-weight: 600; padding: 0 2px; }
.dg-card-blurb { font-size: 12px; color: var(--text-soft); padding: 0 2px; }
.dg-words { display: flex; flex-direction: column; gap: 6px; }
.dg-word { display: grid; grid-template-columns: 74px minmax(0, 1fr); align-items: center; gap: 8px; }
.dg-word span { font-size: 11px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-faint); }
.dg-word input, .dg-title-field input {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
}
.dg-word input:focus, .dg-title-field input:focus { outline: none; border-color: var(--accent); }
.dg-foot { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border-soft); }
.dg-foot .spacer { flex: 1; }
.dg-title-field { display: flex; align-items: center; gap: 8px; flex: 0 1 380px; font-size: 12.5px; color: var(--text-soft); }

/* ---------- small screens ---------- */

@media (max-width: 1100px) {
  .et-label { display: none; }
  .et-labelled { padding: 0 7px; }
}
@media (max-width: 768px) {
  #editor-wrap.rich #editor-main { display: block; padding: 0 16px; }
  #editor-wrap.rich #editor-card { display: block; }
  #editor-wrap #rich-editor { padding: 24px 0 64px; min-height: 55vh; --breakout: 0px; }
  #editor-wrap.rich[data-view='markdown'] #editor-main > #editor-card,
  #editor-wrap.rich[data-view='changes'] #editor-main > #editor-card { width: 100%; }
  #ed-toolbar {
    justify-content: flex-start;
    padding: 5px 8px;
    /* The toolbar scrolls sideways on a phone; the fade says there is more. */
    mask-image: linear-gradient(to right, #000 82%, transparent);
  }
  #editor-bar .ed-path { flex: 0 1 auto; max-width: 58%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #editor-bar .ed-status { display: block; flex: 1 1 35%; text-align: right; font-size: 11.5px; }
  #editor-seg { margin-right: auto; }
  #editor-bar .spacer { display: none; }
  #editor-seg .seg-btn { padding: 5px 9px; }
  #editor-cancel, #editor-draft, #editor-save { padding-left: 11px; padding-right: 11px; }
  #editor-save { margin-left: auto; }
  .et-style-btn { width: 128px; }
  .ed-restore { margin: 12px 0 -6px; flex-wrap: wrap; }
  .rd-changes { padding: 14px 12px; }
  .ed-alt input { width: 160px; }
  .dg-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; overflow-y: auto; }
  .dg-left, .dg-right { overflow: visible; min-height: auto; }
  .dg-preview-wrap { min-height: 240px; flex: none; }
  #diagram-form { top: 2vh; max-height: 96vh; padding: 14px; }
  .dg-gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dg-foot { flex-wrap: wrap; }
  .dg-title-field { flex: 1 1 100%; }
  .ed-foot { padding: 8px 0; }
}
