@import url('https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,400;0,600;0,700;1,400;1,600&display=swap');

:root {
  --bg: #fafaf8;
  --text: #1a1a1a;
  --heading: #111;
  --muted: #6b7280;
  --muted-2: #9ca3af;
  --muted-3: #d1d5db;
  --link: #2563eb;
  --link-hover: #1d4ed8;
  --link-visited: #7c3aed;
  --border: #d1d5db;
  --border-light: #e2e8f0;
  --border-subtle: #e5e7eb;
  --code-bg: #f1f5f9;
  --pre-bg: #1e293b;
  --pre-src: #fff;
  --pre-text: #e2e8f0;
  --pre-example-bg: #f8fafc;
  --pre-example-border: #e2e8f0;
  --pre-example-text: #334155;
  --toc-bg: #f1f5f9;
  --toc-text: #4b5563;
  --toc-text-hover: #111;
  --blockquote-border: #d1d5db;
  --blockquote-text: #4b5563;
  --th-bg: #f1f5f9;
  --kbd-bg: #f1f5f9;
  --kbd-border: #d1d5db;
  --todo-bg: #fef3c7;
  --todo-text: #92400e;
  --done-bg: #d1fae5;
  --done-text: #065f46;
  --tag-bg: #e0e7ff;
  --tag-text: #3730a3;
  --target-bg: #fef9c3;
  --code-hl: #334155;
  --linenr: #94a3b8;
  --verse-border: #e5e7eb;
  --footnotes-border: #e5e7eb;
  --figure-text: #6b7280;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1729;
    --text: #e2e8f0;
    --heading: #f1f5f9;
    --muted: #94a3b8;
    --muted-2: #64748b;
    --muted-3: #475569;
    --link: #60a5fa;
    --link-hover: #93c5fd;
    --link-visited: #a78bfa;
    --border: #334155;
    --border-light: #475569;
    --border-subtle: #334155;
    --code-bg: #334155;
    --pre-bg: #091323;
    --pre-text: #e2e8f0;
    --pre-example-bg: #1e293b;
    --pre-example-border: #334155;
    --pre-example-text: #cbd5e1;
    --toc-bg: #1e293b;
    --toc-text: #94a3b8;
    --toc-text-hover: #f1f5f9;
    --blockquote-border: #475569;
    --blockquote-text: #94a3b8;
    --th-bg: #1e293b;
    --kbd-bg: #1e293b;
    --kbd-border: #475569;
    --todo-bg: #78350f;
    --todo-text: #fde68a;
    --done-bg: #064e3b;
    --done-text: #a7f3d0;
    --tag-bg: #312e81;
    --tag-text: #c7d2fe;
    --target-bg: #713f12;
    --code-hl: #475569;
    --linenr: #64748b;
    --verse-border: #334155;
    --footnotes-border: #334155;
    --figure-text: #94a3b8;
  }

}

:root.light {
  --bg: #fafaf8;
  --text: #1a1a1a;
  --heading: #111;
  --muted: #6b7280;
  --muted-2: #9ca3af;
  --muted-3: #d1d5db;
  --link: #2563eb;
  --link-hover: #1d4ed8;
  --link-visited: #7c3aed;
  --border: #d1d5db;
  --border-light: #e2e8f0;
  --border-subtle: #e5e7eb;
  --code-bg: #f1f5f9;
  --pre-bg: #1e293b;
  --pre-text: #e2e8f0;
  --pre-example-bg: #f8fafc;
  --pre-example-border: #e2e8f0;
  --pre-example-text: #334155;
  --toc-bg: #f1f5f9;
  --toc-text: #4b5563;
  --toc-text-hover: #111;
  --blockquote-border: #d1d5db;
  --blockquote-text: #4b5563;
  --th-bg: #f1f5f9;
  --kbd-bg: #f1f5f9;
  --kbd-border: #d1d5db;
  --todo-bg: #fef3c7;
  --todo-text: #92400e;
  --done-bg: #d1fae5;
  --done-text: #065f46;
  --tag-bg: #e0e7ff;
  --tag-text: #3730a3;
  --target-bg: #fef9c3;
  --code-hl: #334155;
  --linenr: #94a3b8;
  --verse-border: #e5e7eb;
  --footnotes-border: #e5e7eb;
  --figure-text: #6b7280;
}

:root.dark {
  --bg: #0f172a;
  --text: #e2e8f0;
  --heading: #f1f5f9;
  --muted: #94a3b8;
  --muted-2: #64748b;
  --muted-3: #475569;
  --link: #60a5fa;
  --link-hover: #93c5fd;
  --link-visited: #a78bfa;
  --border: #334155;
  --border-light: #475569;
  --border-subtle: #334155;
  --code-bg: #334155;
  --pre-bg: #0f172a;
  --pre-text: #e2e8f0;
  --pre-example-bg: #1e293b;
  --pre-example-border: #334155;
  --pre-example-text: #cbd5e1;
  --toc-bg: #1e293b;
  --toc-text: #94a3b8;
  --toc-text-hover: #f1f5f9;
  --blockquote-border: #475569;
  --blockquote-text: #94a3b8;
  --th-bg: #1e293b;
  --kbd-bg: #1e293b;
  --kbd-border: #475569;
  --todo-bg: #78350f;
  --todo-text: #fde68a;
  --done-bg: #064e3b;
  --done-text: #a7f3d0;
  --tag-bg: #312e81;
  --tag-text: #c7d2fe;
  --target-bg: #713f12;
  --code-hl: #475569;
  --linenr: #64748b;
  --verse-border: #334155;
  --footnotes-border: #334155;
  --figure-text: #94a3b8;
}

#theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
  transition: background 0.2s, color 0.2s;
}

#theme-toggle:hover {
  background: var(--toc-bg);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 1.2em;
}

body {
  font-family: 'Crimson Pro', Georgia, 'Times New Roman', serif;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  max-width: 56rem;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

#content {
  display: grid;
  grid-template-columns: 1fr 30%;
  gap: 2rem;
  align-items: start;
}

.title, .subtitle, p.author, p.date, p.creator, div.footnotes {
  grid-column: 1 / -1;
}

div.outline-2, div.outline-3, div.outline-4 {
  grid-column: 1;
}

#table-of-contents {
  grid-column: 2;
  grid-row: 2 / 9999;
  position: sticky;
  top: 2rem;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  font-size: 0.9rem;
  padding: 1rem;
  background: var(--toc-bg);
  border-radius: 6px;
}

#table-of-contents h2 {
  font-size: 1rem;
  margin-top: 0;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

#table-of-contents ul {
  margin-bottom: 0;
  padding-left: 1.25rem;
}

#table-of-contents li {
  margin-bottom: 0.15rem;
}

#table-of-contents a {
  color: var(--toc-text);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

#table-of-contents a:hover {
  color: var(--toc-text-hover);
  border-bottom-color: var(--border);
}

/* Below 1400px the 30% sidebar stops being wide enough to read, so the
   ToC becomes a slide-in overlay driven by toc.js. Both the button and the
   backdrop are created by that script - without it, .js-toc is never set and
   the ToC just stacks at the top of the page. */
#toc-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 103;
  width: 2.25rem;
  height: 2.25rem;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: background 0.2s, color 0.2s;
}

#toc-toggle:hover {
  background: var(--toc-bg);
}

#toc-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 101;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

@media (max-width: 1400px) {
  #content {
    display: block;
  }

  #table-of-contents {
    position: static;
    max-height: none;
    margin-bottom: 2rem;
  }

  .js-toc #toc-toggle,
  .js-toc #toc-backdrop {
    display: flex;
  }

  .js-toc.toc-open #toc-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .js-toc #table-of-contents {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 102;
    width: min(20rem, 85vw);
    margin-bottom: 0;
    padding: 3.5rem 1.25rem 1.5rem;
    border-radius: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.18);
    transform: translateX(100%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0s linear 0.25s;
  }

  .js-toc.toc-open #table-of-contents {
    transform: none;
    visibility: visible;
    transition: transform 0.25s ease, visibility 0s;
  }
}

@media (prefers-reduced-motion: reduce) {
  #toc-backdrop,
  .js-toc #table-of-contents,
  .js-toc.toc-open #table-of-contents {
    transition: none;
  }
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  margin-top: 2rem;
  margin-bottom: 0.5rem;
  color: var(--heading);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.35rem; }
h4 { font-size: 1.15rem; }

p {
  font-size: 1.1em;
  margin-bottom: 1rem;
}

a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--link-hover);
}

a:visited {
  color: var(--link-visited);
}

img {
  max-width: 100%;
  height: auto;
}

blockquote {
  border-left: 3px solid var(--blockquote-border);
  margin: 1.5rem 0;
  padding: 0.5rem 1rem;
  color: var(--blockquote-text);
  font-style: italic;
}

ul, ol {
  margin-bottom: 1rem;
  padding-left: 2rem;
}

li {
  margin-bottom: 0.25rem;
}

code, pre {
  font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
  font-size: 0.875em;
}

code {
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

pre {
  background: var(--pre-bg);
  /* color: var(--pre-text); */
  padding: 1rem 1.25rem;
  border-radius: 6px;
  overflow-x: auto;
  line-height: 1.5;
  margin: 1.25rem 0;
}

pre code {
  background: none;
  padding: 0;
  border-radius: 0;
}

kbd {
  background: var(--kbd-bg);
  border: 1px solid var(--kbd-border);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-size: 0.85em;
  font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
}

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.25rem 0;
  font-size: 0.95em;
}

th, td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.75rem;
  text-align: left;
}

th {
  background: var(--th-bg);
  font-weight: 600;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

.title {
  font-size: 2.25rem;
  font-weight: 700;
  margin: 1rem 0 0.25rem;
  color: var(--heading);
  line-height: 0.8;
}

.subtitle {
  font-size: 1.25rem;
  font-weight: 400;
  color: var(--muted);
  margin-top: -0.25rem;
  margin-bottom: 1.5rem;
}

p.author, p.date, p.creator {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

p.creator {
  font-size: 0.8rem;
}

.todo {
  display: inline-block;
  background: var(--todo-bg);
  color: var(--todo-text);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1em 0.5em;
  border-radius: 3px;
}

.done {
  display: inline-block;
  background: var(--done-bg);
  color: var(--done-text);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1em 0.5em;
  border-radius: 3px;
}

.timestamp {
  color: var(--muted);
  font-size: 0.85rem;
  font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
}

.timestamp-kwd {
  color: var(--link);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
}

.timestamp-wrapper {
  display: block;
  margin: 0.5rem 0;
}

.tag {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1em 0.45em;
  border-radius: 3px;
  margin-left: 0.35em;
}

.target {
  background: var(--target-bg);
  padding: 0.1em 0.2em;
  border-radius: 2px;
}

.linenr {
  color: var(--linenr);
  font-style: normal;
  user-select: none;
}

.code-highlighted {
  background: var(--code-hl);
}

div.outline-2 { margin-top: 1.5rem; }

/* A rule between posts. The first post is left alone - it already sits under
   the site title, and in the grid layout the border spans the text column
   only, not the ToC beside it. */
div.outline-2 + div.outline-2 {
  margin-top: 8.5rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--border);
}

div.outline-2 + div.outline-2 > h2 {
  margin-top: 0;
}
div.outline-3 { margin-top: 1rem; }
div.outline-4 { margin-top: 0.75rem; }

.outline-text-2,
.outline-text-3,
.outline-text-4 {
  margin-left: 0;
}

.section-number-2 { color: var(--muted); margin-right: 0.3em; }
.section-number-3 { color: var(--muted-2); margin-right: 0.3em; }
.section-number-4 { color: var(--muted-3); margin-right: 0.3em; }

.figure-number,
.table-number,
.listing-number {
  font-weight: 600;
  color: var(--muted);
}

div.figure {
  margin: 1.5rem 0;
  text-align: center;
}

div.figure p {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--figure-text);
  font-style: italic;
}

pre.src {
  position: relative;
  color: var(--pre-src);
}

pre.example {
  background: var(--pre-example-bg);
  border: 1px solid var(--pre-example-border);
  color: var(--pre-example-text);
}

p.verse {
  font-style: italic;
  padding-left: 2rem;
  border-left: 2px solid var(--verse-border);
}

div.footnotes {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--footnotes-border);
  font-size: 0.9rem;
}

div.footnotes h2 {
  font-size: 1.25rem;
}

p.footnote {
  margin-bottom: 0.5rem;
}

.footref, .footnum {
  font-size: 0.8rem;
  vertical-align: super;
  line-height: 0;
}

.footref a, .footnum a {
  color: var(--link);
  text-decoration: none;
}

.footref a:hover, .footnum a:hover {
  text-decoration: underline;
}

.org-svg {
  display: inline-block;
}
