/* markdown.org tools — block view of the Markdown editor (MDTools.mountMarkdownBlocks) */
.mdb { background: var(--bg); }

/* toolbar: one button per block type, then the diagram menu; undo/redo on the right */
.mdb-bar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.mdb-insert, .mdb-hist { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.mdb-hist { margin-left: auto; }
.mdb-bar-h { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; margin-right: 4px; }
.mdb-tool { min-width: 34px; height: 32px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--accent-tint); color: var(--heading); font: 700 0.82rem/1 var(--font); cursor: pointer; white-space: nowrap; }
.mdb-tool:hover { border-color: var(--accent); color: var(--accent-hover); }
.mdb-tool:active { background: var(--accent); color: #fff; }
.mdb-tool[disabled] { opacity: 0.4; cursor: default; }
.mdb-tool-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.mdb-tool-wide { padding: 0 12px; }

/* the list of blocks */
.mdb-list { position: relative; display: flex; flex-direction: column; gap: 14px; padding: 22px 10px 18px; min-height: 50vh; }
.mdb-end { display: flex; flex-direction: column; align-items: center; gap: 6px; padding-top: 4px; }
.mdb-add-end { padding: 9px 18px; border: 2px dashed var(--border-strong); border-radius: var(--radius-sm); background: transparent; color: var(--muted); font: 700 0.9rem var(--font); cursor: pointer; }
.mdb-add-end:hover { border-color: var(--accent); color: var(--accent); background: var(--surface); }
.mdb-hint { margin: 0; font-size: 0.8rem; color: var(--muted); }
.mdb-empty .mdb-list { justify-content: center; }

/* a block: rough grip | bordered body | rough grip */
.mdb-block { position: relative; display: grid; grid-template-columns: 14px minmax(0, 1fr) 14px; }
.mdb-body { position: relative; min-width: 0; background: var(--surface); border: 1px solid var(--border-strong); padding: 26px 16px 12px; }
.mdb-block:hover .mdb-body { border-color: var(--accent); }
.mdb-block.is-selected .mdb-body { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* the grips either side: rounded tabs ridged with horizontal grooves (dark stripe, gap, light
   stripe, gap) so they read as a rough surface to take hold of; drag either one to move the block */
.mdb-grip {
  --groove: #a9c0f2; --ridge: #f4f7ff; --gap: #d3e0fb;
  cursor: grab; touch-action: none;
  background: repeating-linear-gradient(to bottom, var(--groove) 0 2px, var(--gap) 2px 3px, var(--ridge) 3px 5px, var(--gap) 5px 6px);
  border: 1px solid var(--border-strong);
}
.mdb-grip-l { border-right: 0; border-radius: 7px 0 0 7px; }
.mdb-grip-r { border-left: 0; border-radius: 0 7px 7px 0; }
.mdb-block:hover .mdb-grip, .mdb-block.is-selected .mdb-grip { --groove: #8eabef; --gap: #c3d4fa; border-color: var(--accent); }
.mdb-grip:hover { --groove: #6f93ea !important; --gap: #b3c9f9 !important; }
.mdb-grabbing, .mdb-grabbing * { cursor: grabbing !important; user-select: none !important; }

/* block head: type label + actions (shown on hover / when selected) */
.mdb-head { position: absolute; top: 4px; left: 10px; right: 8px; display: flex; align-items: center; gap: 8px; height: 20px; }
.mdb-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; color: var(--muted); opacity: 0.55; cursor: pointer; }
.mdb-block:hover .mdb-label, .mdb-block.is-selected .mdb-label { opacity: 1; color: var(--accent); }
.mdb-btools { margin-left: auto; display: flex; gap: 3px; opacity: 0; transition: opacity 0.12s; }
.mdb-block:hover .mdb-btools, .mdb-block.is-selected .mdb-btools { opacity: 1; }
.mdb-mini { height: 20px; min-width: 22px; padding: 0 6px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); color: var(--heading); font: 700 0.72rem/1 var(--font); cursor: pointer; }
.mdb-mini:hover { border-color: var(--accent); color: var(--accent); }
.mdb-del:hover { border-color: var(--err-bd); color: var(--err-fg); background: var(--err-bg); }
.mdb-done { display: none; background: var(--accent); color: #fff; border-color: var(--accent); }
.mdb-done:hover { color: #fff; }
.mdb-block.is-selected .mdb-done { display: inline-block; }

/* rendered view vs. in-place editor */
.mdb-view { cursor: text; overflow-x: auto; }
.mdb-view.markdown-preview { border: 0; border-radius: 0; padding: 0; background: transparent; } /* keep the typography, drop the card */
.mdb-view > :first-child { margin-top: 0; }
.mdb-view > :last-child { margin-bottom: 0; }
.mdb-view h1, .mdb-view h2, .mdb-view h3, .mdb-view h4, .mdb-view h5, .mdb-view h6 { margin: 0; }
.mdb-view img { max-width: 100%; height: auto; }
.mdb-view .md-diagram, .mdb-dia { text-align: center; }
.mdb-view svg { max-width: 100%; height: auto; }
.mdb-view hr { margin: 6px 0; }
.mdb-view table { margin: 0; }
.mdb-placeholder { margin: 0; color: var(--muted); font-style: italic; }
.mdb-srcview { margin: 0; white-space: pre-wrap; background: var(--surface-soft); color: var(--fg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font: 0.85rem/1.55 var(--mono); }
.mdb-block.is-editing .mdb-view { display: none; }
.mdb-edit:empty { display: none; }

.mdb-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.mdb-fmt { display: flex; gap: 4px; }
.mdb-select { width: auto; max-width: 100%; }
.mdb-view .mdb-check { margin: 0 6px 0 0; vertical-align: -2px; accent-color: var(--accent); }
.mdb-view li:has(> .mdb-check) { list-style: none; margin-left: -1.2em; }
.mdb-select, .mdb-input, .mdb-ta { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 6px 9px; }
.mdb-select:focus, .mdb-input:focus, .mdb-ta:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.mdb-ta { display: block; width: 100%; box-sizing: border-box; resize: none; overflow: hidden; line-height: 1.6; min-height: 2.4em; }
.mdb-mono { font-family: var(--mono); font-size: 0.88rem; }
.mdb-code { background: var(--surface-soft); tab-size: 2; }
.mdb-quote-ta { border-left: 4px solid var(--accent); }
.mdb-input { width: 100%; box-sizing: border-box; }
.mdb-h-input { font-weight: 700; color: var(--heading); }
.mdb-h1 { font-size: 1.9rem; } .mdb-h2 { font-size: 1.5rem; } .mdb-h3 { font-size: 1.25rem; }
.mdb-h4 { font-size: 1.1rem; } .mdb-h5 { font-size: 1rem; } .mdb-h6 { font-size: 0.92rem; }
.mdb-lang { width: 220px; }
.mdb-cap { font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.mdb-note { margin: 0 0 8px; font-size: 0.85rem; color: var(--muted); }
.mdb-items { display: flex; flex-direction: column; gap: 5px; margin-bottom: 8px; }
.mdb-item { display: flex; align-items: center; gap: 8px; }
.mdb-item input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); flex: 0 0 auto; }
.mdb-marker { min-width: 22px; text-align: right; font-weight: 700; color: var(--muted); }
.mdb-img-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 12px; margin-bottom: 10px; }
.mdb-fld { display: flex; flex-direction: column; gap: 3px; }
.mdb-img-prev img { max-width: 100%; max-height: 320px; border-radius: 8px; }
.mdb-host .mde { box-shadow: none; }

/* insert points: a + on the line between blocks */
.mdb-add { position: absolute; left: 14px; right: 14px; top: -14px; height: 14px; display: flex; align-items: center; justify-content: center; z-index: 2; }
.mdb-add::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 2px dashed transparent; transition: border-color 0.12s; }
.mdb-add-btn { position: relative; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--accent); background: var(--surface); color: var(--accent); font: 700 0.95rem/1 var(--font); padding: 0; cursor: pointer; opacity: 0; transform: scale(0.8); transition: opacity 0.12s, transform 0.12s; }
.mdb-add:hover::before { border-top-color: var(--accent); }
.mdb-add:hover .mdb-add-btn { opacity: 1; transform: none; }
.mdb-add-btn:hover, .mdb-add-btn:focus-visible { background: var(--accent); color: #fff; opacity: 1; transform: none; }
.mdb-block:first-child .mdb-add { top: -18px; height: 18px; }

/* dragging: the lifted block follows the cursor; a dotted slot shows where it will land */
.mdb-block.mdb-dragging { position: fixed; z-index: 3000; margin: 0; pointer-events: none; filter: drop-shadow(0 14px 22px rgba(16, 24, 40, 0.22)); transform: rotate(-0.4deg) scale(1.01); }
.mdb-block.mdb-dragging .mdb-body { border-color: var(--accent); }
.mdb-block.mdb-dragging .mdb-add, .mdb-grabbing .mdb-add { display: none; }
.mdb-ph { border: 2px dashed var(--accent); border-radius: var(--radius-sm); background: rgba(59, 110, 246, 0.06); box-sizing: border-box; }

/* insert menu */
.mdb-menu { position: fixed; z-index: 9500; width: 300px; max-height: min(460px, 70vh); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); overflow: hidden; }
.mdb-menu-q { border-radius: 0; border: 0; border-bottom: 1px solid var(--border); padding: 10px 12px; }
.mdb-menu-q:focus { box-shadow: none; }
.mdb-menu-items { overflow-y: auto; padding: 4px 6px 8px; }
.mdb-menu-h { padding: 10px 6px 4px; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; color: var(--muted); }
.mdb-menu-item { display: flex; align-items: center; justify-content: flex-start; gap: 10px; width: 100%; min-height: 0; margin: 0; padding: 6px 8px; border: 0; border-radius: 7px; background: none; box-shadow: none; color: var(--fg); font: 500 0.9rem var(--font); text-align: left; cursor: pointer; }
.mdb-menu-item:hover, .mdb-menu-item:focus-visible { background: var(--accent-tint); color: var(--heading); outline: none; }
.mdb-menu-icon { width: 30px; flex: 0 0 auto; text-align: center; font-weight: 700; font-size: 0.8rem; color: var(--accent); }
.mdb-menu .mdb-note { padding: 8px; }

/* Markdown editor: Text / Blocks switch */
.mde-views { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface); }
.mde-view { padding: 5px 14px; border: 0; border-radius: 6px; background: none; color: var(--fg); font: 700 0.88rem var(--font); cursor: pointer; }
.mde-view[aria-pressed="true"] { background: var(--accent); color: #fff; }
.mde.is-blocks .mde-tabs { display: none; }
/* overflow:hidden on the editor card would stop the block toolbar sticking; clip keeps the rounded corners */
.mde.is-blocks { overflow: visible; overflow: clip; }
.mde-blocks[hidden], .mde-panes[hidden] { display: none; }

@media (max-width: 720px) {
  .mdb-list { padding-left: 2px; padding-right: 2px; }
  .mdb-body { padding-left: 10px; padding-right: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .mdb-add-btn, .mdb-btools, .mdb-grip { transition: none; }
}
