:root {
  --bg: #fff;
  --text: #000;
  --border: #d0d0d0;
  --link: #0645ad;

  --transition-fast: 120ms;
}

/* system dark */
@media (prefers-color-scheme: dark) {
  html:not(.light) {
    --bg: #090909;
    --text: #eaeaea;
    --border: #262626;
    --link: #6aa7ff;

  a[href^="http://"]::after,
  a[href^="https://"]::after {
    filter: invert(1);
  }
}

/* manual override */
html.dark {
  --bg: #090909;
  --text: #eaeaea;
  --border: #262626;
  --link: #6aa7ff;
}

html.light {
  --bg: #fff;
  --text: #000;
  --border: #d0d0d0;
  --link: #0645ad;
}

html {
  scroll-behavior: smooth;
}

a[href^="http"]::after {
  content: "";
  position: relative;
  display: inline-block;

  width: 0.85em;
  height: 0.85em;
  top: 0.1em;
  margin-left: 0.15em;

  background: url("./assets/external-link.svg") no-repeat center / contain;

  vertical-align: text-top;
}

/* Markdown symbols */
h1::before { content: "# "; }
h2::before { content: "## "; }
h3::before { content: "### "; }

h1::before, h2::before, h3::before {
  color: color-mix(in srgb, currentColor 25%, transparent);
}

em::before { content: "_"; }
em::after { content: "_"; }
b::before { content: "**"; }
b::after { content: "**"; }
del::before { content: "~~"; }
del::after { content: "~~"; }

em::before, em::after,
b::before, b::after,
del::before, del::after {
  color: color-mix(in srgb, currentColor 40%, transparent);
}

hr {
  border: none;
  border-top: 0.0625rem solid var(--border);
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

table {
  width: fit;
  border-collapse: collapse;
}

th,
td {
  padding: 0.3em 0.8em;
  border: 0.0625rem solid var(--border);
  text-align: left;
}

th {
  background: var(--bg-secondary);
}

blockquote {
  position: relative;

  margin: 1em 0.4em;
  padding: 0.15em 0.8em;

  border-left: 0.3em solid var(--border);
}

.quote-source {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;

  opacity: 0.45;
  text-decoration: none;

  transition: opacity var(--transition-fast);
}

.quote-source:hover {
  opacity: 1;
}

ul,
ol {
  padding-left: 2ch;
  margin: 0;
}
ul {
  padding-left: 0ch;
  list-style: none;
}

ul li::before {
  content: "* ";
  font-family: "Liberation Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--border);
  font-weight: 600;
}

ol li::marker {
  color: var(--border);
}

legend {
  padding: 0 1ch;
  border-left: 0.0625rem solid var(--border);
  border-right: 0.0625rem solid var(--border);
  font-size: 0.75em;
}

fieldset {
  border: 0.0625rem solid var(--border);
  margin: 0;
  margin-bottom: 0.5em;
}

input[type="checkbox"],
input[type="radio"] {
  appearance: none;
  position: relative;
  bottom: 0.18em;

}

label {
  padding: 1ch;
}

input[type="checkbox"]::before {
  position: relative;
  left: 1ch;
  content: "[ ]";
  font-family: "Liberation Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--border);
  font-weight: 600;
}

input[type="radio"]::before {
  position: relative;
  left: 1ch;
  content: "( )";
  font-family: "Liberation Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--border);
  font-weight: 600;
}

input[type="checkbox"]:hover::before {
  content: "[×]";
  font-family: "Liberation Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

input[type="radio"]:hover::before {
  content: "(•)";
  font-family: "Liberation Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

input[type="checkbox"]:checked::before {
  content: "[×]";
  font-family: "Liberation Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text);
}

input[type="radio"]:checked::before {
  content: "(•)";
  font-family: "Liberation Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text);
}

button {
  padding: 0.4rem 0.8rem;
  border: 0.0625rem solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  background: var(--border);
}

button:active {
  transform: translateY(0.125rem);
}

button:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

code {
  font-family: "Liberation Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: var(--bg-secondary);
  padding: 0.2em;
  border: 0.0625rem solid var(--border);
  font-size: 0.9em;
}

pre {
  background: var(--bg);
  position: relative;
  margin: 1em 0em;

  font-family: "Liberation Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  border: 0.0625rem solid var(--border);
  padding: 1rem;

  overflow-x: auto;
  resize: vertical;
  white-space: pre;
  word-break: break-word;

  font-size: 0.9em;
  max-height: 32em;

  border: 0.0625rem solid var(--border);

  cursor: pointer;
}

pre::before {
  content: attr(data-lang);
  position: absolute;
  top: 0.3em;
  right: 0.6em;

  font-family: "Liberation Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85em;

  padding: 0.1em 0.4em;

  background: var(--bg);
  border: 0.0625rem solid var(--border);
}

pre:hover::before {
  content: "COPY";
  border-bottom: 0.0625rem solid var(--text);
}

pre[data-copied="true"]::before {
  content: "COPIED";
  border: 0.125rem solid var(--link);
}

details {
  display: inline-block;
}

details summary {
  color: var(--link);
  text-decoration: underline dotted;
  list-style: none;

  text-decoration-thickness: 2px;
  text-decoration-color: color-mix(in srgb, currentcolor 50%, transparent);
  cursor: help;
}

abbr[title] {
  text-decoration: underline dotted;
  text-decoration-thickness: 2px;
  text-decoration-color: color-mix(in srgb, currentColor 50%, transparent);
  cursor: help;
}

aside.left {
  position: absolute;
  box-sizing: border-box;
  left: calc(50% - 60ch - 2.5em);
  padding-right: 2ch;
  transform: translateY(calc(-50% - 0.9em));
  width: 20ch;
  border-right: 0.0625rem solid var(--border);
}

aside.right {
  position: absolute;
  box-sizing: border-box;
  right: calc(50% - 60ch - 2.5em);
  padding-left: 2ch;
  transform: translateY(calc(-50% - 0.9em));
  width: 20ch;
  border-left: 0.0625rem solid var(--border);
}

aside.right::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -4.5ch;
  width: 4.5ch;
  height: 0.0625rem;
  background: var(--border);
}

aside.left::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 100%;
  width: 4.5ch;
  height: 0.0625rem;
  background: var(--border);
}

@media (max-width: 134ch) {
  aside {
    position: static;
    left: auto;
    transform: none;

    width: auto;

    margin: 1em 0.4em;
    padding: 0.15em 0.8em;

    border: none;
    border-left: 0.3em solid var(--border);
  }

  aside::after {
    display: none;
  }
}

.callout {
  position: relative;

  margin: 1em 0.4em;
  padding: 1em 0.8em;

  background: var(--callout-bg);
  border: 0.0625rem solid var(--callout-accent);
}

.callout::before {
  content: var(--callout-label);
  position: absolute;
  top: -0.6em;
  left: 0.6em;

  font-family: "Liberation Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.75em;

  padding: 0 0.4em;

  background: var(--bg);
  color: var(--callout-accent);
  border: 0.0625rem solid var(--callout-accent);
}

.callout.note {
  --callout-label: "![NOTE]";
  --callout-accent: #3b82f6;
  --callout-bg: color-mix(in srgb, var(--callout-accent) 10%, transparent);
}

.callout.important {
  --callout-label: "![IMPORTANT]";
  --callout-accent: #facc15;
  --callout-bg: color-mix(in srgb, var(--callout-accent) 10%, transparent);
}

body {
  position: relative;
  background: var(--bg);
  color: var(--text);
  font-family: "FreeSans", "Liberation Sans", Arial, sans-serif;
  font-size: 12pt;
  line-height: 1.5;
  margin: 1rem auto 0;
  width: clamp(40ch, 100%, 80ch);
  box-sizing: border-box;
  padding: 2.5rem;
  border: 0.0625rem solid var(--border);

  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    border-color var(--transition-fast);
}


a {
  color: var(--link);
  text-decoration: none;
}

a.div {
  all: unset;
  cursor: pointer;
}

a.tile {
  all: unset;
  cursor: pointer;
  margin: 0 0.5em 0.5em 0;
  display: inline-block;
  width: 100%;

  fieldset {
    position: relative; 
    padding: 0.9em;

    span {
      position: absolute; 
      top: 0.5em; 
      color: var(--border);
    }
    div {
      position: absolute; 
      top: 0.5em; 
      right: 2ch; 
      color: var(--border);
      fill: var(--border);
    }
    h2 {
      margin-top: 1em;
    }
  }
}

a.tile:hover {
  margin-left: 0.3em;
}


nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.nav-left {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 1ch;
  flex-wrap: wrap;
}

.nav-center {
  justify-self: center;
}

.nav-right {
  justify-self: end;

  display: flex;
  align-items: center;
  gap: 1ch;
}

/* toggle */
.toggle {
  display: none;
}

.btn {
  width: 1em;
  height: 1em;
  display: inline-block;
  position: relative;
  cursor: pointer;
  vertical-align: -0.15em;

  margin-left: auto;
}

.btn svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transition: opacity var(--transition-fast) ease, transform var(--transition-fast) ease;
}

/* default = system light assumed */
.sun {
  opacity: 1;
}

.moon {
  fill: currentColor;
  opacity: 0;
  transform: rotate(90deg) scale(0.75);
}

/* toggle flips theme */
body:has(#theme-toggle:checked) .sun {
  opacity: 0;
  transform: rotate(-90deg) scale(0.75);
}

body:has(#theme-toggle:checked) .moon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}
