* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  margin-block-start: 0;
  margin-block-end: 0;
}

html {
  font-family: "JetBrains Mono", monospace;
  font-size-adjust: ex-height 0.53;
  -webkit-text-size-adjust: 100%;
  --line-height: 1.7rem;
  line-height: var(--line-height);
  font-size: 14px;
}

body {
  padding: 2ch;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  /* Site Header */
  margin-bottom: 2rem;
  & nav {
    display: flex;
    column-gap: 2ch;
    align-items: baseline;
    flex-wrap: wrap;
  }
  & a {
    font-style: normal;
    color: rgba(0, 0, 0, 0.8);
    text-decoration: none;
  }
  & a:hover {
    color: rgba(0, 0, 0, 0.8);
    text-decoration: underline;
  }
  & .title {
    font-size: 1.2em;
    flex-grow: 2;
  }
}

header:has(> h1) {
  /* Article Header */
  margin-bottom: 0.75rem;
  & h1 {
    margin-bottom: 0;
    line-height: 1.2;
  }
}

footer {
  margin-top: 2rem;
  & p {
    display: flex;
    column-gap: 2ch;
    justify-content: center;
    flex-wrap: wrap;
  }
  & a {
    display: flex;
    align-items: center;
    gap: 0.5ch;
    color: rgba(0, 0, 0, 0.8);
    text-decoration: none;
    white-space: nowrap;
    & svg {
      width: 1rem;
      height: 1rem;
    }
  }
}

main {
  max-width: 100%;
  margin: 0 auto;
  flex: 1;
  display: flex;
  gap: 4ch;
  width: 100%;
  justify-content: center;
}

article {
  max-width: 80ch;
  flex: 1;
  min-width: 0;
}

/* Table of Contents Sidebar */
.toc-sidebar {
  width: 30ch;
  position: sticky;
  top: 2ch;
  align-self: flex-start;
  max-height: calc(100vh - 4ch);
  overflow-y: auto;
  display: none;
  order: -1; /* Ensure TOC appears first (left side) */
  flex-shrink: 0;
}

@media (min-width: 140ch) {
  .toc-sidebar {
    display: block;
  }
}

.toc-sidebar nav {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  line-height: 1.4;
}

.toc-sidebar nav a {
  display: block;
  color: rgba(0, 0, 0, 0.6);
  text-decoration: none;
  padding: 0.25rem 0;
  border-left: 2px solid transparent;
  padding-left: 0.5ch;
  transition: all 0.2s ease;
}

.toc-sidebar nav a:hover {
  color: #4a90e2;
  border-left-color: #4a90e2;
}

.toc-sidebar nav a.active {
  color: #4a90e2;
  border-left-color: #4a90e2;
  font-weight: 500;
}

.toc-sidebar nav .toc-h2 {
  padding-left: 0.5ch;
}

.toc-sidebar nav .toc-h3 {
  padding-left: 2ch;
  font-size: 0.8rem;
}

.toc-sidebar::-webkit-scrollbar {
  width: 4px;
}

.toc-sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.toc-sidebar::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 2px;
}

.toc-sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

h1 {
  margin-bottom: 0.75rem;
}
h2, h3 {
  margin-bottom: 0.5rem;
}
section {
  margin-top: 1rem;
}
p, table, ol, ul, figure, aside, dl, hr {
  margin-bottom: var(--line-height);
}

sup, sub {
  line-height: 0;
}

h1, h2, h3 {
  font-family: "JetBrains Mono", monospace;
  font-weight: 600;
  color: #4a90e2;
  text-rendering: optimizeLegibility;
  text-wrap: balance;
  line-height: 1.3em;
}
h1, h2 {
  font-size: 1.5rem;
}
h3 {
  font-size: 1.2rem;
}

section:target > :is(h1, h2, h3) {
  position: relative;
}
section:target > :is(h1, h2, h3)::before {
  position: absolute;
  left: -1.2ch;
  content: "§";
}
:is(h1, h2, h3) > a {
  color: inherit;
  text-decoration: none;
}
:is(h1, h2, h3) > a:hover {
  color: inherit;
  text-decoration: none;
}

/* Block */

img, video {
  display: inline-block;
  vertical-align: middle;
  max-width: 100%;
  height: auto;
}
figure > img, figure > video {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

p {
  hyphens: auto;
  text-align: justify;
}
figure.blockquote {
  padding-left: 1em;
  border-left: 3px solid #4a90e2;
}
figure.blockquote > figcaption {
  text-align: right;
}

table {
  border-collapse: collapse;
  background: #fff;
}
table, td, th {
  border: 1px solid #dedede;
}
td, th {
  padding: 0.5625em 0.625em;
}

ol, ul, dd {
  padding-left: 3ch;
}
ul {
  list-style-type: disc;
}
ul::marker {
  color: #999 !important;
}
ul li::marker {
  color: #999 !important;
}
.roman {
  list-style-type: lower-roman;
}

/* Indent guides - Obsidian style */
ul ul, ul ol, ol ul, ol ol {
  position: relative;
}

ul ul::before, ol ul::before {
  content: "";
  position: absolute;
  left: -1.5ch;
  top: 0;
  bottom: 0;
  width: 1px;
  background-color: rgba(0, 0, 0, 0.12);
}

ul ol::before, ol ol::before {
  content: "";
  position: absolute;
  left: -1.5ch;
  top: 0;
  bottom: 0;
  width: 1px;
  background-color: rgba(0, 0, 0, 0.12);
}

/* Additional indent guides for deeper nesting */
ul ul ul::before, ul ol ul::before, ol ul ul::before, ol ol ul::before {
  left: -1.5ch;
  background-color: rgba(0, 0, 0, 0.1);
}

ul ul ol::before, ul ol ol::before, ol ul ol::before, ol ol ol::before {
  left: -1.5ch;
  background-color: rgba(0, 0, 0, 0.1);
}

dt {
  font-weight: bold;
}

aside.admn {
  display: flex;
  flex-direction: row;
  align-items: center;
}
aside.admn > svg.icon {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  fill: #1e3a8a;
}
aside.admn.warn > svg.icon {
  fill: #8b4513;
}
aside.admn > div {
  flex: 1;
  min-width: 0;
  padding-left: 1ch;
  margin-left: 1ch;
  border-left: 1px solid #dddddf;
  & > :last-child {
    margin-bottom: 0;
  }
}

aside.block {
  border-style: solid;
  border-width: 1px;
  border-radius: 4px;
  border-color: #87ceeb;
  padding: 1em;
  background: #f0f8ff;
  & > :last-child {
    margin-bottom: 0;
  }
  & > .title {
    font-family: "Open Sans", sans-serif;
    font-size: 1.5rem;
    color: #1e3a8a;
    text-align: center;
    margin-top: 0;
    margin-bottom: 0.5rem;
  }
}

details {
  padding-left: 1em;
  border-left: 3px solid #1e3a8a;
}

code {
  font-family: "JetBrains Mono", monospace;
  font-variant-ligatures: none;
  color: rgba(0, 0, 0, 0.9);
}
figcaption.title {
  font-style: italic;
  font-weight: 400;
  line-height: 1.45;
  color: #1e3a8a;
  margin-top: 0;
  margin-bottom: 0.25em;
}
figure.code-block > pre > code {
  display: flex;
  flex-direction: column;
  overflow-x: auto;
  overflow-y: clip;
  counter-reset: line;
  line-height: 1.2;
}
figure.code-block > pre > code > .line {
  counter-increment: line;
}
figure.code-block > pre > code > .line:before {
  content: counter(line);
  display: inline-block;
  width: 3ch;
  padding-right: 0.5ch;
  margin-right: 1ch;
  text-align: right;
  opacity: 0.35;
  border-right: 1px solid black;
}
ol.callout {
  list-style: none;
  counter-reset: callout;
}
ol.callout > li {
  position: relative;
}
ol.callout > li::before {
  counter-increment: callout;
  content: counter(callout);
  position: absolute;
  top: 0.2rem;
  left: -1.1rem;
}
i.callout::after {
  content: attr(data-value);
}
ol.callout > li::before, i.callout::after {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-size: 0.75rem;
  font-weight: bold;
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  line-height: 0.9rem;
  border-radius: 100%;
  background-color: black;
  color: white;
  text-align: center;
}

.two-col {
  display: flex;
  flex-direction: row;
}
.two-col > *:first-child {
  flex: 30%;
}
.two-col > *:last-child {
  flex: 30%;
}

hr {
  border: none;
  border-top: 1px solid rgba(0, 0, 0, 0.2);
  margin: var(--line-height) 0;
}

/* Inline */

p > code {
  white-space: nowrap;
} /* Sadly, overflow-wrap: anywhere doesn't compose with this */
p > code:not(.display) {
  line-height: 0px;
} /* https://iamvdo.me/en/blog/css-font-metrics-line-height-and-vertical-align */
.display {
  display: block;
  margin: calc(var(--line-height) / 2) 0;
  text-align: center;
  overflow-x: auto;
}

a {
  text-decoration-color: #4a90e2;
  text-decoration-thickness: 7%;
  color: black;
}
a:hover, a:focus {
  color: #4a90e2;
  fill: #4a90e2;
}
a:hover, a:focus {
  & code {
    color: #4a90e2;
    fill: #4a90e2;
  }
}
a.url {
  word-break: break-all;
}

kbd {
  font-family: "JetBrains Mono", monospace;
  font-variant-ligatures: none;
  line-height: 1;
}

kbd > kbd {
  display: inline-block;
  color: rgba(0, 0, 0, 0.8);
  background: #f7f7f7;
  border: 1px solid #ccc;
  border-radius: 3px;
  box-shadow: 0 1px 0 rgb(0 0 0 / 20%), 0 0 0 0.1em #fff inset;
  margin: 0 0.15em;
  padding: 0.2em 0.5em;
  top: -0.1em;
  vertical-align: middle;
  position: relative;
  white-space: nowrap;
}

dfn, .small-caps {
  font-style: normal;
  font-variant: small-caps;
}

.meta {
  display: block;
  color: #828282;
  font-family: "JetBrains Mono", monospace;
  font-size: 1rem;
}

.menu {
  font-weight: bold;
}

/* Special Cases */

.post-list {
  margin-left: 0;
  list-style: none;
}
.post-list > li {
  margin-top: 1em;
}
.post-list h2 {
  margin-top: 0;
}
.post-list a {
  color: #4a90e2;
  text-decoration: none;
  display: block;
}
.post-list a:hover {
  color: #4a90e2;
  text-decoration: underline;
}

.about-ava {
  float: left;
  margin-right: 2ch;
  display: inline;
}

/* Highlighting */

.hl-keyword, .hl-literal {
  color: #000000;
  font-weight: bold;
}
.hl-type {
  color: #0086b3;
}
.hl-tag {
  color: #000080;
}
.hl-title.function_ {
  color: #990000;
  font-weight: bold;
}
.hl-title.class_ {
  color: #445588;
  font-weight: bold;
}
.hl-comment {
  color: #008000;
  font-style: italic;
}
.hl-built_in, .hl-meta {
  color: #3c5d5d;
  font-weight: bold;
}
.hl-number {
  color: #009999;
}
.hl-string {
  color: #d14;
}
.hl-output {
  color: #4a90e2;
}
.hl-subst {
  color: rgba(0, 0, 0, 0.9);
}
.hl-attr, .hl-symbol {
  color: #008080;
}
.hl-line {
  background-color: #ffc;
}

/* Note sections */
.note {
  border-left-color: #ff6b6b;
  background-color: #fff5f5;
  border-left: 4px solid #ff6b6b;
  padding: 1em;
  margin: 1em 0;
  border-radius: 4px;
}

/* Callout blocks (Obsidian-style) */
div.callout {
  border-left: 4px solid #ff6b6b;
  background-color: #fff5f5;
  padding: 1em;
  margin: 1em 0;
  border-radius: 4px;
}

div.callout-pdf {
  border-left-color: #ff6b6b;
  background-color: #fff5f5;
}

div.callout-important {
  border-left-color: #ff6b6b;
  background-color: #fff5f5;
}

div.callout-title {
  font-size: 0.85em;
  color: rgba(0, 0, 0, 0.5);
  font-weight: 600;
  margin-bottom: 0.5em;
  font-family: "JetBrains Mono", monospace;
}

div.callout > blockquote {
  margin: 0.5em 0;
  padding-left: 1em;
  border-left: 2px solid rgba(0, 0, 0, 0.1);
}

div.callout > blockquote > blockquote {
  margin: 0.25em 0;
  padding: 0.5em 1em;
  background-color: rgba(255, 255, 255, 0.5);
  border-left: 2px solid rgba(0, 0, 0, 0.2);
  font-style: italic;
}

div.callout p:last-child {
  margin-bottom: 0;
}

/* Code blocks */
pre {
  background-color: #f5f5f5;
  padding: 1em;
  border-radius: 4px;
  overflow-x: auto;
}
