/* A note's rendered HTML (renderDocument in editor/markdownToHtml.ts), drawn
   from the theme's editor and document tokens the way the editor draws the
   note in Always Rendered. Used by the PDF export and Share as Image and meant
   for deft.page too, so nothing here reaches outside .rendered-note or into
   the app's own classes. Blocks have no margins: the space between them is
   the blank lines the note has, which the renderer writes as empty
   paragraphs. */
@layer app {
	.rendered-note {
		/* The print view sets the scale: the font size is multiplied by it, and
		   rem lengths go through --document-rem so they follow. */
		--document-rem: calc(1rem * var(--document-scale, 1));
		/* One line of the note: what a blank line leaves in the editor. */
		--line: calc(var(--editor-font-size) * var(--editor-line-height));
		--blockquote-step: calc(1.25 * var(--document-rem));
		--list-step: calc(1.5 * var(--document-rem));
		/* The --measured- widths are the markers measured in the note's font
		   (printView.ts); these estimates stand in until they are. */
		--task-width: var(--measured-task, calc(13px * var(--document-scale, 1) + 0.4em));
		font-family: var(--editor-font-family);
		font-size: var(--editor-font-size);
		font-weight: var(--editor-font-weight);
		line-height: var(--editor-line-height);
		color: var(--editor-foreground);
		background-color: var(--editor-background);
		overflow-wrap: break-word;
		print-color-adjust: exact;
		-webkit-print-color-adjust: exact;
	}

	.rendered-note *,
	.rendered-note *::before,
	.rendered-note *::after {
		box-sizing: border-box;
	}

	.rendered-note :where(p, h1, h2, h3, h4, h5, h6, blockquote, ul, ol, li, pre, table, figure) {
		margin: 0;
	}

	/* The note's title above it, as the editor's header shows it. */
	.rendered-note-title {
		margin: 0 0 var(--line);
		font-family: var(--editor-font-family);
		font-size: var(--heading-1-font-size);
		font-weight: var(--heading-1-font-weight);
		line-height: 1.3;
		color: var(--editor-foreground);
	}

	.rendered-note :is(h1, h2, h3, h4, h5, h6) {
		font-family: var(--heading-font-family);
	}

	.rendered-note h1 {
		font-size: var(--heading-1-font-size);
		font-weight: var(--heading-1-font-weight);
		color: var(--heading-1-foreground);
		padding-top: var(--heading-1-padding-top);
		border-bottom: var(--heading-1-border-width) solid var(--heading-1-border);
	}

	.rendered-note h2 {
		font-size: var(--heading-2-font-size);
		font-weight: var(--heading-2-font-weight);
		color: var(--heading-2-foreground);
		padding-top: var(--heading-2-padding-top);
		border-bottom: var(--heading-2-border-width) solid var(--heading-2-border);
	}

	.rendered-note h3 {
		font-size: var(--heading-3-font-size);
		font-weight: var(--heading-3-font-weight);
		color: var(--heading-3-foreground);
		padding-top: var(--heading-3-padding-top);
		border-bottom: var(--heading-3-border-width) solid var(--heading-3-border);
	}

	.rendered-note h4 {
		font-size: var(--heading-4-font-size);
		font-weight: var(--heading-4-font-weight);
		color: var(--heading-4-foreground);
		padding-top: var(--heading-4-padding-top);
		border-bottom: var(--heading-4-border-width) solid var(--heading-4-border);
	}

	.rendered-note h5 {
		font-size: var(--heading-5-font-size);
		font-weight: var(--heading-5-font-weight);
		color: var(--heading-5-foreground);
		padding-top: var(--heading-5-padding-top);
		border-bottom: var(--heading-5-border-width) solid var(--heading-5-border);
	}

	.rendered-note h6 {
		font-size: var(--heading-6-font-size);
		font-weight: var(--heading-6-font-weight);
		color: var(--heading-6-foreground);
		padding-top: var(--heading-6-padding-top);
		border-bottom: var(--heading-6-border-width) solid var(--heading-6-border);
	}

	.rendered-note strong {
		font-weight: 700;
	}

	.rendered-note :is(a, .note-link) {
		color: var(--link);
		text-decoration: none;
	}

	.rendered-note mark {
		background-color: color-mix(in srgb, var(--highlight-background) 55%, transparent);
		color: inherit;
		border-radius: 2px;
	}

	/* Source the editor shows rather than renders: HTML that doesn't render, an
	   embed that isn't an image. */
	.rendered-note .markup {
		color: var(--markup-foreground);
	}

	.rendered-note hr {
		height: 0;
		margin: calc((var(--line) - 1px) / 2) 0;
		border: none;
		border-top: 1px solid var(--hr-border);
	}

	/* Lists as the editor indents them: the marker on the text's edge, the
	   text past it with wrapped lines hanging under it, each level a step in. */
	.rendered-note :is(ul, ol) {
		padding: 0;
		list-style: none;
	}

	.rendered-note li {
		position: relative;
		padding-left: var(--hang);
	}

	.rendered-note li + li,
	.rendered-note li li:first-child {
		margin-top: 0.35em;
	}

	.rendered-note li > :is(ul, ol) {
		margin-left: calc(var(--list-step) - var(--hang));
	}

	.rendered-note ul > li {
		--hang: var(--measured-bullet, 0.75em);
	}

	.rendered-note ul > li::before {
		content: '•';
		position: absolute;
		left: 0;
		font-weight: 700;
		color: var(--editor-foreground);
	}

	.rendered-note ol > li {
		--marker: calc(var(--digits, 1) * var(--measured-digit, 0.6em) + var(--measured-dot, 0.6em));
		--hang: var(--marker);
	}

	/* No text-indent: a task's negative one would carry its number out past
	   the item's edge. */
	.rendered-note ol > li::before {
		content: attr(data-marker);
		position: absolute;
		left: 0;
		font-variant-numeric: tabular-nums;
		text-indent: 0;
	}

	.rendered-note ol > li.paren {
		--marker: calc(var(--digits, 1) * var(--measured-digit, 0.6em) + var(--measured-paren, 0.65em));
	}

	.rendered-note li.digits-2 {
		--digits: 2;
	}

	.rendered-note li.digits-3 {
		--digits: 3;
	}

	/* A task's box stands in for the bullet; the box and its space hang. */
	.rendered-note li.task {
		text-indent: calc(-1 * var(--task-width));
	}

	.rendered-note ul > li.task {
		--hang: var(--task-width);
	}

	.rendered-note ul > li.task::before {
		content: none;
	}

	.rendered-note ol > li.task {
		--hang: calc(var(--marker) + var(--task-width));
	}

	/* Only the item's first line hangs: a nested list, a later paragraph or
	   an inline block such as math starts from its own edge. */
	.rendered-note li.task :not(li.task, li.task > p:first-child) {
		text-indent: 0;
	}

	.rendered-note input[type='checkbox'] {
		width: calc(13px * var(--document-scale, 1));
		height: calc(13px * var(--document-scale, 1));
		margin: 0;
		vertical-align: middle;
		position: relative;
		top: -1px;
	}

	/* A bar per level, the text a step in. A border rather than a drawn bar,
	   so a quote broken across pages keeps its bar on both. */
	.rendered-note blockquote {
		padding-left: calc(var(--blockquote-step) - var(--blockquote-border-width));
		border-left: var(--blockquote-border-width) solid var(--blockquote-border);
		color: var(--blockquote-foreground);
		font-style: var(--blockquote-font-style);
	}

	.rendered-note code {
		font-family: var(--code-font-family);
		font-size: var(--code-font-size);
	}

	.rendered-note :not(pre) > code {
		padding: 0.1em 0.3em;
		background-color: var(--code-inline-background);
		border-radius: var(--border-radius-small);
	}

	.rendered-note kbd {
		font-family: var(--code-font-family);
		font-size: 0.85em;
		padding: 0.05em 0.35em;
		border: 1px solid var(--editor-border);
		border-bottom-width: 2px;
		border-radius: var(--border-radius-small);
		background-color: var(--code-inline-background);
	}

	/* The fenced box. Its hairline is a border inside the padding, since a
	   box-shadow prints blurred. */
	.rendered-note pre {
		padding: calc(0.4 * var(--document-rem) - 1px) calc(0.6 * var(--document-rem) - 1px);
		font-family: var(--code-font-family);
		font-size: var(--code-font-size);
		white-space: pre;
		overflow-x: auto;
		background-color: var(--code-background);
		border: 1px solid var(--code-border);
		border-radius: var(--border-radius-medium);
	}

	.rendered-note pre code {
		font-size: inherit;
	}

	/* Indented code is monospace and nothing more, as in the editor. */
	.rendered-note pre.indented {
		padding: 0;
		background: none;
		border: none;
		border-radius: 0;
	}

	/* What the editor's highlighter colors, by the class CODE_TOKENS
	   (editor/codeHighlighting.ts) gives each token. */
	.rendered-note .tok-keyword {
		color: var(--syntax-keyword);
	}

	.rendered-note .tok-string {
		color: var(--syntax-string);
	}

	.rendered-note .tok-number {
		color: var(--syntax-number);
	}

	.rendered-note .tok-comment {
		color: var(--syntax-comment);
		font-style: italic;
	}

	.rendered-note .tok-function {
		color: var(--syntax-function);
	}

	.rendered-note .tok-constant {
		color: var(--syntax-constant);
	}

	.rendered-note .tok-type {
		color: var(--syntax-type);
	}

	.rendered-note .tok-property {
		color: var(--syntax-type);
	}

	.rendered-note .tok-operator {
		color: var(--editor-foreground-muted);
	}

	/* Tables with the medium corner, as roundedTable.ts draws them: the table
	   draws the outer edge, each cell its top and left. */
	.rendered-note table {
		border-collapse: separate;
		border-spacing: 0;
		border: 1px solid var(--table-border);
		border-radius: var(--border-radius-medium);
		font-size: var(--table-font-size);
	}

	.rendered-note :is(th, td) {
		padding: 0.35em 0.6em;
		border-top: 1px solid var(--table-border);
		border-left: 1px solid var(--table-border);
	}

	.rendered-note thead tr:first-child > *,
	.rendered-note table > tbody:first-child > tr:first-child > * {
		border-top: 0;
	}

	.rendered-note tr > :first-child {
		border-left: 0;
	}

	.rendered-note thead tr:first-child > :first-child {
		border-top-left-radius: calc(var(--border-radius-medium) - 1px);
	}

	.rendered-note thead tr:first-child > :last-child {
		border-top-right-radius: calc(var(--border-radius-medium) - 1px);
	}

	.rendered-note table > :last-child > tr:last-child > :first-child {
		border-bottom-left-radius: calc(var(--border-radius-medium) - 1px);
	}

	.rendered-note table > :last-child > tr:last-child > :last-child {
		border-bottom-right-radius: calc(var(--border-radius-medium) - 1px);
	}

	.rendered-note th {
		font-weight: var(--table-header-font-weight);
		background-color: var(--table-header-background);
	}

	.rendered-note tbody tr:nth-child(even) td {
		background-color: var(--table-striped-row-background);
	}

	/* An empty cell keeps a line's height. */
	.rendered-note :is(th, td):empty::before {
		content: '\200b';
	}

	/* Images as the editor places them (imageHtml in markdownToHtml.ts). */
	.rendered-note img {
		display: block;
		max-width: 100%;
		margin: 0;
	}

	.rendered-note img.inline {
		display: inline-block;
		vertical-align: bottom;
		width: auto;
		max-height: 1lh;
		object-fit: contain;
	}

	.rendered-note img.item {
		display: inline-block;
		vertical-align: top;
	}

	.rendered-note img.html {
		display: inline-block;
		vertical-align: middle;
	}

	/* In an HTML block an image sits in its line, as .cm-html-block draws it. */
	.rendered-note .html-block img {
		display: inline;
	}

	.rendered-note img[width][height] {
		height: auto;
	}

	.rendered-note .image-missing {
		display: inline-flex;
		align-items: center;
		gap: 0.4em;
		padding: 0 0.4em;
		border: 1px dashed var(--editor-border);
		border-radius: var(--border-radius-medium);
		background-color: color-mix(in srgb, var(--editor-foreground) 4%, transparent);
		color: var(--editor-foreground-muted);
		font-size: 0.85em;
		line-height: 1.4;
		vertical-align: middle;
	}

	.rendered-note .image-missing svg {
		flex-shrink: 0;
	}

	.rendered-note .math-display {
		display: block;
		padding: 2px;
		overflow-x: auto;
		overflow-y: hidden;
	}

	.rendered-note .math-display .katex-display {
		margin: 0;
	}

	.rendered-note .footnote-ref {
		font-size: 0.75em;
		vertical-align: super;
	}

	.rendered-note .footnotes {
		margin-top: var(--line);
	}

	.rendered-note .footnotes > ol {
		margin-top: var(--line);
	}

	.rendered-note .footnotes > ol > li {
		padding-left: 0;
	}

	.rendered-note .footnotes > ol > li::before {
		content: none;
	}

	.rendered-note .footnote-label {
		color: var(--editor-foreground-muted);
		font-size: 0.85em;
	}

	/* A rendered HTML block, its elements styled as their markdown
	   counterparts (livePreview.ts's .cm-html-block). */
	.rendered-note .html-block p {
		margin: 0.5em 0;
	}

	.rendered-note .html-block :is(h1, h2, h3, h4, h5, h6) {
		margin: 0.5em 0;
		padding-top: 0;
	}

	.rendered-note .html-block blockquote {
		margin: 0.5em 0;
		padding-left: calc(1.5 * var(--document-rem));
		border-left: none;
	}

	.rendered-note .html-block :is(ul, ol) {
		margin: 0.5em 0;
		padding-left: calc(1.5 * var(--document-rem));
		list-style: revert;
	}

	.rendered-note .html-block li {
		padding-left: 0;
	}

	.rendered-note .html-block li::before {
		content: none;
	}

	.rendered-note .html-block hr {
		margin: 0.5em 0;
	}

	.rendered-note .html-block pre {
		margin: 0.5em 0;
		padding: 0.6em 0.8em;
	}

	.rendered-note .html-block > :first-child,
	.rendered-note .html-block > :first-child > :first-child {
		margin-top: 0;
	}

	.rendered-note .html-block > :last-child,
	.rendered-note .html-block > :last-child > :last-child {
		margin-bottom: 0;
	}

	/* Paper and a picture can't scroll sideways. A table too wide for them
	   lets a cell's URL or hash break (wrapWideTables in printView.ts, and the
	   share card's fitTables), and failing that every cell's words. */
	.rendered-note :is(th, td).long,
	.rendered-note table.squeezed :is(th, td) {
		overflow-wrap: anywhere;
	}

	@media print {
		/* The sheet is the page: WebKit paints no background into a page's
		   margins, so a tinted page would print framed in white. */
		.rendered-note {
			background-color: transparent;
		}

		/* Laid out once, so the slower wrap that avoids a lone last word costs
		   nothing. Code is left to wrap where it fills. */
		.rendered-note :is(p, li, th, td) {
			text-wrap-style: pretty;
		}

		/* Paper can't scroll sideways, so long lines wrap. */
		.rendered-note pre {
			white-space: pre-wrap;
			overflow-wrap: anywhere;
			text-wrap-style: auto;
		}

		.rendered-note :is(h1, h2, h3, h4, h5, h6) {
			break-after: avoid;
		}

		.rendered-note :is(img, tr, .math-display, .image-missing) {
			break-inside: avoid;
		}
	}
}
