/* Render the HTML so it looks like the markdown it came from.
   Markdown syntax is drawn with ::before/::after, so it is dimmed
   and is not copied when the reader selects text or code. */

:root {
  --bg: #fdfdfb;
  --fg: #1d1d1b;
  --dim: #9a9a93;
  --link: #1a5fb4;
  --code-bg: #f2f2ee;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --fg: #dcdcd6;
    --dim: #6c6c66;
    --link: #78aeed;
    --code-bg: #1f1f1d;
  }
}

* { box-sizing: border-box; }

html {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--fg);
}
body {
  max-width: 80ch;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

/* Every block is one "line" of markdown: same size, blank line between. */
h1, h2, h3, h4, h5, h6, p, ul, ol, pre, blockquote, table, hr, figure {
  font-size: 1rem;
  margin: 0 0 1.6em;
}
h1, h2, h3, h4, h5, h6 { font-weight: bold; }
h1::before { content: "# "; }
h2::before { content: "## "; }
h3::before { content: "### "; }
h4::before { content: "#### "; }
h5::before { content: "##### "; }
h6::before { content: "###### "; }
h1::before, h2::before, h3::before, h4::before, h5::before, h6::before { color: var(--dim); }

/* Inline syntax */
strong::before, strong::after { content: "**"; color: var(--dim); font-weight: normal; }
em::before, em::after { content: "_"; color: var(--dim); }
del::before, del::after { content: "~~"; color: var(--dim); }
:not(pre) > code::before, :not(pre) > code::after { content: "`"; color: var(--dim); }
:not(pre) > code { background: var(--code-bg); }

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
main a::before { content: "["; color: var(--dim); }
main a::after { content: "](" attr(href) ")"; color: var(--dim); word-break: break-all; }
.posts a::after, .meta a::after { content: "]"; }

/* Lists */
ul, ol { padding-left: 0; list-style: none; }
li { padding-left: 2ch; position: relative; }
ul > li::before { content: "-"; position: absolute; left: 0; color: var(--dim); }
ol { counter-reset: md-ol; }
ol > li { counter-increment: md-ol; padding-left: 3ch; }
ol > li::before { content: counter(md-ol) "."; position: absolute; left: 0; color: var(--dim); }
li > ul, li > ol, li > p { margin-bottom: 0; }

/* Code blocks get their fences back */
pre {
  background: var(--code-bg);
  padding: 0.8em 1ch;
  overflow-x: auto;
  line-height: 1.45;
}
pre code { font-family: inherit; }
pre code::before { content: "```" attr(data-lang) "\A"; color: var(--dim); }
pre code::after { content: "\A```"; color: var(--dim); }

/* Quotes, rules, images */
blockquote { margin-left: 0; padding-left: 2ch; position: relative; }
blockquote::before { content: ">"; position: absolute; left: 0; color: var(--dim); }
blockquote > :last-child { margin-bottom: 0; }
hr { border: 0; text-align: left; }
hr::before { content: "---"; color: var(--dim); }
img { max-width: 100%; display: block; }

/* Tables: pipes and dashes */
table { border-collapse: collapse; display: block; overflow-x: auto; }
th, td { padding: 0 1ch; border-left: 1px solid var(--dim); text-align: left; }
th:last-child, td:last-child { border-right: 1px solid var(--dim); }
thead th { border-bottom: 1px dashed var(--dim); }

/* Chrome around the content */
header { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1ch; margin-bottom: 3em; }
header p { margin: 0; font-weight: bold; }
header a { color: var(--fg); }
nav a { margin-left: 2ch; color: var(--dim); }
.meta { color: var(--dim); }
.meta::before { content: "<!-- "; }
.meta::after { content: " -->"; }
.posts time { color: var(--dim); margin-right: 1ch; }
footer { color: var(--dim); margin-top: 4em; }
footer code { background: none; user-select: all; cursor: pointer; }
