/* Layout inspired by Zed's mdBook theme: https://github.com/zed-industries/zed/tree/main/docs/theme */

:root {
  --sidebar-target-width: 280px;
  --content-max-width: 840px;
  --menu-bar-height: 56px;
  --page-padding: 0px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono-font: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", monospace;
}

/* A small documentation palette, using the editor's Modus neutrals. */
.light,
html:not(.js) {
  --color-scheme: light;
  --bg: #ffffff;
  --fg: #000000;
  --surface: #f2f2f2;
  --surface-hover: #e0e0e0;
  --muted: #595959;
  --border: #c4c4c4;
  --links: #3548cf;
  --success: #006800;
  --warning-color: #6f5500;
  --danger: #a60000;
  --shadow: rgb(0 0 0 / 16%);
}

.colibri {
  --color-scheme: dark;
  --bg: #000000;
  --fg: #ffffff;
  --surface: #1e1e1e;
  --surface-hover: #303030;
  --muted: #989898;
  --border: #535353;
  --links: #79a8ff;
  --success: #44bc44;
  --warning-color: #d0bc00;
  --danger: #ff5f59;
  --shadow: rgb(0 0 0 / 55%);
}

/* Map mdBook and component colors to the same palette in both themes. */
.light,
.colibri,
html:not(.js) {
  --full-contrast: var(--fg);
  --title-color: var(--fg);
  --border-light: var(--surface-hover);
  --border-hover: var(--muted);
  --border-footer: var(--border-light);

  --media-bg: var(--surface);
  --chrome-bg: var(--surface);
  --sidebar-bg: var(--surface);
  --sidebar-fg: var(--fg);
  --sidebar-non-existant: var(--muted);
  --sidebar-non-existent: var(--muted);
  --sidebar-active: var(--fg);
  --sidebar-item-hover-bg: var(--surface-hover);
  --sidebar-active-bg: var(--surface-hover);
  --sidebar-spacer: var(--border-light);
  --sidebar-mobile-shadow: 0 16px 32px var(--shadow);

  --scrollbar: var(--border);
  --icons: var(--muted);
  --icons-hover: var(--fg);
  --icon-btn-bg-hover: var(--surface-hover);

  --link-line-decoration: color-mix(in srgb, var(--links) 40%, transparent);
  --link-line-decoration-hover: color-mix(in srgb, var(--links) 80%, transparent);
  --inline-code-color: var(--fg);
  --code-text: var(--fg);
  --code-bg: var(--surface);
  --keybinding-bg: var(--surface-hover);

  --pre-bg: var(--surface);
  --pre-border: var(--border);
  --theme-popup-bg: var(--bg);
  --theme-popup-border: var(--border);
  --theme-hover: var(--surface-hover);
  --popover-bg: var(--bg);
  --popover-border: var(--border);
  --popover-shadow: 0 16px 40px var(--shadow);

  --quote-bg: var(--surface);
  --quote-border: var(--border);
  --warning-border: var(--warning-color);

  --table-border-color: var(--border);
  --table-header-bg: var(--surface);
  --table-alternate-bg: var(--bg);
  --table-border-line: var(--border-light);

  --searchbar-border-color: var(--border);
  --searchbar-bg: var(--bg);
  --searchbar-fg: var(--fg);
  --searchbar-shadow-color: var(--shadow);
  --searchresults-header-fg: var(--muted);
  --searchresults-border-color: var(--border);
  --searchresults-li-bg: var(--surface);
  --search-mark-bg: color-mix(in srgb, var(--links) 20%, var(--bg));

  --blockquote-note-color: var(--links);
  --blockquote-tip-color: var(--success);
  --blockquote-important-color: var(--links);
  --blockquote-warning-color: var(--warning-color);
  --blockquote-caution-color: var(--danger);
  --footnote-highlight: var(--links);
  --overlay-bg: var(--shadow);
  --sidebar-header-border-color: var(--border);
}

html {
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
}

code {
  font-family: inherit !important;
}

strong {
  color: var(--full-contrast);
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--links);
  outline-offset: 2px;
}

.page {
  margin-block-start: 0;
  padding: 0;
}

.page-wrapper {
  min-height: calc(100vh - var(--menu-bar-height));
  background-color: var(--bg);
}

#mdbook-menu-bar {
  position: sticky !important;
  top: 0 !important;
  z-index: 102;
  display: grid;
  grid-template-columns: minmax(180px, var(--sidebar-width)) minmax(220px, 300px) minmax(180px, var(--sidebar-width));
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  height: var(--menu-bar-height);
  margin: 0;
  padding: 0 16px;
  box-sizing: border-box;
  background-color: var(--chrome-bg);
  border-bottom: 1px solid var(--border-light);
}

#mdbook-menu-bar .left-buttons,
#mdbook-menu-bar .right-buttons {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
}

#mdbook-menu-bar .right-buttons {
  justify-content: flex-end;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: 4px;
  color: var(--sidebar-fg) !important;
  font-size: 1.4rem;
  font-weight: 600;
  text-decoration: none;
}

.header-brand img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

#mdbook-menu-bar .icon-button,
#mdbook-menu-bar .right-buttons a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 4px;
  color: var(--icons);
}

#mdbook-menu-bar .icon-button:hover,
#mdbook-menu-bar .right-buttons a:hover {
  color: var(--icons-hover);
  background-color: var(--icon-btn-bg-hover);
}

.menu-title {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.search-button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 30px;
  padding: 0 6px 0 10px;
  border: 1px solid var(--table-border-color);
  border-radius: 4px;
  background: var(--code-bg);
  color: var(--icons);
  font: inherit;
  font-size: 1.3rem;
  cursor: pointer;
}

.search-button:hover {
  border-color: var(--border-hover);
  background: var(--theme-hover);
  color: var(--icons-hover);
}

.search-button>.search-label {
  flex: 1;
  color: var(--fg);
  text-align: left;
}

.search-button kbd {
  padding: 2px 5px 3px;
  font-size: 1.1rem;
  line-height: 1;
}

.theme-popup {
  top: calc(var(--menu-bar-height) - 6px);
  right: 12px;
  left: auto;
  border-radius: 6px;
  box-shadow: var(--popover-shadow);
}

.sidebar {
  top: var(--menu-bar-height);
  width: var(--sidebar-width);
  background-color: transparent;
  border-right: 0;
}

.sidebar .sidebar-scrollbox {
  top: 0;
  padding: 10px 12px 28px;
  scrollbar-color: var(--scrollbar) transparent;
  scrollbar-width: thin;
}

.sidebar .sidebar-scrollbox::-webkit-scrollbar {
  width: 6px;
}

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

.sidebar .sidebar-scrollbox::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--scrollbar);
}

.sidebar .sidebar-resize-indicator {
  display: none;
}

.chapter {
  margin: 0;
  padding: 0;
  line-height: 1.5;
}

.chapter li.chapter-item {
  margin: 2px 0;
  padding: 0;
}

.chapter .chapter-link-wrapper {
  width: 100%;
}

.chapter li.chapter-item a:not(.toggle) {
  display: block;
  flex: 1;
  min-width: 0;
  padding: 6px 12px;
  box-sizing: border-box;
  border-radius: 8px;
  color: var(--sidebar-fg);
  font-size: 1.4rem;
  line-height: 1.45;
  text-decoration: none;
  transition: color .15s ease, background-color .15s ease;
}

.chapter li.chapter-item a:not(.toggle):hover {
  color: var(--sidebar-active);
  background-color: var(--sidebar-item-hover-bg);
}

.chapter li.chapter-item a.active {
  color: var(--sidebar-active);
  background-color: var(--sidebar-active-bg);
}

.chapter li.part-title {
  margin: 20px 0 8px;
  padding: 0 12px;
  color: var(--title-color);
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.5;
}

.chapter li.part-title:first-child {
  margin-top: 8px;
}

.chapter .section {
  margin: 4px 0 8px;
  padding: 0;
  border-left: 0;
}

.chapter .section li.chapter-item {
  padding: 0;
}

.content {
  display: grid;
  grid-template-columns: minmax(0, var(--content-max-width)) 190px;
  justify-content: center;
  align-items: start;
  column-gap: 40px;
  padding: 36px 32px 80px;
  box-sizing: border-box;
  overflow-y: visible;
}

/* Pages without section headings do not need a TOC column. */
.content:has(.toc-container[hidden]) {
  grid-template-columns: minmax(0, var(--content-max-width));
}

.content main {
  min-width: 0;
  width: 100%;
  max-width: var(--content-max-width);
  margin: 0;
}

.content h1,
.content h2,
.content h3,
.content h4,
.content h5,
.content h6 {
  position: relative;
  color: var(--full-contrast);
  font-family: var(--font);
  font-weight: 400;
}

.content h1 {
  margin: 0 0 1.6rem;
  color: var(--title-color);
  font-size: 3.4rem;
  font-weight: 700;
  line-height: 1.2;
}

.content h2 {
  margin: 3.2rem 0 1.4rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-light);
  font-size: 2.5rem;
}

.content h3 {
  margin: 2.8rem 0 1.2rem;
  padding-bottom: .8rem;
  border-bottom: 1px dashed var(--border-light);
  font-size: 2rem;
}

.content h4 {
  margin: 2.4rem 0 1rem;
  font-size: 1.8rem;
}

.content h5,
.content h6 {
  margin: 2rem 0 .8rem;
  font-size: 1.6rem;
}

.content h1 code,
.content h2 code,
.content h3 code,
.content h4 code,
.content h5 code,
.content h6 code {
  font-size: inherit;
}

.content .header:link,
.content .header:visited {
  color: inherit;
  text-decoration: none;
}

.content p,
.content ol,
.content ul {
  line-height: 1.7;
}

.content p {
  margin: 0 0 1.4rem;
}

.content ol,
.content ul {
  margin: 0 0 1.4rem;
  padding-left: 2em;
}

.content li+li {
  margin-top: .35rem;
}

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

.content a:hover {
  text-decoration-color: var(--link-line-decoration-hover);
}

.content img,
.content video {
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: var(--media-bg);
}

.content img.editor-screenshot {
  height: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.toc-container {
  position: sticky;
  top: calc(var(--menu-bar-height) + 32px);
  max-height: calc(100vh - var(--menu-bar-height) - 64px);
  overflow-y: auto;
  color: var(--icons);
  font-size: 1.25rem;
}

.toc-title {
  margin-bottom: 10px;
  color: var(--full-contrast);
  font-size: 1.3rem;
  font-weight: 600;
}

#page-toc {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#page-toc a {
  color: var(--icons);
  line-height: 1.35;
  text-decoration: underline;
  text-decoration-color: var(--link-line-decoration);
}

#page-toc a:hover,
#page-toc a.active {
  color: var(--links);
  text-decoration-color: var(--link-line-decoration-hover);
}

#page-toc .toc-level-3 {
  padding-left: 14px;
}

.table-wrapper {
  margin: 1.8rem 0 2.2rem;
  border: 1px solid var(--table-border-color);
  border-radius: 6px;
}

table {
  width: 100%;
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.5;
}

/* Let dense references scroll before their descriptions become narrow strips. */
table:has(th:nth-child(3)) {
  min-width: 640px;
}

table thead tr {
  border: 0;
}

table th,
table td {
  padding: 6px 12px;
  border: 0;
  text-align: left;
  vertical-align: top;
}

table th {
  color: var(--fg);
  font-weight: 600;
}

table tbody tr {
  border-top: 1px solid var(--table-border-line);
}

blockquote,
.warning {
  margin: 1.8rem 0;
  padding: 1rem 1.25rem;
  color: var(--full-contrast);
  background-color: var(--quote-bg);
  border: 1px solid var(--quote-border);
  border-radius: 4px;
}

blockquote> :last-child,
.warning> :last-child {
  margin-bottom: 0;
}

kbd {
  padding: 3px 5px 5px;
  border: 1px solid var(--popover-border);
  border-radius: 4px;
  background-color: var(--keybinding-bg);
  box-shadow: inset 0 -1px 0 var(--theme-hover);
  color: var(--full-contrast);
  font-family: inherit;
}

:not(pre)>.hljs {
  padding: .12em .35em;
  border-radius: 3px;
  color: var(--inline-code-color);
  background-color: var(--code-bg);
}

pre {
  margin: 1.8rem 0 2.2rem;
  border: 1px solid var(--pre-border);
  border-radius: 4px;
  background-color: var(--pre-bg);
}

pre,
pre code {
  font-family: var(--mono-font) !important;
}

pre code.hljs {
  display: block;
  overflow-x: auto;
  padding: 1.2rem;
  background: transparent;
}

pre>.buttons button {
  border-color: var(--border);
  background-color: var(--popover-bg);
}

#mdbook-search-wrapper:not(.hidden) {
  position: fixed;
  z-index: 1000;
  top: calc(var(--menu-bar-height) + 16px);
  left: 50%;
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - var(--menu-bar-height) - 32px);
  padding: 14px 20px 20px;
  box-sizing: border-box;
  overflow-y: auto;
  transform: translateX(-50%);
  border: 1px solid var(--popover-border);
  border-radius: 8px;
  background-color: var(--popover-bg);
  box-shadow: var(--popover-shadow);
}

#mdbook-search-wrapper .searchbar-outer,
#mdbook-search-wrapper .searchresults-outer {
  max-width: none;
}

#mdbook-searchbar {
  margin: 0;
  border-radius: 4px;
}

#mdbook-searchresults-outer {
  border-bottom: 0;
}

.nav-wide-wrapper {
  display: none !important;
}

.nav-wrapper {
  grid-column: 1;
  display: flex !important;
  gap: 12px;
  width: 100%;
  max-width: var(--content-max-width);
  margin: 48px 0 0;
}

.mobile-nav-chapters {
  float: none;
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  width: auto;
  padding: 0 12px;
  box-sizing: border-box;
  border: 1px solid var(--table-border-color);
  border-radius: 5px;
  background-color: var(--table-alternate-bg);
  color: var(--links);
  font-size: 1.3rem;
  text-decoration: none;
}

.mobile-nav-chapters:hover {
  border-color: var(--border-hover);
  background-color: var(--theme-hover);
}

.mobile-nav-chapters.next {
  margin-left: auto;
}

/* Syntax uses ordinary text, muted comments, and the link accent. */
:where(.light, .colibri, html:not(.js)) .hljs {
  color: var(--fg);
  background: transparent;
}

:where(.light, .colibri, html:not(.js)) .hljs-comment,
:where(.light, .colibri, html:not(.js)) .hljs-quote,
:where(.light, .colibri, html:not(.js)) .hljs-operator,
:where(.light, .colibri, html:not(.js)) .hljs-punctuation {
  color: var(--muted);
}

:where(.light, .colibri, html:not(.js)) .hljs-keyword,
:where(.light, .colibri, html:not(.js)) .hljs-name,
:where(.light, .colibri, html:not(.js)) .hljs-selector-tag,
:where(.light, .colibri, html:not(.js)) .hljs-tag,
:where(.light, .colibri, html:not(.js)) .hljs-meta,
:where(.light, .colibri, html:not(.js)) .hljs-built_in,
:where(.light, .colibri, html:not(.js)) .hljs-symbol,
:where(.light, .colibri, html:not(.js)) .hljs-string,
:where(.light, .colibri, html:not(.js)) .hljs-bullet,
:where(.light, .colibri, html:not(.js)) .hljs-link,
:where(.light, .colibri, html:not(.js)) .hljs-regexp,
:where(.light, .colibri, html:not(.js)) .hljs-formula,
:where(.light, .colibri, html:not(.js)) .hljs-number,
:where(.light, .colibri, html:not(.js)) .hljs-literal {
  color: var(--links);
}

:where(.light, .colibri, html:not(.js)) .hljs-attribute,
:where(.light, .colibri, html:not(.js)) .hljs-attr,
:where(.light, .colibri, html:not(.js)) .hljs-property,
:where(.light, .colibri, html:not(.js)) .hljs-params,
:where(.light, .colibri, html:not(.js)) .hljs-title,
:where(.light, .colibri, html:not(.js)) .hljs-section,
:where(.light, .colibri, html:not(.js)) .hljs-type,
:where(.light, .colibri, html:not(.js)) .hljs-class,
:where(.light, .colibri, html:not(.js)) .hljs-selector-id,
:where(.light, .colibri, html:not(.js)) .hljs-selector-class,
:where(.light, .colibri, html:not(.js)) .hljs-variable,
:where(.light, .colibri, html:not(.js)) .hljs-template-variable {
  color: var(--fg);
}

:where(.light, .colibri, html:not(.js)) .hljs-addition {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 12%, var(--surface));
}

:where(.light, .colibri, html:not(.js)) .hljs-deletion {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
}

.hljs-emphasis {
  font-style: italic;
}

.hljs-strong {
  font-weight: 700;
}

@media only screen and (max-width: 1180px) {
  .content {
    grid-template-columns: minmax(0, var(--content-max-width));
  }

  .toc-container {
    display: none;
  }
}

@media only screen and (max-width: 780px) {
  #mdbook-menu-bar {
    grid-template-columns: auto minmax(120px, 260px) auto;
    gap: 12px;
    padding: 0 12px;
  }

  #mdbook-menu-bar .right-buttons a,
  #mdbook-menu-bar .right-buttons a+a {
    display: none;
  }

  .search-button {
    max-width: 260px;
  }

  .content {
    padding: 28px 24px 64px;
  }
}

@media only screen and (max-width: 480px) {
  #mdbook-menu-bar {
    grid-template-columns: auto 34px 34px;
    gap: 8px;
    padding: 0 10px;
  }

  #mdbook-menu-bar .right-buttons {
    gap: 0;
  }

  #mdbook-menu-bar .right-buttons> :not(#mdbook-theme-toggle):not(#mdbook-theme-list) {
    display: none;
  }

  .search-button>.search-label,
  .search-button kbd {
    display: none;
  }

  .search-button {
    justify-content: center;
    width: 34px;
    justify-self: center;
    padding: 0;
  }

  .content {
    padding: 24px 16px 56px;
  }

  .content h1 {
    font-size: 3rem;
  }

  .content h2 {
    font-size: 2.3rem;
  }

  .nav-wrapper {
    flex-direction: column;
  }
}

@media print {

  #mdbook-menu-bar,
  #mdbook-sidebar,
  .toc-container,
  .nav-wrapper,
  .nav-wide-wrapper {
    display: none !important;
  }

  .page-wrapper {
    margin: 0 !important;
  }

  .content {
    display: block;
    padding: 0;
  }
}