/* The rendered document: a sheet of paper on a calm canvas, in the system font. */

:root {
  color-scheme: light dark;
  --canvas: #efeeeb;
  --paper: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #a1a1a6;
  --rule: #e2e1dd;
  --code-bg: #f4f3f0;
  --link: #0a66d6;
  --accent: -apple-system-control-accent;
  --ring: rgba(10, 102, 214, 0.35);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 10px 32px rgba(0, 0, 0, 0.07);
  --note: #0969da; --tip: #1a7f37; --important: #8250df; --warning: #9a6700; --caution: #cf222e;
}

/* Dark: by the system, or chosen in the web app (theme-dark / theme-light on the root). */
@media (prefers-color-scheme: dark) {
  :root:not(.print):not(.theme-light) {
    --canvas: #19191b;
    --paper: #232325;
    --text: #e9e9eb;
    --muted: #a1a1a6;
    --faint: #6e6e73;
    --rule: #3a3a3d;
    --code-bg: #2d2d30;
    --link: #4aa3ff;
    --ring: rgba(74, 163, 255, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 32px rgba(0, 0, 0, 0.35);
    --note: #4493f8; --tip: #3fb950; --important: #ab7df8; --warning: #d29922; --caution: #f85149;
  }
}
:root.theme-light { color-scheme: light; }
:root.theme-dark { color-scheme: dark; }
:root.theme-dark:not(.print) {
  --canvas: #19191b;
  --paper: #232325;
  --text: #e9e9eb;
  --muted: #a1a1a6;
  --faint: #6e6e73;
  --rule: #3a3a3d;
  --code-bg: #2d2d30;
  --link: #4aa3ff;
  --ring: rgba(74, 163, 255, 0.4);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 32px rgba(0, 0, 0, 0.35);
  --note: #4493f8; --tip: #3fb950; --important: #ab7df8; --warning: #d29922; --caution: #f85149;
}

html, body { margin: 0; background: var(--canvas); }
body {
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

#page { padding: 28px 28px 0; }
#content {
  max-width: 760px;
  margin: 0 auto;
  padding: 56px 64px 40vh;
  background: var(--paper);
  border-radius: 14px 14px 0 0;
  box-shadow: var(--shadow);
  min-height: 60vh;
  outline: none;
}

/* Narrow panes (split view) use the full width, without the sheet. */
@media (max-width: 880px) {
  body { background: var(--paper); }
  #page { padding: 0; }
  #content { max-width: none; padding: 28px 30px 40vh; border-radius: 0; box-shadow: none; }
}

/* Typography */
.markdown > :first-child > :first-child, .markdown > :first-child { margin-top: 0; }
h1, h2, h3, h4, h5, h6 { line-height: 1.25; margin: 1.6em 0 0.6em; font-weight: 700; }
h1 { font-size: 2em; letter-spacing: -0.01em; }
h2 { font-size: 1.5em; }
h3 { font-size: 1.25em; font-weight: 600; }
h4 { font-size: 1.05em; font-weight: 600; }
h5, h6 { font-size: 0.95em; font-weight: 600; color: var(--muted); }
p { margin: 0 0 1em; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
strong { font-weight: 650; }
del { color: var(--muted); }
hr { border: 0; height: 1px; background: var(--rule); margin: 2.2em 0; }
img { max-width: 100%; height: auto; border-radius: 6px; }

ul, ol { margin: 0 0 1em; padding-left: 1.6em; }
li { margin: 0.2em 0; }
li > p { margin: 0.3em 0; }
li > ul, li > ol { margin: 0.2em 0; }
ul.task-list { padding-left: 0.4em; }
li.task { list-style: none; }
li.task > input[type="checkbox"] {
  margin: 0 0.45em 0 -0.1em;
  vertical-align: -0.1em;
  width: 1em; height: 1em;
  accent-color: var(--accent);
  cursor: pointer;
}

blockquote { margin: 0 0 1em; padding: 0.1em 0 0.1em 1.1em; border-left: 3px solid var(--rule); color: var(--muted); }
blockquote > :last-child { margin-bottom: 0; }

code, pre, .mdv-source-editor { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
code { font-size: 0.86em; background: var(--code-bg); border-radius: 5px; padding: 0.12em 0.38em; }
pre { background: var(--code-bg); border-radius: 10px; padding: 14px 16px; margin: 0 0 1em; overflow-x: auto; line-height: 1.45; }
pre code { background: none; padding: 0; font-size: 0.86em; }

table { border-collapse: collapse; margin: 0 0 1em; display: block; overflow-x: auto; max-width: 100%; }
th, td { border: 1px solid var(--rule); padding: 6px 12px; }
th { background: var(--code-bg); font-weight: 600; }
tr:nth-child(2n) td { background: color-mix(in srgb, var(--code-bg) 45%, transparent); }

/* Syntax colours (Xcode-like, calm) */
.tok-keyword { color: #ad3da4; font-weight: 600; }
.tok-string { color: #c41a16; }
.tok-comment { color: #707f8c; font-style: italic; }
.tok-number { color: #1c00cf; }
.tok-type { color: #3900a0; }
.tok-attr, .tok-tag { color: #0f68a0; }
.tok-inserted { color: #1a7f37; }
.tok-deleted { color: #cf222e; }
@media (prefers-color-scheme: dark) {
  :root:not(.print):not(.theme-light) .tok-keyword { color: #ff7ab2; }
  :root:not(.print):not(.theme-light) .tok-string { color: #ff8170; }
  :root:not(.print):not(.theme-light) .tok-comment { color: #7f8c98; }
  :root:not(.print):not(.theme-light) .tok-number { color: #d9c97c; }
  :root:not(.print):not(.theme-light) .tok-type { color: #dabaff; }
  :root:not(.print):not(.theme-light) .tok-attr, :root:not(.print):not(.theme-light) .tok-tag { color: #6bdfff; }
  :root:not(.print):not(.theme-light) .tok-inserted { color: #3fb950; }
  :root:not(.print):not(.theme-light) .tok-deleted { color: #f85149; }
}
:root.theme-dark:not(.print) .tok-keyword { color: #ff7ab2; }
:root.theme-dark:not(.print) .tok-string { color: #ff8170; }
:root.theme-dark:not(.print) .tok-comment { color: #7f8c98; }
:root.theme-dark:not(.print) .tok-number { color: #d9c97c; }
:root.theme-dark:not(.print) .tok-type { color: #dabaff; }
:root.theme-dark:not(.print) .tok-attr, :root.theme-dark:not(.print) .tok-tag { color: #6bdfff; }
:root.theme-dark:not(.print) .tok-inserted { color: #3fb950; }
:root.theme-dark:not(.print) .tok-deleted { color: #f85149; }

/* GitHub alerts */
.mdv-alert { margin: 0 0 1em; padding: 0.4em 0 0.4em 1em; border-left: 3px solid var(--alert); }
.mdv-alert > :last-child { margin-bottom: 0; }
.mdv-alert-title { font-weight: 650; color: var(--alert); margin-bottom: 0.3em; }
.mdv-alert-note { --alert: var(--note); }
.mdv-alert-tip { --alert: var(--tip); }
.mdv-alert-important { --alert: var(--important); }
.mdv-alert-warning { --alert: var(--warning); }
.mdv-alert-caution { --alert: var(--caution); }

/* Find: all matches, the current one stronger. */
::highlight(mdv-find) { background-color: rgba(255, 200, 0, 0.35); }
::highlight(mdv-find-current) { background-color: rgba(255, 170, 0, 0.9); color: #000000; }

/* Selection in the raw editor, mirrored on the page (split view) */
::highlight(mdv-source) { background-color: rgba(10, 102, 214, 0.22); }

/* Diagrams */
.mdv-mermaid { margin: 0 0 1em; text-align: center; }
.mdv-mermaid-svg svg { max-width: 100%; height: auto; }
.mdv-mermaid-source { text-align: left; }
.mdv-stale { opacity: 0.55; transition: opacity 0.2s; }

/* Diagram editor: a small bar over the diagram, selected node outlined in the link colour. */
.mdv-mermaid { position: relative; }
.mdv-mermaid g.node { cursor: pointer; }
.mdv-mermaid g.node.mdv-selected rect, .mdv-mermaid g.node.mdv-selected polygon,
.mdv-mermaid g.node.mdv-selected circle, .mdv-mermaid g.node.mdv-selected path {
  stroke: var(--link) !important; stroke-width: 3px !important;
}
/* Above the diagram, not on it: it would cover the nodes at the top right. */
.mdv-mermaid .mdv-edge-hit { fill: none; stroke: transparent; stroke-width: 16px; pointer-events: stroke; cursor: pointer; }
.mdv-mermaid path.mdv-selected-edge { stroke: var(--link) !important; stroke-width: 3px !important; }
.mdv-diagram-bar {
  display: flex; justify-content: flex-end; gap: 6px; align-items: center; margin: 0 0 6px;
  font-size: 12px; opacity: 0; transition: opacity 0.15s;
}
.mdv-mermaid:hover .mdv-diagram-bar, .mdv-mermaid.mdv-diagram-active .mdv-diagram-bar { opacity: 1; }
.mdv-diagram-bar button {
  font: inherit; font-weight: 600; padding: 4px 11px; border: 0; border-radius: 999px;
  background: var(--code-bg); color: var(--text); cursor: pointer;
}
.mdv-diagram-bar button:hover { color: var(--link); }
.mdv-diagram-hint { color: var(--muted); }
.mdv-node-input {
  position: absolute; z-index: 2; box-sizing: border-box; font: inherit; font-size: 14px;
  padding: 6px 10px; border: 2px solid var(--link); border-radius: 8px; outline: none;
  background: var(--paper); color: var(--text); text-align: center;
}
.mdv-error { font-size: 0.85em; color: var(--caution); margin: 0.4em 0 0; text-align: left; }

/* Images that cannot be shown */
.mdv-missing {
  display: inline-flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 12px 14px; border-radius: 10px; background: var(--code-bg);
  color: var(--muted); font-size: 0.85em; line-height: 1.35; max-width: 100%;
}
.mdv-missing strong { color: var(--text); font-weight: 600; }
.mdv-missing button {
  font: inherit; font-weight: 600; color: var(--link); background: none; border: 0; padding: 0; cursor: pointer;
}

/* Button over an image to replace it */
.mdv-image-button {
  position: absolute; z-index: 3; font: 600 12px -apple-system, system-ui, sans-serif;
  padding: 5px 12px; border: 0; border-radius: 999px; cursor: pointer;
  background: rgba(30, 30, 32, 0.72); color: #ffffff; backdrop-filter: blur(12px);
}
.mdv-image-button:hover { background: rgba(30, 30, 32, 0.88); }
html.print .mdv-image-button { display: none; }

/* Editing in place */
.mdv-block { position: relative; }
.mdv-block.mdv-editing { outline: 2px solid var(--ring); outline-offset: 6px; border-radius: 3px; caret-color: var(--accent); }
.mdv-block[data-edit="source"] { cursor: default; }
.mdv-source-editor {
  display: block; box-sizing: border-box; width: 100%; min-height: 3em; margin: 0 0 1em;
  padding: 12px 14px; border: 0; border-radius: 10px; resize: none;
  background: var(--code-bg); color: var(--text); font-size: 0.86em; line-height: 1.45;
  outline: 2px solid var(--ring); outline-offset: 2px;
}
.mdv-placeholder > p:first-child::before {
  content: attr(data-placeholder);
  color: var(--faint);
  pointer-events: none;
  position: absolute;
}

/* Print and PDF: always light, no sheet, nothing interactive. */
html.print, html.print body { background: #ffffff; }
/* In the PDF one CSS pixel is one point: --print-size is the body text size in points. */
html.print body { font-size: var(--print-size, 12px); line-height: 1.45; }
html.print #page { padding: 0; }
html.print #content { max-width: none; padding: 0; border-radius: 0; box-shadow: none; min-height: 0; }
html.print pre { white-space: pre-wrap; overflow: visible; }
html.print table { display: table; }
html.print h1, html.print h2, html.print h3, html.print h4 { break-after: avoid; }
html.print pre, html.print table, html.print img, html.print .mdv-mermaid, html.print blockquote, html.print .mdv-alert { break-inside: avoid; }
html.print.break-h1 #content > h1:not(:first-child) { break-before: page; }
html.print a { color: var(--link); }
html.print .mdv-diagram-bar { display: none; }
