/* ==========================================================================
   Editor.js blocks + rendered post content
   --------------------------------------------------------------------------
   The project shipped the Editor.js *scripts* (assets/vendor/editorjs/, all
   UMD builds) but never the CSS — so both the editor and every published
   post rendered tables without borders, code without a monospace font and
   ASCII diagrams with broken alignment.

   This file covers both surfaces:
     • editor view  — .ce-block, .cdx-block, .tc-table, .ce-code__textarea …
     • published    — .post-content pre / code / table / blockquote / figure

   Colours come from the app theme tokens (themes.css), so dark and light
   both work without a second rule set.
   ========================================================================== */

/* ── shared tokens ───────────────────────────────────────────────────────── */
.post-content,
.codex-editor {
  --pc-mono: ui-monospace, "SFMono-Regular", "SF Mono", "Cascadia Mono",
             "JetBrains Mono", Consolas, "Liberation Mono", Menlo, monospace;
  /* themes.css has no --tw-surface: referencing it made the whole colour-mix
     invalid (IACVT) and every code block rendered on a transparent ground. */
  --pc-code-bg: color-mix(in srgb, var(--tw-text) 7%, var(--tw-bg-2, var(--tw-bg, #101216)));
  --pc-inline-bg: color-mix(in srgb, var(--tw-text) 10%, transparent);
  --pc-row-bg: color-mix(in srgb, var(--tw-text) 4%, transparent);
  /* muted/links pulled towards the body text so AA holds in every theme
     (the 'soft' palette's muted is only ~3.3:1 on its own background) */
  --pc-muted: color-mix(in srgb, var(--tw-muted) 55%, var(--tw-text));
  --pc-link: color-mix(in srgb, var(--tw-link) 85%, var(--tw-text));
  /* one hue per token family, pulled toward the body text so the palette
     keeps AA contrast on the dark, light and soft themes */
  --pc-str: color-mix(in srgb, #2ea043 62%, var(--tw-text));
  --pc-num: color-mix(in srgb, #d29922 70%, var(--tw-text));
  --pc-fn: color-mix(in srgb, #4493f8 68%, var(--tw-text));
}

/* ==========================================================================
   PUBLISHED POSTS
   ========================================================================== */

.post-content {
  font-size: 1.0625rem;
  line-height: 1.75;
  overflow-wrap: break-word;
  color: var(--tw-text);
}

.post-content > * + * { margin-top: 1.15rem; }

.post-content h1,
.post-content h2,
.post-content h3,
.post-content h4 {
  color: var(--tw-heading);
  line-height: 1.25;
  font-weight: 700;
  scroll-margin-top: 5rem;
}

.post-content h1 { font-size: 1.9rem; margin-top: 2.4rem; }
.post-content h2 { font-size: 1.5rem; margin-top: 2.2rem; }
.post-content h3 { font-size: 1.22rem; margin-top: 1.9rem; }
.post-content h4 { font-size: 1.06rem; margin-top: 1.6rem; }

.post-content a {
  color: var(--pc-link);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.post-content a:hover { color: var(--tw-accent-hover); }

.post-content ul,
.post-content ol { padding-left: 1.5rem; }
.post-content li + li { margin-top: 0.35rem; }
.post-content li > ul,
.post-content li > ol { margin-top: 0.35rem; }

.post-content strong { font-weight: 700; }

.post-content hr {
  border: 0;
  border-top: 1px solid var(--tw-border);
  margin: 2rem 0;
}

/* ── code ────────────────────────────────────────────────────────────────── */
.post-content pre {
  font-family: var(--pc-mono);
  font-size: 0.875rem;
  line-height: 1.45;
  /* Explicit: Bootstrap ships `pre{color:#212529}`, which on any dark surface
     (or in dark theme) renders the article's own diagrams invisible. */
  color: var(--tw-text);
  background: var(--pc-code-bg);
  border: 1px solid var(--tw-border);
  border-left: 3px solid var(--tw-accent);
  border-radius: 0.5rem;
  padding: 0.9rem 1rem;
  margin: 1.6rem 0;
  overflow-x: auto;
  /* ASCII diagrams must not wrap — alignment is the whole point */
  white-space: pre;
  tab-size: 4;
  -webkit-overflow-scrolling: touch;
}

.post-content pre code {
  font-family: inherit;
  font-size: inherit;
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  white-space: inherit;
}

/* inline code (not inside a block) */
.post-content :not(pre) > code,
.post-content p code,
.post-content li code,
.post-content td code {
  font-family: var(--pc-mono);
  font-size: 0.9em;
  background: var(--pc-inline-bg);
  border: 1px solid var(--tw-border);
  border-radius: 0.25rem;
  padding: 0.1em 0.35em;
  white-space: nowrap;
  color: var(--tw-text);
}

/* ── syntax highlighting (pygments spans) ───────────────────────────────────
   The converter highlights code with pygments, whose bundled theme is
   monokai: light-on-dark. On the light theme's light code surface those
   colours disappear, so the palette below is derived from the theme tokens
   and stays readable in both themes. */
.post-content pre span { color: inherit; }

.post-content pre span.c,
.post-content pre span.c1,
.post-content pre span.cm,
.post-content pre span.cs,
.post-content pre span.cp { color: var(--pc-muted); font-style: italic; }

.post-content pre span.k,
.post-content pre span.kc,
.post-content pre span.kd,
.post-content pre span.kn,
.post-content pre span.kr,
.post-content pre span.kt,
.post-content pre span.kw { color: var(--tw-accent); font-weight: 600; }

.post-content pre span.s,
.post-content pre span.s1,
.post-content pre span.s2,
.post-content pre span.sb,
.post-content pre span.sc,
.post-content pre span.sd,
.post-content pre span.se,
.post-content pre span.sh,
.post-content pre span.si,
.post-content pre span.sx {
  /* a green pulled toward the body text: readable on dark, light and soft */
  color: var(--pc-str);
}

.post-content pre span.m,
.post-content pre span.mi,
.post-content pre span.mf,
.post-content pre span.mh,
.post-content pre span.mo,
.post-content pre span.il { color: var(--pc-num); }

.post-content pre span.nf,
.post-content pre span.fm,
.post-content pre span.nc,
.post-content pre span.nn { color: var(--tw-text); font-weight: 600; }

.post-content pre span.nt { color: var(--tw-accent); }
.post-content pre span.nb, .post-content pre span.bp { color: var(--pc-fn); }
.post-content pre span.o,
.post-content pre span.ow,
.post-content pre span.p { color: var(--tw-text); }
.post-content pre span.err { color: var(--tw-text); text-decoration: underline wavy; }

/* pygments wraps the block in <div class="highlight"> */
.post-content .highlight { margin: 1.6rem 0; }
.post-content .highlight > pre { margin: 0; }

/* ── tables ──────────────────────────────────────────────────────────────── */
.post-content .table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.6rem 0;
  border: 1px solid var(--tw-border);
  border-radius: 0.5rem;
}

.post-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.6rem 0;
  font-size: 0.95rem;
  color: var(--tw-text);
}

.post-content .table-wrap > table { margin: 0; min-width: 100%; }

.post-content th,
.post-content td {
  border: 1px solid var(--tw-border);
  padding: 0.55rem 0.75rem;
  text-align: left;
  vertical-align: top;
}

.post-content thead th {
  background: var(--pc-code-bg);
  font-weight: 600;
  white-space: nowrap;
}

.post-content tbody tr:nth-child(even) { background: var(--pc-row-bg); }

/* ── quotes / media ──────────────────────────────────────────────────────── */
.post-content blockquote {
  border-left: 3px solid var(--tw-accent);
  margin: 1.6rem 0;
  padding: 0.2rem 0 0.2rem 1.1rem;
  color: var(--pc-muted);
  font-style: italic;
}
.post-content blockquote cite {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.9em;
  font-style: normal;
}

.post-content figure { margin: 1.6rem 0; }
.post-content img,
.post-content iframe {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
}
.post-content figcaption {
  margin-top: 0.4rem;
  font-size: 0.875rem;
  color: var(--pc-muted);
}

/* ==========================================================================
   EDITOR VIEW  (Editor.js core + the tools shipped in vendor/editorjs)
   ========================================================================== */

.codex-editor {
  color: var(--tw-text);
  font-size: 1rem;
  line-height: 1.7;
}

.codex-editor .ce-block__content { max-width: 100%; }
.codex-editor .ce-block { padding: 0.15rem 0; }

.codex-editor .ce-paragraph { line-height: 1.7; }

.codex-editor .ce-header { color: var(--tw-heading); line-height: 1.3; }
.codex-editor h2.ce-header { font-size: 1.5rem; }
.codex-editor h3.ce-header { font-size: 1.25rem; }
.codex-editor h4.ce-header { font-size: 1.1rem; }

/* placeholder + inputs */
.codex-editor [data-placeholder]::before,
.codex-editor .ce-paragraph[data-placeholder]::before {
  color: var(--tw-muted);
  opacity: 0.7;
}
.codex-editor .cdx-input,
.codex-editor .ce-code__textarea {
  background: var(--tw-surface);
  color: var(--tw-text);
  border: 1px solid var(--tw-border);
  border-radius: 0.4rem;
  padding: 0.5rem 0.65rem;
  font-family: inherit;
  font-size: inherit;
  width: 100%;
}

/* code tool */
.codex-editor .ce-code__textarea {
  font-family: var(--pc-mono);
  font-size: 0.875rem;
  line-height: 1.45;
  min-height: 8rem;
  white-space: pre;
  tab-size: 4;
  background: var(--pc-code-bg);
}
.codex-editor .cdx-code { position: relative; }

/* table tool */
.codex-editor .tc-table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.5rem 0;
  font-size: 0.95rem;
}
.codex-editor .tc-table td,
.codex-editor .tc-table th {
  border: 1px solid var(--tw-border);
  padding: 0.5rem 0.65rem;
  min-width: 3rem;
  vertical-align: top;
}
.codex-editor .tc-table th,
.codex-editor .tc-table tr:first-child td {
  background: var(--pc-code-bg);
  font-weight: 600;
}
.codex-editor .tc-row--selected { background: var(--pc-row-bg); }
.codex-editor .tc-cell--selected { outline: 2px solid var(--tw-accent); }
.codex-editor .tc-toolbox,
.codex-editor .tc-add-row,
.codex-editor .tc-add-column {
  color: var(--tw-muted);
}

/* lists, checklists, quotes, markers */
.codex-editor .cdx-list { padding-left: 1.5rem; }
.codex-editor .cdx-list__item { line-height: 1.7; }
.codex-editor .cdx-checklist__item { line-height: 1.7; }
.codex-editor .cdx-checklist__item-checkbox { accent-color: var(--tw-accent); }

.codex-editor .cdx-quote {
  border-left: 3px solid var(--tw-accent);
  padding: 0.2rem 0 0.2rem 1rem;
  margin: 0.4rem 0;
}
.codex-editor .cdx-quote__text { font-style: italic; color: var(--pc-muted); }
.codex-editor .cdx-quote__caption { color: var(--tw-muted); font-size: 0.9rem; }

.codex-editor mark,
.post-content mark {
  background: color-mix(in srgb, var(--tw-accent) 35%, transparent);
  color: inherit;
  padding: 0 0.15em;
  border-radius: 0.15rem;
}

/* inline code from the inline-code tool */
.codex-editor code,
.post-content code {
  font-family: var(--pc-mono);
}
.codex-editor :not(pre) > code {
  background: var(--pc-inline-bg);
  border: 1px solid var(--tw-border);
  border-radius: 0.25rem;
  padding: 0.1em 0.35em;
  font-size: 0.9em;
}

/* images / embeds inside the editor */
.codex-editor .cdx-image,
.codex-editor .cdx-simple-image { border-radius: 0.5rem; overflow: hidden; }
.codex-editor .cdx-image img,
.codex-editor .cdx-simple-image img,
.codex-editor .cdx-embed iframe { max-width: 100%; height: auto; display: block; }
.codex-editor .cdx-image__caption,
.codex-editor .cdx-simple-image__caption { color: var(--tw-muted); font-size: 0.875rem; }
.codex-editor .image-tool__image { background: var(--tw-surface); }
.codex-editor .image-tool__caption,
.codex-editor .image-tool__image-picture { color: var(--tw-text); }

/* delimiter */
.codex-editor .ce-delimiter {
  border-top: 2px solid var(--tw-border);
  margin: 1.2rem 0;
  text-align: center;
}

/* toolbar + popovers (Editor.js UI) */
.codex-editor .ce-toolbar__plus,
.codex-editor .ce-toolbar__settings-btn {
  color: var(--tw-text);
  background: var(--tw-surface);
  border: 1px solid var(--tw-border);
  border-radius: 0.35rem;
}
.codex-editor .ce-toolbar__plus:hover,
.codex-editor .ce-toolbar__settings-btn:hover {
  background: var(--tw-accent);
  color: #fff;
}
.codex-editor .ce-popover,
.codex-editor .ce-inline-toolbar,
.codex-editor .ce-conversion-toolbar {
  background: var(--tw-surface);
  color: var(--tw-text);
  border: 1px solid var(--tw-border-strong);
  border-radius: 0.5rem;
  box-shadow: 0 8px 24px var(--tw-shadow);
}
.codex-editor .ce-popover-item:hover,
.codex-editor .ce-inline-tool:hover {
  background: var(--pc-row-bg);
}
.codex-editor .ce-popover-item__title,
.codex-editor .ce-inline-tool { color: var(--tw-text); }
.codex-editor .ce-popover__search,
.codex-editor .cdx-search-field {
  background: var(--tw-bg);
  color: var(--tw-text);
  border-color: var(--tw-border);
}
.codex-editor .ce-block--selected .ce-block__content {
  background: color-mix(in srgb, var(--tw-accent) 12%, transparent);
}

/* accessibility: visible focus everywhere in the editor and the article */
.codex-editor :focus-visible,
.post-content :focus-visible {
  outline: 2px solid var(--tw-accent);
  outline-offset: 2px;
}

/* small screens: keep wide content scrollable instead of breaking the layout */
@media (max-width: 640px) {
  .post-content pre { font-size: 0.8125rem; }
  .post-content table { font-size: 0.875rem; }
  .post-content .table-wrap { margin-left: -0.5rem; margin-right: -0.5rem; }
}


/* ── Mermaid diagrams ────────────────────────────────────────────────────── */
/* The stored markup is <div class="mermaid">graph TD; …</div>; mermaid.js
   replaces the text with an SVG in the browser. Before/without JS the raw
   definition must still be readable, so it gets the code-block treatment. */
.post-content .mermaid {
  margin: 1.6rem 0;
  padding: 1rem;
  background: var(--pc-code-bg);
  border: 1px solid var(--tw-border);
  border-left: 3px solid var(--tw-accent);
  border-radius: 0.5rem;
  overflow-x: auto;
  text-align: center;
  color: var(--tw-text);
}
.post-content .mermaid:not([data-processed]) {
  font-family: var(--pc-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre;
  text-align: left;
}
.post-content .mermaid svg {
  max-width: 100%;
  height: auto;
  background: transparent !important;
}
.post-content .mermaid svg text,
.post-content .mermaid svg tspan { fill: var(--tw-text); }
.post-content .mermaid svg .edgePath path,
.post-content .mermaid svg path.path { stroke: var(--tw-border-strong); }

/* ── article chrome ─────────────────────────────────────────────────────── */
/* The breadcrumb carries <a id="postID">UUID</a> because the post JS reads
   that UUID; it is not content, so keep it in the DOM but out of sight. */
#postID {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
