/*
 * How a Markdown document looks: headings, text, lists, quotes, code, tables, callouts and the rest.
 *
 * One file, two readers: MarkQ's preview and the Quick Look preview in Finder both use it. It is copied into
 * index.html and the Quick Look bundle by `node scripts/sync-preview-css.js`; edit this file, not the copies.
 *
 * It styles only what sits inside an element with the class "md-content". The size of the text (font-size),
 * the font and the line height are set by whoever hosts the document (MarkQ: 20px with the zoom; Quick Look: 16px),
 * so every size below is in em.
 *
 * Custom styles: MarkQ and Quick Look load ~/Library/Application Support/MarkQ/preview.css after this file.
 * Every rule here has the weight of a plain element selector (the :where() wrapper adds none), so a rule like
 * `.md-content h1 { color: red }` in that file always wins. The colours and the spacing that people change most
 * are variables: set them on `.md-content` (`.md-content { --md-link: #c00 }`). The names below are public:
 * do not rename one without keeping the old name working.
 */

:where(.md-content) {
  --md-text: light-dark(#24292e, #c9d1d9);
  --md-heading: light-dark(#24292e, #f0f6fc);
  --md-muted: light-dark(#57606a, #8b949e);
  --md-border: light-dark(#eaecef, #30363d);
  --md-link: light-dark(#0969da, #58a6ff);
  --md-accent: #388bfd;
  --md-code-bg: light-dark(#f6f8fa, #161b22);
  --md-code-border: light-dark(#e1e4e8, #30363d);
  --md-code-text: light-dark(#24292e, #e6edf3);
  --md-inline-code: light-dark(#d63384, #ff7b72);
  --md-box-bg: light-dark(#f6f8fa, #21262d);
  --md-token-keyword: light-dark(#d73a49, #ff7b72);
  --md-token-string: light-dark(#032f62, #79c0ff);
  --md-token-function: light-dark(#6f42c1, #d2a8ff);
  --md-token-comment: light-dark(#6a737d, #8b949e);
  --md-font-mono: "SF Mono", "Input Mono", Menlo, Monaco, Consolas, monospace;
  color: var(--md-text);
}

/* Text */
:where(.md-content) p { margin: 1em 0; }
:where(.md-content) h1, :where(.md-content) h2, :where(.md-content) h3,
:where(.md-content) h4, :where(.md-content) h5, :where(.md-content) h6 {
  color: var(--md-heading);
  font-weight: 600;
  line-height: 1.25;
  margin: 1.5em 0 0.5em;
}
:where(.md-content) h1 { font-size: 1.7em; padding-bottom: 0.3em; border-bottom: 1px solid var(--md-border); }
:where(.md-content) h2 { font-size: 1.4em; padding-bottom: 0.3em; border-bottom: 1px solid var(--md-border); }
:where(.md-content) h3 { font-size: 1.17em; }
:where(.md-content) h4 { font-size: 1em; }
:where(.md-content) h5 { font-size: 0.9em; }
:where(.md-content) h6 { font-size: 0.85em; color: var(--md-muted); }
:where(.md-content) a { color: var(--md-link); text-decoration: none; }
:where(.md-content) a:hover { text-decoration: underline; }
:where(.md-content) strong { font-weight: 700; }
:where(.md-content) hr { border: 0; border-top: 1px solid var(--md-border); margin: 1.5em 0; }
:where(.md-content) img { max-width: 100%; height: auto; }

/* Lists */
:where(.md-content) ul, :where(.md-content) ol { margin: 1em 0; padding-left: 1.8em; }
:where(.md-content) li ul, :where(.md-content) li ol { margin: 0; }
:where(.md-content) li { margin: 0.15em 0; }
:where(.md-content) li p { margin: 0.4em 0; }
:where(.md-content) .task-list-item {
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 0.4em;
  margin-left: -1.4em;
}
:where(.md-content) .task-list-item > span { min-width: 0; overflow-wrap: anywhere; }
/* The box is drawn here, not by the browser: Chromium (MarkQ) and WebKit (Quick Look) draw their own check boxes differently */
:where(.md-content) .task-checkbox {
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  font-size: inherit;
  width: 0.8em;
  height: 0.8em;
  margin: 0.15em 0 0;
  flex-shrink: 0;
  cursor: pointer;
  border: 1.5px solid var(--md-muted);
  border-radius: 3px;
  background: transparent no-repeat center / 100% 100%;
}
:where(.md-content) .task-checkbox:checked {
  border-color: var(--md-accent);
  background-color: var(--md-accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.6 8.4l2.8 2.8 6-6' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
:where(.md-content) .task-checkbox:focus-visible { outline: 2px solid var(--md-accent); outline-offset: 1px; }

/* Quotes and callouts */
:where(.md-content) blockquote {
  margin: 1em 0;
  padding: 0 1em;
  color: var(--md-muted);
  border-left: 0.25em solid var(--md-border);
}
:where(.md-content) blockquote > :first-child { margin-top: 0; }
:where(.md-content) blockquote > :last-child { margin-bottom: 0; }
:where(.md-content) blockquote.callout {
  --callout: #388bfd;
  margin: 1em 0;
  padding: 0.6em 1em 0.7em 1em;
  color: var(--md-text);
  border-left: 4px solid var(--callout);
  border-radius: 0 6px 6px 0;
  background: color-mix(in srgb, var(--callout) 11%, transparent);
}
:where(.md-content) blockquote.callout > :last-child { margin-bottom: 0; }
:where(.md-content) blockquote.callout .callout-title + * { margin-top: 0; }
:where(.md-content) blockquote.callout ul, :where(.md-content) blockquote.callout ol { padding-left: 1.4em; }
:where(.md-content) blockquote.callout .callout-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 0.2em 0;
  font-weight: 600;
  color: var(--callout);
}
:where(.md-content) blockquote.callout .callout-title svg { width: 16px; height: 16px; flex: none; }
:where(.md-content) blockquote.callout-note { --callout: #388bfd; }
:where(.md-content) blockquote.callout-tip { --callout: #2da44e; }
:where(.md-content) blockquote.callout-important { --callout: #a371f7; }
:where(.md-content) blockquote.callout-warning { --callout: #d29922; }
:where(.md-content) blockquote.callout-caution { --callout: #f85149; }

/* Tables */
:where(.md-content) table { width: 100%; margin: 1em 0; border-collapse: collapse; }
:where(.md-content) th { border: 1px solid var(--md-border); border-bottom: 2px solid var(--md-border); padding: 0.6em 1em; font-weight: bold; background-color: var(--md-code-bg); }
:where(.md-content) td { border: 1px solid var(--md-border); padding: 0.6em 1em; }

/* Code */
:where(.md-content) pre {
  margin: 1.5em 0;
  padding: 14px;
  color: var(--md-code-text);
  background: var(--md-code-bg);
  border: 1px solid var(--md-code-border);
  border-radius: 6px;
}
:where(.md-content) pre code {
  display: block;
  overflow-x: auto;
  color: var(--md-code-text);
  font-family: var(--md-font-mono);
  font-size: 1em;
  line-height: 1.5;
}
/* Inline code: any code that is not inside a code block (in a paragraph, a check-list item, a heading, a table cell, a link) */
:where(.md-content) :not(pre) > code {
  font-family: var(--md-font-mono);
  font-size: 0.9em;
  padding: 2px 4px;
  color: var(--md-inline-code);
  background: var(--md-code-bg);
  border: 1px solid var(--md-code-border);
  border-radius: 4px;
}
:where(.md-content) .token.keyword, :where(.md-content) .token.boolean, :where(.md-content) .token.selector,
:where(.md-content) .token.builtin, :where(.md-content) .token.command { color: var(--md-token-keyword); font-weight: bold; }
:where(.md-content) .token.tag, :where(.md-content) .token.doctype-tag, :where(.md-content) .token.name { color: var(--md-token-keyword); font-weight: 600; }
:where(.md-content) .token.string, :where(.md-content) .token.char, :where(.md-content) .token.attr-value,
:where(.md-content) .token.number, :where(.md-content) .token.triple-quoted-string,
:where(.md-content) .token.string-interpolation { color: var(--md-token-string); }
:where(.md-content) .token.function, :where(.md-content) .token.class-name, :where(.md-content) .token.property,
:where(.md-content) .token.class, :where(.md-content) .token.decorator, :where(.md-content) .token.attr-name { color: var(--md-token-function); }
:where(.md-content) .token.comment, :where(.md-content) .token.prolog, :where(.md-content) .token.doctype { color: var(--md-token-comment); font-style: italic; }
:where(.md-content) .token.operator, :where(.md-content) .token.punctuation { color: var(--md-text); }

/* Math, footnotes, links between files, front matter */
:where(.md-content) .math-block { margin: 1em 0; overflow-x: auto; overflow-y: hidden; }
:where(.md-content) .katex-display { display: block; margin: 0; }
:where(.md-content) math { font-size: 1.12em; }
:where(.md-content) .math-block math[display="block"] { font-size: 1.25em; }
:where(.md-content) code.math-error { color: #cf222e; }
:where(.md-content) sup.footnote-ref { font-size: 0.75em; line-height: 0; }
:where(.md-content) sup.footnote-ref a, :where(.md-content) a.footnote-backref { text-decoration: none; }
:where(.md-content) section.footnotes { font-size: 0.9em; margin-top: 2em; }
:where(.md-content) section.footnotes ol { padding-left: 1.6em; }
:where(.md-content) section.footnotes li { margin: 0.3em 0; }
:where(.md-content) a.wikilink.unresolved { opacity: 0.7; text-decoration: underline dashed; }
:where(.md-content) details.front-matter {
  margin: 0 0 1.4em 0;
  border: 1px solid var(--md-border);
  border-radius: 8px;
  background: var(--md-box-bg);
  font-size: 0.72em;
  line-height: 1.5;
}
:where(.md-content) details.front-matter > summary {
  cursor: pointer;
  padding: 7px 12px;
  font-weight: 600;
  color: var(--md-muted);
  list-style-position: inside;
  user-select: none;
}
:where(.md-content) details.front-matter > summary span {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 0.85em;
  font-weight: 600;
  border: 1px solid var(--md-border);
}
:where(.md-content) details.front-matter table.front-matter-table {
  width: 100%;
  margin: 0;
  border: none;
  border-top: 1px solid var(--md-border);
  border-collapse: collapse;
  display: table;
}
:where(.md-content) details.front-matter table.front-matter-table th,
:where(.md-content) details.front-matter table.front-matter-table td {
  padding: 4px 12px;
  border: none;
  background: transparent;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}
:where(.md-content) details.front-matter table.front-matter-table th { width: 28%; font-weight: 600; color: var(--md-muted); }
:where(.md-content) details.front-matter pre.front-matter-raw { margin: 0; padding: 8px 12px; border: none; border-top: 1px solid var(--md-border); background: transparent; border-radius: 0; }

/* The box around a drawn diagram */
:where(.md-content) .mermaid-container {
  margin: 1.5em 0;
  padding: 16px;
  background-color: var(--md-code-bg);
  border: 1px solid var(--md-code-border);
  border-radius: 6px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: auto;
}

/* A drawn diagram, and the message shown in its place when Mermaid cannot draw it */
:where(.md-content) .mermaid-chart { display: flex; justify-content: center; width: 100%; }
:where(.md-content) .mermaid-error {
  color: #ff7b72;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 12px;
  padding: 8px 12px;
  background: rgba(255, 123, 114, 0.1);
  border: 1px solid rgba(255, 123, 114, 0.3);
  border-radius: 4px;
  width: 100%;
}

/* An embedded file (![[file]]): a tinted block with the file's name above it */
:where(.md-content) .embed-block { margin: 1.2em 0; padding: 0 16px 4px; border: 1px solid var(--md-border, rgba(128, 128, 128, 0.3)); border-left: 4px solid var(--md-accent, #4a7bd0); border-radius: 6px; background: color-mix(in srgb, var(--md-accent, #4a7bd0) 6%, transparent); }
:where(.md-content) .embed-head { display: flex; align-items: center; gap: 8px; margin: 0 -16px 4px; padding: 6px 16px; border-bottom: 1px solid var(--md-border, rgba(128, 128, 128, 0.25)); font: 600 11px/1.4 -apple-system, BlinkMacSystemFont, sans-serif; letter-spacing: 0.02em; color: var(--md-muted, #6a737d); }
:where(.md-content) .embed-head::before { content: 'EMBEDDED'; padding: 1px 6px; border-radius: 4px; background: color-mix(in srgb, var(--md-accent, #4a7bd0) 18%, transparent); color: var(--md-accent, #4a7bd0); font-size: 10px; letter-spacing: 0.06em; }
:where(.md-content) .embed-head { break-after: avoid; } /* in a PDF the header is never left alone at the bottom of a page */
:where(.md-content) .embed-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
:where(.md-content) .embed-body > :first-child { margin-top: 0.6em; }
:where(.md-content) .embed-body > :last-child { margin-bottom: 0.6em; }
:where(.md-content) .embed-error { border-left-color: #d9534f; background: color-mix(in srgb, #d9534f 7%, transparent); }
:where(.md-content) .embed-error .embed-head::before { content: 'CANNOT EMBED'; background: color-mix(in srgb, #d9534f 18%, transparent); color: #d9534f; }
:where(.md-content) .embed-msg { margin: 0.6em 0 !important; color: var(--md-muted, #6a737d); }
