:root {
  --fg: #292a25;
  --bg: #e4dcc1;
  --muted: #6f6a5d;
  --accent: #a35015;
  --border: #d2caad;
  --code-bg: #e4dcc1;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #d6d3c9;
    --bg: #291b0c;
    --muted: #aaa89f;
    --accent: #dcbe65;
    --border: #5a3f1c;
    --code-bg: #291b0c;
  }
}

html {
  font-size: 18px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--fg);
  background: var(--bg);
  font-family: helvetica, arial, sans-serif;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Centered container: header, sidebar and body share its edges. */
.page {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 64rem;
  margin: 0 auto;
  padding: 0 1.5rem;
  box-sizing: border-box;
}

/* Sidebar + content row. Grows so short pages still push the footer down. */
.layout {
  flex: 1 0 auto;
  display: flex;
}

/* Text column. Centered alone; flush to the sidebar when there is one. */
.column {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 46rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1 0 auto;
  padding: 2.5rem 0 6rem;
}

footer {
  padding: 1.5rem 0;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Sticky sidebar; align-self is what lets sticky engage. */
.sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  flex: none;
  width: 15rem;
  max-height: 100vh;
  overflow-y: auto;
  padding: 2.5rem 1.5rem 1.5rem 0;
  font-size: 0.9rem;
  box-sizing: border-box;
}

/* 'browse'/'readme' mode folder labels. */
.sidebar summary {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;  /* Safari needs the prefix; the bare one is ignored there */
  margin: 0.6rem 0 0.3rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.sidebar summary::marker {
  font-size: 0.8em;
}

/* Nested-level indent (compounds down the tree). */
.sidebar details > ul,
.sidebar details > details,
.sidebar li > ul,
.sidebar li > details {
  padding-left: 0.75rem;
}

/* 'toc' mode: flat bulleted list of the page's headings. */
.sidebar.toc {
  font-size: 0.8rem;
}

.sidebar.toc ul {
  list-style: disc;
  padding-left: 1.1rem;
}

.sidebar.toc ul ul {
  list-style: circle;
  padding-left: 1.3rem;
}

.sidebar.toc li::marker {
  color: var(--muted);
}

.sidebar .toc-title {
  margin-bottom: 0.75rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* 'readme' mode Home link. */
.sidebar .nav-home {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar li {
  margin: 0.2rem 0;
}

.sidebar ~ .column {
  margin-left: 0;
}

/* Narrow: stack sidebar above main. */
@media (max-width: 64rem) {
  .layout {
    flex-direction: column;
  }
  .sidebar {
    position: static;
    align-self: auto;
    width: auto;
    max-height: none;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
  }
  .sidebar ~ .column {
    margin-left: auto;
  }
}

/* Outbound-link bar (in normal flow, scrolls away). */
.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 1.25rem 0;
  font-size: 0.85rem;
}

.masthead .links {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
}

/* Align body's first line with the sidebar's. */
main > :first-child {
  margin-top: 0;
}

h1 {
  line-height: 1.25;
  margin-top: 2rem;
  font-family: Georgia, 'Times New Roman', Times, serif;
}

h2, h3, h4, h5 {
  line-height: 1.25;
  margin-top: 2rem;
  font-family: sans-serif
}

a {
  color: var(--accent);
}

code {
  background: var(--code-bg);
  padding: 0.15em 0.35em;
  border-radius: 3px;
  font-size: 0.9em;
}

pre {
  background: var(--code-bg);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
}

pre code {
  background: none;
  padding: 0;
}

blockquote {
  margin: 0;
  padding: 0rem 1.5rem;
  border-left: 3px solid var(--border);
}

table {
  border-collapse: collapse;
  width: 100%;
}

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

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

sup, sub {
  line-height: 0;
}

.footnote {
  font-size: 0.9rem;
  color: var(--fg);
  margin-top: 3rem;
}
