/* The documentation theme.
 *
 * Colours are declared once as custom properties, and everything else is
 * written against them, so a site re-themes itself by changing the first block
 * rather than by rewriting the rules below it.
 */

:root {
  color-scheme: light dark;

  --ink: #1a1d21;
  --ink-soft: #4a5158;
  --ink-faint: #6b7278;
  --surface: #ffffff;
  --surface-sunken: #f6f7f9;
  --surface-raised: #ffffff;
  --line: #e3e6ea;
  --line-strong: #cfd4da;
  --accent: #1f5f9c;
  --accent-soft: #1f5f9c14;
  --accent-line: #1f5f9c40;

  --note: #1f5f9c;
  --note-wash: #eef5fb;
  --tip: #0f766e;
  --tip-wash: #ecfdf7;
  --warning: #a45b00;
  --warning-wash: #fdf6e6;
  --danger: #b3261e;
  --danger-wash: #fbeceb;

  --code-bg: #f6f7f9;
  --code-line: #e3e6ea;
  --code-ink: #24292f;

  --measure: 46rem;
  --sidebar-width: 17rem;
  --rail-width: 15rem;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e6e8ea;
    --ink-soft: #b6bcc2;
    --ink-faint: #8b9299;
    --surface: #14171a;
    --surface-sunken: #1a1e22;
    --surface-raised: #1f2429;
    --line: #2a3036;
    --line-strong: #3a4249;
    --accent: #79b8f3;
    --accent-soft: #79b8f31f;
    --accent-line: #79b8f34d;

    --note: #79b8f3;
    --note-wash: #16232e;
    --tip: #5eead4;
    --tip-wash: #10272444;
    --warning: #fbbf24;
    --warning-wash: #2b2411;
    --danger: #f87171;
    --danger-wash: #2c1616;

    --code-bg: #1a1e22;
    --code-line: #2a3036;
    --code-ink: #d6dae0;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- header - */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.5rem;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--line);
}

.site-title {
  font-weight: 650;
  font-size: 1.05rem;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.site-title:hover { color: var(--accent); }

.site-project {
  color: var(--ink-faint);
  font-size: 0.9rem;
  white-space: nowrap;
}

.version { color: var(--ink-faint); }

.search { margin-left: auto; position: relative; }

.search input {
  width: 15rem;
  max-width: 40vw;
  padding: 0.4rem 0.7rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
}

.search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#rho-doc-results {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  width: 26rem;
  max-width: 80vw;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14);
}

#rho-doc-results.visible { display: block; }

#rho-doc-results a {
  display: block;
  padding: 0.5rem 0.75rem;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
}

#rho-doc-results a:hover, #rho-doc-results a:focus { background: var(--surface-sunken); }

#rho-doc-results .result-section { display: block; color: var(--ink-faint); font-size: 0.75rem; }
#rho-doc-results .empty { padding: 0.7rem 0.75rem; color: var(--ink-faint); }

.menu-toggle {
  display: none;
  font-size: 1.1rem;
  padding: 0.25rem 0.5rem;
  color: var(--ink);
  background: none;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  cursor: pointer;
}

/* ----------------------------------------------------------------- layout - */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--rail-width);
  align-items: start;
  gap: 2.5rem;
  max-width: 90rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ----------------------------------------------------------------- menu - */

.sidebar {
  position: sticky;
  top: 4rem;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  padding: 1.75rem 0 3rem;
  border-right: 1px solid var(--line);
  padding-right: 1rem;
}

.nav-group { margin-bottom: 1.5rem; }

.nav-title {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

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

.nav-link {
  display: block;
  padding: 0.2rem 0.55rem;
  margin-left: -0.55rem;
  color: var(--ink-soft);
  text-decoration: none;
  border-left: 2px solid transparent;
  border-radius: 0 0.3rem 0.3rem 0;
}

.nav-link:hover { color: var(--accent); background: var(--accent-soft); }

/* The page being read, marked in the menu. A reader who has followed a
   reference needs to see where they are in the tree. */
.nav-link.current {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.nav-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0 0.35em;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
  border: 1px solid var(--line-strong);
  border-radius: 0.5rem;
  vertical-align: 0.08em;
}

/* ------------------------------------------------------------------ page - */

.page {
  min-width: 0;
  max-width: var(--measure);
  padding: 2rem 0 4rem;
}

.page h1 {
  margin: 0 0 1.25rem;
  font-size: 2.1rem;
  line-height: 1.2;
  letter-spacing: -0.015em;
}

.page h2 {
  margin: 2.75rem 0 0.9rem;
  padding-bottom: 0.3rem;
  font-size: 1.5rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
  border-bottom: 1px solid var(--line);
}

.page h3 { margin: 2rem 0 0.7rem; font-size: 1.2rem; line-height: 1.35; }
.page h4 { margin: 1.6rem 0 0.6rem; font-size: 1.03rem; }
.page h5, .page h6 { margin: 1.4rem 0 0.5rem; font-size: 0.95rem; color: var(--ink-soft); }

/* A heading is the anchor a reference names, so it is marked on hover. */
.page h2[id]:hover::before,
.page h3[id]:hover::before,
.page h4[id]:hover::before {
  content: "#";
  margin-left: -1.1em;
  padding-right: 0.3em;
  color: var(--line-strong);
  font-weight: 400;
}

.page p { margin: 0.85rem 0; }

.page a { color: var(--accent); text-underline-offset: 0.15em; }
.page a:hover { text-decoration: none; border-bottom: 1px solid var(--accent-line); }

.page li { margin: 0.25rem 0; }
.page li > ul, .page li > ol { margin: 0.25rem 0; }

.page hr { margin: 2.5rem 0; border: none; border-top: 1px solid var(--line); }

.site-identity { margin: 0 0 0.3rem; color: var(--ink-faint); }
.page-count { margin: 0 0 2rem; color: var(--ink-faint); font-size: 0.9rem; }

/* ------------------------------------------------------------------ code - */

code {
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 0.12em 0.35em;
  color: var(--code-ink);
  background: var(--code-bg);
  border: 1px solid var(--code-line);
  border-radius: 0.3rem;
  word-break: break-word;
}

pre {
  margin: 1rem 0;
  padding: 0.9rem 1.1rem;
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--code-line);
  border-radius: 0.6rem;
  line-height: 1.55;
}

pre code {
  padding: 0;
  font-size: 0.855rem;
  background: none;
  border: none;
  white-space: pre;
}

/* ----------------------------------------------------------------- notes - */

.admonition {
  margin: 1.25rem 0;
  padding: 0.85rem 1.1rem 0.85rem 1.1rem;
  background: var(--note-wash);
  border: 1px solid var(--accent-line);
  border-left: 4px solid var(--note);
  border-radius: 0.5rem;
}

.admonition-title {
  margin: 0 0 0.35rem;
  font-weight: 650;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--note);
}

.admonition > :last-child { margin-bottom: 0; }

.admonition.tip, .admonition.hint { background: var(--tip-wash); border-color: #0f766e40; border-left-color: var(--tip); }
.admonition.tip .admonition-title, .admonition.hint .admonition-title { color: var(--tip); }
.admonition.warning, .admonition.caution, .admonition.important, .admonition.attention {
  background: var(--warning-wash);
  border-color: #a45b0040;
  border-left-color: var(--warning);
}
.admonition.warning .admonition-title, .admonition.caution .admonition-title,
.admonition.important .admonition-title, .admonition.attention .admonition-title { color: var(--warning); }
.admonition.danger, .admonition.error { background: var(--danger-wash); border-color: #b3261e40; border-left-color: var(--danger); }
.admonition.danger .admonition-title, .admonition.error .admonition-title { color: var(--danger); }

blockquote {
  margin: 1.1rem 0;
  padding: 0.2rem 0 0.2rem 1.1rem;
  color: var(--ink-soft);
  border-left: 3px solid var(--line-strong);
}

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

/* ----------------------------------------------------------------- table - */

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

th, td {
  padding: 0.5rem 0.7rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

th {
  font-weight: 650;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--line-strong);
}

tbody tr:hover { background: var(--surface-sunken); }

table code { font-size: 0.85em; }

/* ------------------------------------------------------------------ rail - */

.rail {
  position: sticky;
  top: 4rem;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  padding: 2.25rem 0 3rem;
  font-size: 0.85rem;
}

.rail-title {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.rail ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }

.rail-link {
  display: block;
  padding: 0.15rem 0 0.15rem 0.75rem;
  color: var(--ink-soft);
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -1px;
}

.rail-link:hover { color: var(--accent); border-left-color: var(--accent); }
.rail-link.nested { padding-left: 1.5rem; font-size: 0.95em; }

/* ----------------------------------------------------------- neighbours - */

.neighbours {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  font-size: 0.94rem;
}

.neighbours a { color: var(--accent); text-decoration: none; }
.neighbours a:hover { text-decoration: underline; }
.neighbours .next { margin-left: auto; text-align: right; }

/* ----------------------------------------------------------------- index - */

.index-section { margin: 2rem 0; }
.index-section h2 { font-size: 1.2rem; border-bottom: none; margin-bottom: 0.5rem; }

.index-list { list-style: none; margin: 0; padding: 0; }
.index-list li { padding: 0.25rem 0; border-bottom: 1px solid var(--line); }
.index-list a { text-decoration: none; }
.index-list a:hover { text-decoration: underline; }
.index-module { color: var(--ink-faint); font-size: 0.82rem; margin-left: 0.4rem; }

/* ------------------------------------------------------------ responsive - */

@media (max-width: 1180px) {
  .layout { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
  .rail { display: none; }
}

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .menu-toggle { display: inline-block; order: 3; }
  .search { margin-left: 0; flex: 1; }
  .search input { width: 100%; max-width: none; }
  .sidebar {
    position: static;
    max-height: none;
    padding: 1rem 0;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .sidebar.hidden { display: none; }
  .page { padding-top: 1.25rem; }
  .page h1 { font-size: 1.7rem; }
}

@media print {
  .topbar, .sidebar, .rail, .neighbours, .search, .menu-toggle { display: none; }
  .layout { display: block; }
  .page { max-width: none; padding: 0; }
  pre, .admonition, table { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}
