/* meerpad: the block editor. Builds on the shell's tokens (css/app.css) and
   defines only what is the editor's own: block colours, list markers, the
   live-preview markers, media, tables, the gutter and selection.

   Sizes are in em from one base (16px, 14px with the page's "small text"), so
   the page's font choice and size carry through every block. Spacing follows
   Notion's: 3px of padding around a line of text and 1px between blocks,
   which is what makes a page read as one document rather than a stack of
   boxes. */

:root {
  /* Notion's nine text colours and backgrounds, light and dark. */
  --ed-gray: light-dark(#86868b, #9b9b9f);
  --ed-brown: light-dark(#9f6b53, #ba856f);
  --ed-orange: light-dark(#d9730d, #c77d48);
  --ed-yellow: light-dark(#cb912f, #ca9849);
  --ed-green: light-dark(#448361, #529e72);
  --ed-blue: light-dark(#337ea9, #5e87c9);
  --ed-purple: light-dark(#9065b0, #9d68d3);
  --ed-pink: light-dark(#c14c8a, #d15796);
  --ed-red: light-dark(#d44c47, #df5452);
  --ed-gray-bg: light-dark(#f0f0f2, #2c2c2e);
  --ed-brown-bg: light-dark(#f4eeee, #4a3228);
  --ed-orange-bg: light-dark(#fbecdd, #5c3b23);
  --ed-yellow-bg: light-dark(#fbf3db, #564328);
  --ed-green-bg: light-dark(#edf3ec, #243d30);
  --ed-blue-bg: light-dark(#e7f3f8, #143a4e);
  --ed-purple-bg: light-dark(#f6f3f9, #3c2d49);
  --ed-pink-bg: light-dark(#faf1f5, #4e2c3c);
  --ed-red-bg: light-dark(#fdebec, #522e2a);
  --ed-select: light-dark(rgba(35, 131, 226, .14), rgba(35, 131, 226, .24));
  --ed-code-bg: var(--bg-elev);
  --ed-inline-code: light-dark(#eb5757, #ff7369);
  --ed-inline-code-bg: light-dark(rgba(135, 131, 120, .15), rgba(135, 131, 120, .2));
  --ed-mark: light-dark(rgba(255, 212, 0, .38), rgba(255, 212, 0, .26));
  --ed-mono: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace);
}

/* --- the page ------------------------------------------------------------------ */
.editor { position: relative; font-size: 16px; line-height: 1.5; color: var(--text); outline: none; }
.small-text .editor { font-size: 14px; }
/* Inside the shell's page column the editor reaches into the side padding, so
   the margins beside the blocks (where the gutter sits, and where a rubber-band
   selection starts) are the editor's too. */
.page-container .editor { margin-inline: calc(-1 * var(--page-pad, 0px)); padding-inline: var(--page-pad, 0px); }
.editor-inner { position: relative; max-width: 720px; margin: 0 auto; }
.page-full-width .editor-inner { max-width: none; }

.editor-title { margin: 0 0 6px; padding: 3px 2px; font-size: 1.85em; line-height: 1.2; font-weight: 700;
  letter-spacing: -.015em; outline: none; white-space: pre-wrap; word-break: break-word; cursor: text; }
.editor-title:empty::before { content: attr(data-placeholder); color: var(--text-faint); pointer-events: none; }
.editor-header { margin: 2px 0 14px; }
.editor-blocks { position: relative; }
.editor-tail { min-height: 140px; cursor: text; }
.editor.is-readonly .editor-tail { min-height: 40px; cursor: default; }

/* --- blocks ---------------------------------------------------------------------- */
.blk { position: relative; margin: 1px 0; }
.blk-row { position: relative; display: flex; align-items: flex-start; min-width: 0; border-radius: 4px; }
.blk-children { padding-left: 1.5em; }
.blk-text { position: relative; flex: 1 1 auto; min-width: 0; min-height: 1.5em; padding: 3px 2px;
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; outline: none; caret-color: var(--text); }

/* Placeholders: in an empty line being edited, and always in an empty heading.
   Positioned, so the caret sits at the start of the line rather than after
   the words. */
.blk-text:empty::before { position: absolute; left: 2px; right: 2px; top: 3px; overflow: hidden; white-space: nowrap;
  text-overflow: ellipsis; color: var(--text-faint); pointer-events: none; }
.editor:not(.is-readonly) .blk-text:empty:focus::before,
.editor:not(.is-readonly) .blk-heading_1 > .blk-row > .blk-text:empty::before,
.editor:not(.is-readonly) .blk-heading_2 > .blk-row > .blk-text:empty::before,
.editor:not(.is-readonly) .blk-heading_3 > .blk-row > .blk-text:empty::before { content: attr(data-placeholder); }

/* The live preview (meerail's): markers are real text, dimmed where the caret
   is and hidden everywhere else, so a block's DOM never changes on focus.
   `is-live` rather than :focus, because a browser focuses the editable before
   it places the caret for a click: the markers must appear only after that,
   or the text shifts under the pointer and the caret lands a few characters
   off (app.editor.input.js sets the class on mouseup). */
.md-mark { color: var(--text-faint); font-weight: 400; font-style: normal; opacity: .8; }
.blk-text:not(.is-live) .md-mark, .tbl-cell:not(.is-live) .md-mark, .editor.is-readonly .md-mark { display: none; }
.blk-text strong, .tbl-cell strong { font-weight: 600; }
.blk-text del, .tbl-cell del { text-decoration: line-through; text-decoration-color: var(--text-muted); }
.blk-text mark, .tbl-cell mark { background: var(--ed-mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.blk-text .md-code, .tbl-cell .md-code { font-family: var(--ed-mono); font-size: .85em; color: var(--ed-inline-code);
  background: var(--ed-inline-code-bg); border-radius: 4px; padding: .12em .32em; }
.blk-text .md-link, .tbl-cell .md-link, .blk-text a, .tbl-cell a { color: inherit; text-decoration: underline;
  text-decoration-color: light-dark(rgba(55, 53, 47, .38), rgba(255, 255, 255, .36)); text-underline-offset: 2px;
  text-decoration-thickness: 1px; }
.blk-text a[data-page-id], .tbl-cell a[data-page-id] { font-weight: 500; text-decoration-color: var(--accent-soft); }
/* A link is part of the text: dragging it would move a URL, not the words. */
.blk-text a, .tbl-cell a { -webkit-user-drag: none; }
.blk-text:not(.is-live) a, .tbl-cell:not(.is-live) a, .editor.is-readonly .blk-text a { cursor: pointer; }
.blk-text:not(.is-live) a:hover, .tbl-cell:not(.is-live) a:hover { text-decoration-color: currentColor; }

/* Headings: the space above them is what separates sections. */
.blk-heading_1 { margin-top: 1.4em; }
.blk-heading_2 { margin-top: 1.05em; }
.blk-heading_3 { margin-top: .75em; }
.editor-blocks > .blk:first-child { margin-top: 0; }
.blk-heading_1 > .blk-row > .blk-text { font-size: 1.875em; font-weight: 700; line-height: 1.3; letter-spacing: -.005em; }
.blk-heading_2 > .blk-row > .blk-text { font-size: 1.5em; font-weight: 650; line-height: 1.3; }
.blk-heading_3 > .blk-row > .blk-text { font-size: 1.25em; font-weight: 600; line-height: 1.3; }

/* --- lists ---------------------------------------------------------------------------- */
.blk-marker { flex: 0 0 1.5em; display: flex; justify-content: center; align-self: flex-start;
  min-height: calc(1.5em + 6px); user-select: none; -webkit-user-select: none; }
/* Bullets by depth: disc, circle, square. */
.blk-bulleted_list > .blk-row > .blk-marker::before { content: ""; width: 6px; height: 6px; margin-top: calc(3px + .75em - 3px);
  border-radius: 50%; background: currentColor; }
.blk-bulleted_list[data-ld="1"] > .blk-row > .blk-marker::before { background: transparent; border: 1.5px solid currentColor; width: 6px; height: 6px; }
.blk-bulleted_list[data-ld="2"] > .blk-row > .blk-marker::before { border-radius: 1px; width: 5.5px; height: 5.5px; }
/* Numbers from consecutive siblings, styled by depth: 1. a. i. CSS counters,
   reset by every list container (so a nested list counts on its own and the
   outer one carries on after it) and by any other block (so a run restarts
   after a paragraph). */
.editor-blocks, .blk-children { counter-reset: blk-num; }
.blk:not(.blk-numbered_list) { counter-reset: blk-num; }
.blk-numbered_list { counter-increment: blk-num; }
.blk-numbered_list > .blk-row > .blk-marker::before { content: counter(blk-num) "."; padding-top: 3px; line-height: 1.5;
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.blk-numbered_list[data-ld="1"] > .blk-row > .blk-marker::before { content: counter(blk-num, lower-alpha) "."; }
.blk-numbered_list[data-ld="2"] > .blk-row > .blk-marker::before { content: counter(blk-num, lower-roman) "."; }

/* To-do */
.blk-check { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px;
  margin-top: calc(3px + .75em - 8px); border: 1.5px solid currentColor; border-radius: 3px; cursor: pointer;
  color: var(--text); background: var(--bg); transition: background .1s ease; }
.blk-check .icon { opacity: 0; color: #fff; }
.blk-check:hover { background: var(--hover-tint); }
.blk-to_do.is-checked > .blk-row .blk-check { background: var(--accent); border-color: var(--accent); }
.blk-to_do.is-checked > .blk-row .blk-check .icon { opacity: 1; }
.blk-to_do.is-checked > .blk-row > .blk-text { color: var(--text-muted); text-decoration: line-through;
  text-decoration-color: var(--text-faint); }
.editor.is-readonly .blk-check { cursor: default; }

/* Toggle */
.toggle-btn { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  margin-top: calc(3px + .75em - 11px); border-radius: 4px; cursor: pointer; color: var(--text); }
.toggle-btn:hover { background: var(--hover-tint); }
.toggle-btn .icon { transition: transform .15s ease; }
.blk-toggle.is-open > .blk-row .toggle-btn .icon { transform: rotate(90deg); }
.blk-toggle.is-collapsed > .blk-children, .blk-toggle.is-collapsed > .toggle-empty { display: none; }
.toggle-empty { display: none; padding: 3px 2px 3px calc(1.5em + 2px); color: var(--text-faint); cursor: text; user-select: none; }
.toggle-empty:hover { color: var(--text-muted); }
.blk-toggle.is-open > .blk-children:empty + .toggle-empty { display: block; }

/* Quote and callout: their children sit inside the bar and the box. */
.quote-box { flex: 1; min-width: 0; margin: 4px 0; padding-left: 14px; border-left: 3px solid currentColor; }
.quote-box > .blk-text { font-size: 1.12em; }
.quote-box > .blk-children, .callout-body > .blk-children { padding-left: 0; }
.callout-box { flex: 1; min-width: 0; display: flex; gap: 6px; margin: 4px 0; padding: 12px 16px 12px 12px;
  border-radius: 4px; background: var(--ed-gray-bg); }
.callout-icon { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px;
  margin-top: calc(3px + .75em - 13px); border-radius: 4px; font-size: 1.15em; line-height: 1; cursor: pointer; user-select: none; }
.editor:not(.is-readonly) .callout-icon:hover { background: var(--hover-tint); }
.callout-body { flex: 1; min-width: 0; }

/* Divider */
.blk-divider > .blk-row { padding: 11px 2px; }
.blk-hr { flex: 1; margin: 0; border: 0; border-top: 1px solid var(--border-strong); }

/* A block kind this client does not know yet. */
.blk-unknown { gap: 8px; padding: 3px 2px; color: var(--text-muted); }
.blk-unknown-tag { font-family: var(--ed-mono); font-size: .75em; padding: .1em .4em; border-radius: 4px; background: var(--hover-tint); }

/* --- colours ------------------------------------------------------------------------- */
.blk.c-gray > .blk-row { color: var(--ed-gray); }
.blk.c-brown > .blk-row { color: var(--ed-brown); }
.blk.c-orange > .blk-row { color: var(--ed-orange); }
.blk.c-yellow > .blk-row { color: var(--ed-yellow); }
.blk.c-green > .blk-row { color: var(--ed-green); }
.blk.c-blue > .blk-row { color: var(--ed-blue); }
.blk.c-purple > .blk-row { color: var(--ed-purple); }
.blk.c-pink > .blk-row { color: var(--ed-pink); }
.blk.c-red > .blk-row { color: var(--ed-red); }
.blk.bg-gray > .blk-row { background: var(--ed-gray-bg); }
.blk.bg-brown > .blk-row { background: var(--ed-brown-bg); }
.blk.bg-orange > .blk-row { background: var(--ed-orange-bg); }
.blk.bg-yellow > .blk-row { background: var(--ed-yellow-bg); }
.blk.bg-green > .blk-row { background: var(--ed-green-bg); }
.blk.bg-blue > .blk-row { background: var(--ed-blue-bg); }
.blk.bg-purple > .blk-row { background: var(--ed-purple-bg); }
.blk.bg-pink > .blk-row { background: var(--ed-pink-bg); }
.blk.bg-red > .blk-row { background: var(--ed-red-bg); }
/* A callout's colour is its box. */
.blk-callout[class*=" bg-"] > .blk-row { background: none; }
.blk-callout.bg-brown .callout-box { background: var(--ed-brown-bg); }
.blk-callout.bg-orange .callout-box { background: var(--ed-orange-bg); }
.blk-callout.bg-yellow .callout-box { background: var(--ed-yellow-bg); }
.blk-callout.bg-green .callout-box { background: var(--ed-green-bg); }
.blk-callout.bg-blue .callout-box { background: var(--ed-blue-bg); }
.blk-callout.bg-purple .callout-box { background: var(--ed-purple-bg); }
.blk-callout.bg-pink .callout-box { background: var(--ed-pink-bg); }
.blk-callout.bg-red .callout-box { background: var(--ed-red-bg); }
.blk-callout[class*=" c-"] .callout-box { background: transparent; border: 1px solid var(--border-strong); }

.color-swatch { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px;
  border: 1px solid var(--border); border-radius: 4px; font-size: 12px; font-weight: 600; line-height: 1; color: var(--text); }
.color-swatch.c-gray { color: var(--ed-gray); } .color-swatch.c-brown { color: var(--ed-brown); }
.color-swatch.c-orange { color: var(--ed-orange); } .color-swatch.c-yellow { color: var(--ed-yellow); }
.color-swatch.c-green { color: var(--ed-green); } .color-swatch.c-blue { color: var(--ed-blue); }
.color-swatch.c-purple { color: var(--ed-purple); } .color-swatch.c-pink { color: var(--ed-pink); }
.color-swatch.c-red { color: var(--ed-red); }
.color-swatch.bg-gray { background: var(--ed-gray-bg); } .color-swatch.bg-brown { background: var(--ed-brown-bg); }
.color-swatch.bg-orange { background: var(--ed-orange-bg); } .color-swatch.bg-yellow { background: var(--ed-yellow-bg); }
.color-swatch.bg-green { background: var(--ed-green-bg); } .color-swatch.bg-blue { background: var(--ed-blue-bg); }
.color-swatch.bg-purple { background: var(--ed-purple-bg); } .color-swatch.bg-pink { background: var(--ed-pink-bg); }
.color-swatch.bg-red { background: var(--ed-red-bg); }

/* --- code -------------------------------------------------------------------------------- */
.code-wrap { flex: 1; min-width: 0; position: relative; flex-direction: column; align-items: stretch; margin: 4px 0;
  border-radius: 4px; background: var(--ed-code-bg); }
.code-head { display: flex; align-items: center; gap: 4px; height: 30px; padding: 4px 6px 0 8px; }
.code-spacer { flex: 1; }
.code-lang, .code-copy { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 6px; border: 0;
  border-radius: 4px; background: none; color: var(--text-muted); font-family: var(--font); font-size: 12px; line-height: 1; }
.code-lang:hover, .code-copy:hover { background: var(--hover-tint); color: var(--text); }
.code-copy { opacity: 0; transition: opacity .12s ease; }
.blk-code:hover .code-copy, .code-copy:focus-visible { opacity: 1; }
.code-body { overflow-x: auto; padding: 2px 16px 16px; }
.code-src { font-family: var(--ed-mono); font-size: .85em; line-height: 1.6; white-space: pre; word-break: normal;
  overflow-wrap: normal; tab-size: 2; padding: 0; min-height: 1.6em; width: max-content; min-width: 100%; }
.code-src:empty::before { top: 0; left: 0; white-space: pre; }

/* Syntax highlighting (app.highlight.js, highlight.js class names). GitHub's
   palette, light and dark, the same one the published sites use
   (app/templates/sites/_blocks.css), so code looks alike in both places. */
.code-src {
  --hl-keyword: light-dark(#cf222e, #ff7b72);
  --hl-title: light-dark(#8250df, #d2a8ff);
  --hl-literal: light-dark(#0550ae, #79c0ff);
  --hl-string: light-dark(#0a3069, #a5d6ff);
  --hl-builtin: light-dark(#953800, #ffa657);
  --hl-comment: light-dark(#6e7781, #8b949e);
  --hl-tag: light-dark(#116329, #7ee787);
  --hl-bullet: light-dark(#7d4e00, #f2cc60);
  --hl-add: light-dark(#dafbe1, #033a16);
  --hl-add-ink: light-dark(#116329, #aff5b4);
  --hl-del: light-dark(#ffebe9, #67060c);
  --hl-del-ink: light-dark(#82071e, #ffdcd7);
}
.code-src .hljs-doctag, .code-src .hljs-keyword, .code-src .hljs-meta .hljs-keyword, .code-src .hljs-template-tag,
.code-src .hljs-template-variable, .code-src .hljs-type, .code-src .hljs-variable.language_ { color: var(--hl-keyword); }
.code-src .hljs-title, .code-src .hljs-title.class_, .code-src .hljs-title.class_.inherited__,
.code-src .hljs-title.function_ { color: var(--hl-title); }
.code-src .hljs-attr, .code-src .hljs-attribute, .code-src .hljs-literal, .code-src .hljs-meta, .code-src .hljs-number,
.code-src .hljs-operator, .code-src .hljs-selector-attr, .code-src .hljs-selector-class, .code-src .hljs-selector-id,
.code-src .hljs-variable { color: var(--hl-literal); }
.code-src .hljs-meta .hljs-string, .code-src .hljs-regexp, .code-src .hljs-string { color: var(--hl-string); }
.code-src .hljs-built_in, .code-src .hljs-symbol { color: var(--hl-builtin); }
.code-src .hljs-code, .code-src .hljs-comment, .code-src .hljs-formula { color: var(--hl-comment); font-style: italic; }
.code-src .hljs-name, .code-src .hljs-quote, .code-src .hljs-selector-pseudo, .code-src .hljs-selector-tag { color: var(--hl-tag); }
.code-src .hljs-section { color: var(--hl-literal); font-weight: 600; }
.code-src .hljs-bullet { color: var(--hl-bullet); }
.code-src .hljs-emphasis { font-style: italic; }
.code-src .hljs-strong { font-weight: 600; }
.code-src .hljs-addition { color: var(--hl-add-ink); background: var(--hl-add); }
.code-src .hljs-deletion { color: var(--hl-del-ink); background: var(--hl-del); }

.mermaid-view { display: flex; justify-content: center; overflow-x: auto; padding: 4px 16px 16px; }
.mermaid-view svg { max-width: 100%; height: auto; }
.editor:not(.is-readonly) .mermaid-view { cursor: pointer; }
.blk-code.is-mermaid.has-view:not(.is-editing) .code-body { display: none; }
.blk-code.is-mermaid.is-editing .mermaid-view { border-top: 1px dashed var(--border-strong); padding-top: 12px; }
.mermaid-error { color: var(--danger-text); font-size: 12px; font-family: var(--font); }

/* --- equation -------------------------------------------------------------------------- */
.eq-wrap { flex: 1; min-width: 0; flex-direction: column; align-items: stretch; margin: 4px 0; }
.eq-view { min-height: 2.4em; padding: 6px 4px; border-radius: 4px; text-align: center; overflow-x: auto; }
.editor:not(.is-readonly) .eq-view { cursor: pointer; }
.editor:not(.is-readonly) .eq-view:hover { background: var(--hover-tint-soft); }
.eq-empty { display: inline-block; padding: 4px 0; color: var(--text-faint); }
.eq-source { font-family: var(--ed-mono); font-size: .9em; white-space: pre-wrap; }
.eq-edit { display: none; margin: 2px 0 6px; padding: 8px; border-radius: 6px; background: var(--popover, var(--bg));
  box-shadow: var(--shadow); }
.blk-equation.is-editing .eq-edit { display: block; }
.eq-src { font-family: var(--ed-mono); font-size: .85em; line-height: 1.6; padding: 6px 8px; border-radius: 4px; background: var(--bg-elev); }
.eq-hint { margin-top: 6px; color: var(--text-faint); font-size: 12px; font-family: var(--font); }

/* --- media -------------------------------------------------------------------------------- */
.media-row { flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column; margin: 6px 0; }
.blk-caption { flex: none; align-self: stretch; min-height: 0; padding: 6px 2px 2px; font-size: .875em; color: var(--text-muted); }
.blk-caption:empty { display: none; }
.blk.is-captioning .blk-caption:empty { display: block; min-height: calc(1.5em + 8px); }

.img-col { align-self: center; display: flex; flex-direction: column; max-width: 100%; }
/* width 0 + min-width 100%: the caption fills the picture's width without
   ever widening it. */
.img-col > .blk-caption { width: 0; min-width: 100%; }
.img-frame { position: relative; max-width: 100%; }
.img { display: block; max-width: 100%; height: auto; border-radius: 3px; cursor: zoom-in; }
.img-frame[style*="width"] .img { width: 100%; }
.img-broken { display: none; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  min-height: 120px; min-width: 240px; padding: 1rem; border-radius: 4px; background: var(--hover-tint-soft);
  color: var(--text-muted); font-size: .875em; text-align: center; }
.img-frame.is-broken .img { display: none; }
.img-frame.is-broken .img-broken { display: flex; }
.img-handle { position: absolute; top: 0; bottom: 0; width: 16px; display: flex; align-items: center; justify-content: center;
  cursor: ew-resize; opacity: 0; transition: opacity .15s ease; touch-action: none; }
.img-handle::after { content: ""; width: 6px; height: 46px; max-height: 50%; border-radius: 4px;
  background: rgba(15, 15, 15, .6); border: 1px solid rgba(255, 255, 255, .9); }
.img-handle-left { left: 2px; }
.img-handle-right { right: 2px; }
.img-frame:hover .img-handle, .img-frame.is-resizing .img-handle { opacity: 1; }

.media-tools { position: absolute; top: 6px; right: 6px; z-index: 2; display: flex; gap: 1px; padding: 2px; border-radius: 5px;
  background: var(--popover, var(--bg)); box-shadow: var(--shadow); opacity: 0; transition: opacity .12s ease; }
.blk:hover > .blk-row .media-tools, .media-tools:focus-within, .blk.is-selected > .blk-row .media-tools { opacity: 1; }
.media-tool { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 24px; border: 0;
  border-radius: 4px; background: none; color: var(--text-muted); }
.media-tool:hover { background: var(--hover-tint); color: var(--text); }

.media-empty { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 10px; padding: 12px 14px; border-radius: 4px;
  background: var(--hover-tint-soft); color: var(--text-muted); font-size: .875em; transition: background .12s ease; }
.media-empty-icon { display: inline-flex; color: var(--text-faint); }
.media-empty-actions { display: inline-flex; gap: 6px; margin-left: auto; }
.media-empty-hint { flex-basis: 100%; color: var(--text-faint); font-size: .85em; }
.media-empty .url-form { flex: 1 1 260px; }
.media-empty-form { flex-wrap: nowrap; }
.blk.is-drop-target .media-empty { background: var(--accent-weak); outline: 2px dashed var(--accent-soft); outline-offset: -2px; }
.blk.is-uploading .media-empty { display: none; }
.url-form { display: flex; gap: 6px; align-items: center; min-width: 0; }
.url-input { flex: 1; min-width: 0; height: 30px; }
.url-input.is-invalid { border-color: var(--danger); }

.file-card { position: relative; display: flex; align-items: center; gap: 6px; min-height: 40px; padding: 4px 6px 4px 8px;
  border: 1px solid var(--border); border-radius: 4px; }
.file-card:hover { background: var(--hover-tint-soft); }
.file-main { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.file-icon { display: inline-flex; color: var(--text-muted); }
.file-meta { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.file-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { flex: none; color: var(--text-faint); font-size: .8em; white-space: nowrap; }
.file-actions { display: flex; align-items: center; gap: 2px; }
.file-btn { display: inline-flex; align-items: center; height: 26px; padding: 0 8px; border: 0; border-radius: 4px;
  background: none; color: var(--text-muted); font-size: .8em; text-decoration: none; }
.file-btn:hover { background: var(--hover-tint); color: var(--text); }
.blk.is-converting .convert-webp, .blk.is-converting .media-tools { pointer-events: none; opacity: .55; }
.pdf-frame { display: block; width: 100%; height: min(720px, 80vh); margin-top: 6px; border: 1px solid var(--border);
  border-radius: 4px; background: #fff; }

.bookmark-card { display: flex; align-self: stretch; min-width: 0; border: 1px solid var(--border); border-radius: 4px; color: inherit;
  text-decoration: none; overflow: hidden; }
.bookmark-card:hover { background: var(--hover-tint-soft); }
.bm-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; padding: 12px 14px 13px; }
.bm-title { font-size: .875em; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bm-desc { font-size: .75em; color: var(--text-muted); line-height: 1.45; max-height: 2.9em; overflow: hidden; }
.bm-url { display: flex; align-items: center; gap: 6px; font-size: .75em; color: var(--text); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bm-url .icon { flex: none; color: var(--text-muted); }

.embed-frame { position: relative; width: 100%; overflow: hidden; border-radius: 4px; background: var(--bg-elev); }
.embed-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Page links and inline databases. (.page-icon is the page header's.) */
.page-card { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; padding: 3px 2px; border-radius: 4px;
  color: inherit; text-decoration: none; font-weight: 500; line-height: 1.5; }
.page-card:hover { background: var(--hover-tint); }
.pl-icon { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  font-size: 1.05em; line-height: 1; color: var(--text-muted); }
.pl-icon img { width: 20px; height: 20px; object-fit: cover; border-radius: 3px; }
.pl-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-bottom: 1px solid var(--border-strong); line-height: 1.3; }
.page-card.is-deleted { color: var(--text-faint); }
.page-card.is-deleted .pl-title { border-bottom: 0; text-decoration: line-through; }
.db-host { display: block; flex: 1; min-width: 0; margin: 6px 0; }

/* --- tables --------------------------------------------------------------------------------- */
.table-row { flex: 1; min-width: 0; display: flex; flex-direction: column; margin: 6px 0; }
.tbl-wrap { display: flex; align-items: stretch; gap: 4px; overflow-x: auto; padding-bottom: 2px; }
.tbl { flex: none; border-collapse: collapse; font-size: .95em; }
.tbl td, .tbl th { min-width: 120px; padding: 0; border: 1px solid var(--border-strong); vertical-align: top;
  text-align: left; font-weight: inherit; }
.tbl th { background: var(--hover-tint-soft); font-weight: 600; }
.tbl-cell { min-height: 1.5em; padding: 6px 9px; white-space: pre-wrap; word-break: break-word; outline: none;
  caret-color: var(--text); }
.tbl td:focus-within, .tbl th:focus-within { box-shadow: inset 0 0 0 1.5px var(--accent-soft); }
.tbl-add { flex: none; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 4px;
  background: var(--hover-tint-soft); color: var(--text-faint); opacity: 0; transition: opacity .12s ease; }
.tbl-add:hover { background: var(--hover-tint); color: var(--text-muted); }
.tbl-add-col { width: 18px; }
.tbl-add-row { height: 18px; margin-top: 3px; }
.blk-table:hover .tbl-add, .blk-table:focus-within .tbl-add { opacity: 1; }
.tbl-tools { position: absolute; right: 0; top: -32px; z-index: 3; display: none; gap: 2px; padding: 3px; border-radius: 6px;
  background: var(--popover, var(--bg)); box-shadow: var(--shadow); }
.blk-table:focus-within .tbl-tools { display: flex; }
.tbl-tool { height: 24px; padding: 0 8px; border: 0; border-radius: 4px; background: none; color: var(--text-muted);
  font-family: var(--font); font-size: 12px; white-space: nowrap; }
.tbl-tool:hover { background: var(--hover-tint); color: var(--text); }
.tbl-tool[aria-pressed="true"] { color: var(--accent); background: var(--accent-weak); }

/* --- grids ---------------------------------------------------------------------------------- */
/* The cells are the grid's children, laid out by CSS in --grid-cols columns,
   row by row (app.editor.grid.js). The column gap is the gutter's width, so a
   block in the second column has its handle beside it, not over the first.
   A cell stretches to its row's height: the space below a short cell's
   blocks is there to click into, or drop onto. */
.grid-frame { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: stretch; margin: 4px 0; }
.blk-grid[class*=" bg-"] > .grid-frame { padding: 12px 14px; }
.grid-main { display: flex; align-items: stretch; gap: 4px; min-width: 0; }
.grid-body { flex: 1; min-width: 0; }
.grid-body > .blk-children { display: grid; grid-template-columns: repeat(var(--grid-cols, 2), minmax(0, 1fr));
  gap: 10px 46px; padding-left: 0; }
.blk-grid_cell { display: flex; flex-direction: column; min-width: 0; margin: 0; }
.blk-grid_cell > .cell-frame { flex: 1; flex-direction: column; align-items: stretch; }
.cell-frame > .blk-children { flex: 1; padding-left: 0; }
.cell-frame > .blk-children:empty { min-height: 2.75em; }
.editor:not(.is-readonly) .cell-frame > .blk-children:empty { display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--border-strong); border-radius: 4px; color: var(--text-faint); font-size: .85em; cursor: text; }
.editor:not(.is-readonly) .cell-frame > .blk-children:empty::before { content: "Click to write, or drop a block here";
  padding: 4px 8px; text-align: center; }
.editor:not(.is-readonly) .blk-grid:hover > .grid-frame > .grid-main > .grid-body > .blk-children > .blk-grid_cell > .cell-frame {
  outline: 1px dashed var(--border); outline-offset: 3px; }
.cell-menu-btn { position: absolute; top: -10px; right: -12px; z-index: 4; display: inline-flex; align-items: center;
  justify-content: center; width: 24px; height: 20px; padding: 0; border: 0; border-radius: 5px;
  background: var(--popover, var(--bg)); box-shadow: var(--shadow); color: var(--text-muted);
  opacity: 0; pointer-events: none; transition: opacity .12s ease; }
.blk-grid_cell:hover > .cell-frame > .cell-menu-btn, .cell-menu-btn:focus-visible { opacity: 1; pointer-events: auto; }
.cell-menu-btn:hover { color: var(--text); }
.grid-add { flex: none; display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 0;
  border-radius: 4px; background: var(--hover-tint-soft); color: var(--text-faint); opacity: 0; transition: opacity .12s ease; }
.grid-add:hover { background: var(--hover-tint); color: var(--text-muted); }
.grid-add-col { width: 18px; }
.grid-add-row { height: 18px; margin-top: 6px; }
.blk-grid:hover > .grid-frame > .grid-main > .grid-add-col, .blk-grid:hover > .grid-frame > .grid-add-row { opacity: 1; }
.blk-grid.is-full > .grid-frame > .grid-main > .grid-add-col { visibility: hidden; }
/* A grid's row holds all of its cells, so hovering it is not hovering the
   pictures in them: an image's tools show for that image only. */
.blk-grid:hover > .blk-row .media-tools, .blk-grid.is-selected > .blk-row .media-tools { opacity: 0; }
.blk-grid .blk:not(.blk-grid):not(.blk-grid_cell):hover > .blk-row .media-tools,
.blk-grid .blk.is-selected > .blk-row .media-tools, .blk-grid .blk .media-tools:focus-within { opacity: 1; }

/* --- uploads -------------------------------------------------------------------------------- */
.blk-uploading { display: flex; align-items: center; gap: 10px; margin: 4px 0; padding: 9px 12px; border-radius: 4px;
  background: var(--hover-tint-soft); color: var(--text-muted); font-size: .875em; }
.up-icon { display: inline-flex; color: var(--text-faint); }
.up-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-bar { position: relative; flex: 0 0 120px; height: 4px; border-radius: 2px; background: var(--hover-tint-strong); overflow: hidden; }
.up-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 3%; background: var(--accent); transition: width .2s ease; }
.blk-uploading.is-indeterminate .up-fill { width: 30%; animation: ed-slide 1.1s ease-in-out infinite; }
@keyframes ed-slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

/* --- selection, focus, dragging ------------------------------------------------------------- */
.blk.is-selected::after { content: ""; position: absolute; inset: 0 -3px; z-index: 1; border-radius: 4px;
  background: var(--ed-select); pointer-events: none; }
.blk.is-selected .blk.is-selected::after { display: none; }
.blk.is-flash > .blk-row { animation: ed-flash 1.6s ease-out; }
@keyframes ed-flash { 0%, 35% { background: var(--ed-mark); } 100% { background: transparent; } }
.blk.is-dragging { opacity: .35; }
.editor-ghost { position: fixed; left: 0; top: 0; z-index: 400; max-height: 140px; overflow: hidden; padding: 2px 8px;
  border-radius: 4px; background: var(--bg); box-shadow: var(--shadow); opacity: .82; pointer-events: none; }
.ghost-count { position: absolute; top: 4px; right: 6px; min-width: 20px; padding: 1px 6px; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 600; text-align: center; }
body.editor-dragging, body.editor-dragging * { cursor: grabbing !important; user-select: none; }
.editor-drop { position: absolute; z-index: 6; height: 4px; border-radius: 2px; background: var(--accent-soft);
  opacity: .9; pointer-events: none; }
.editor-rubber { position: fixed; z-index: 150; border-radius: 2px; pointer-events: none;
  background: light-dark(rgba(35, 131, 226, .08), rgba(35, 131, 226, .16));
  border: 1px solid light-dark(rgba(35, 131, 226, .3), rgba(59, 130, 246, .45)); }

/* The gutter: "+" and the drag handle, beside the block under the pointer. */
.editor-gutter { position: absolute; z-index: 5; display: flex; align-items: center; height: 24px; gap: 2px;
  animation: ed-fade .12s ease; }
@keyframes ed-fade { from { opacity: 0; } to { opacity: 1; } }
.gutter-btn { display: inline-flex; align-items: center; justify-content: center; height: 24px; padding: 0; border: 0;
  border-radius: 4px; background: none; color: var(--text-faint); }
.gutter-btn:hover { background: var(--hover-tint); color: var(--text-muted); }
.gutter-plus { width: 24px; }
.gutter-handle { width: 18px; cursor: grab; }
.gutter-handle:active { cursor: grabbing; }

/* --- menus ------------------------------------------------------------------------------------ */
.slash-menu { width: min(330px, calc(100vw - 16px)); }
.slash-menu .menu-item { min-height: 46px; gap: .65rem; }
.slash-menu .menu-icon, .paste-menu .menu-icon { width: 40px; height: 40px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--bg); color: var(--text-muted); }
.slash-menu .menu-icon .icon { width: 20px; height: 20px; }
.paste-menu { width: min(300px, calc(100vw - 16px)); }
.paste-menu .menu-item { min-height: 44px; }
.popover-link { width: min(380px, calc(100vw - 16px)); }
.link-pop { display: flex; flex-direction: column; }
.link-input { margin: 8px 8px 2px; width: calc(100% - 16px); height: 32px; }
.link-results { max-height: 300px; }
.lang-menu { width: 220px; }
.block-menu { min-width: 240px; }

.editor-lightbox { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(0, 0, 0, .84); cursor: zoom-out; animation: ed-fade .15s ease; }
.editor-lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 3px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5); }

/* --- Markdown mode (meerail's composer) --------------------------------------------------------- */
.editor-md { position: relative; min-height: 50vh; padding: 3px 2px; outline: none; white-space: pre-wrap;
  overflow-wrap: anywhere; caret-color: var(--text); cursor: text; }
.editor-md.is-empty::before { content: attr(data-placeholder); position: absolute; color: var(--text-faint); pointer-events: none; }
.editor-md .md-line { min-height: 1.5em; }
.editor-md .md-mark { opacity: .7; }
.editor-md .md-line.md-h { font-weight: 700; line-height: 1.35; }
.editor-md .md-line.md-h1 { font-size: 1.6em; margin-top: .4em; }
.editor-md .md-line.md-h2 { font-size: 1.32em; margin-top: .3em; }
.editor-md .md-line.md-h3 { font-size: 1.12em; }
.editor-md .md-line.md-quote { color: var(--text-muted); }
.editor-md .md-line.md-hr, .editor-md .md-line.md-tagline { color: var(--text-faint); }
.editor-md .md-line.md-summary { font-weight: 600; }
.editor-md .md-line.md-fence, .editor-md .md-line.md-in-code, .editor-md .md-line.md-table {
  font-family: var(--ed-mono); font-size: .86em; }
.editor-md .md-line.md-in-code { background: var(--ed-code-bg); }
.editor-md .md-task.md-done { color: var(--text-muted); }
.editor-md .md-link { color: var(--accent); text-decoration: underline; }
.editor-md .md-code { font-family: var(--ed-mono); font-size: .85em; color: var(--ed-inline-code);
  background: var(--ed-inline-code-bg); border-radius: 4px; padding: .08em .3em; }
.editor-md strong { font-weight: 600; }
.editor-md mark { background: var(--ed-mark); color: inherit; }

/* --- narrow screens ----------------------------------------------------------------------------- */
/* No hover to find the gutter by: the handle follows the block being edited,
   in the page's side padding, and "+" is the slash menu's job. */
@media (max-width: 700px) {
  .editor-title { font-size: 1.6em; }
  .editor-gutter { display: none; }
  .editor-gutter.is-touch { display: flex; }
  .editor-gutter.is-touch .gutter-plus { display: none; }
  .blk-heading_1 > .blk-row > .blk-text { font-size: 1.6em; }
  .blk-heading_2 > .blk-row > .blk-text { font-size: 1.35em; }
  .tbl td, .tbl th { min-width: 90px; }
  .code-copy { opacity: 1; }
  .tbl-tools { top: auto; bottom: -34px; }
}
/* A phone's column is too narrow for cells side by side: they stack, in order. */
@media (max-width: 560px) {
  .grid-body > .blk-children { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .editor-gutter, .editor-lightbox, .blk.is-flash > .blk-row { animation: none; }
  .toggle-btn .icon { transition: none; }
}
