/* dor.tools. Every color is a token below, defined for both schemes;
   src/mermaid.js reads the same tokens to draw the diagrams. */
:root {
  color-scheme: light dark;
  --bg: #fbfbf9;
  --fg: #1d1f21;
  --muted: #5c6166;
  --faint: #e7e7e2;
  --border: #c9cac4;
  --surface: #f1f1ed;
  --accent: #0b6a64;
  --accent-soft: #e0f0ee;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --measure: 44rem;
  --gutter: 1rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131517;
    --fg: #e3e4e1;
    --muted: #9ca1a6;
    --faint: #25292c;
    --border: #3b4045;
    --surface: #1c1f22;
    --accent: #62c6bd;
    --accent-soft: #17312f;
  }
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 1rem/1.65 var(--sans);
  font-kerning: normal;
}

@media (min-width: 40rem) {
  body { font-size: 1.0625rem; }
  :root { --gutter: 2rem; }
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

.skip { position: absolute; left: -999px; top: 0.5rem; }
.skip:focus { left: 0.5rem; background: var(--bg); padding: 0.25rem 0.5rem; }

/* Header and footer */

.bar, .layout {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 1.5rem;
}

header.site { border-bottom: 1px solid var(--faint); }
header.site .bar { padding-block: 0.9rem; justify-content: space-between; }
header.site a { text-decoration: none; }
header.site a:hover { text-decoration: underline; }

.brand { color: var(--fg); font-weight: 700; font-size: 1.125rem; letter-spacing: -0.01em; }
.brand::before {
  content: "";
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  margin-right: 0.45em;
  border-radius: 2px;
  background: var(--accent);
}

header.site ul { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; margin: 0; padding: 0; list-style: none; font-size: 0.9375rem; }
header.site nav a { color: var(--muted); }
header.site nav a[aria-current="page"] { color: var(--fg); font-weight: 600; }

footer.site { margin-top: 5rem; border-top: 1px solid var(--faint); color: var(--muted); font-size: 0.875rem; }
footer.site .bar { padding-block: 1.5rem 2.5rem; }
footer.site a { color: inherit; }

/* Page layout: title, then contents, then the body; on a wide screen the
   contents move to a column at the right. */

.layout {
  display: grid;
  grid-template-columns: minmax(0, var(--measure));
  grid-template-areas: "title" "toc" "body";
}

@media (min-width: 64rem) {
  .layout.has-toc {
    grid-template-columns: minmax(0, var(--measure)) 15rem;
    grid-template-areas: "title toc" "body toc";
    column-gap: 4rem;
    justify-content: start;
  }
  .has-toc .toc {
    align-self: start;
    position: sticky;
    top: 0;
    max-height: 100vh;
    overflow-y: auto;
    padding: 2.75rem 0 2rem;
    margin: 0;
    border: 0;
    background: none;
  }
}

.title {
  grid-area: title;
  margin: 2.5rem 0 1.25rem;
  font-size: clamp(1.875rem, 1.4rem + 2vw, 2.5rem);
  line-height: 1.15;
  letter-spacing: -0.025em;
  font-weight: 750;
  overflow-wrap: break-word;
}

.prose { grid-area: body; min-width: 0; }

/* Table of contents */

.toc {
  grid-area: toc;
  font-size: 0.875rem;
  line-height: 1.45;
  margin: 0 0 1.5rem;
  padding: 0.9rem 1rem 1rem;
  border: 1px solid var(--faint);
  border-radius: 8px;
  background: var(--surface);
}
.toc-title {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc ol ol { padding-left: 0.85rem; }
.toc a { display: block; padding: 0.2rem 0 0.2rem 0.75rem; border-left: 1px solid var(--border); color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--fg); border-left-color: var(--accent); }
.toc code { font-size: 0.9em; padding: 0; border: 0; background: none; }

/* Body text */

.prose > :first-child { margin-top: 0; }
.prose p, .prose li, .prose blockquote { overflow-wrap: break-word; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose figure, .prose pre, .prose .scroll { margin: 0 0 1.15rem; }

.prose h2, .prose h3 { line-height: 1.25; letter-spacing: -0.015em; scroll-margin-top: 1rem; }
.prose h2 { font-size: 1.5rem; font-weight: 700; margin: 3rem 0 1rem; padding-top: 1.5rem; border-top: 1px solid var(--faint); }
.prose h3 { font-size: 1.1875rem; font-weight: 650; margin: 2.25rem 0 0.75rem; }

.anchor { margin-left: 0.4em; color: var(--muted); text-decoration: none; opacity: 0; }
.anchor::before { content: "#"; }
:hover > .anchor, .anchor:focus-visible { opacity: 1; }

.prose ul, .prose ol { padding-left: 1.4rem; }
.prose li + li { margin-top: 0.35rem; }
.prose li > p { margin: 0; }
.prose li::marker { color: var(--muted); }

.prose blockquote {
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  background: var(--accent-soft);
}
.prose blockquote > :last-child { margin-bottom: 0; }

.prose strong { font-weight: 650; }

/* Code */

code, pre { font-family: var(--mono); }
:not(pre) > code {
  font-size: 0.875em;
  padding: 0.1em 0.3em;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--faint);
}
pre {
  overflow-x: auto;
  padding: 0.85rem 1rem;
  border: 1px solid var(--faint);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.875rem;
  line-height: 1.55;
  tab-size: 2;
}

/* Tables scroll inside their own box */

.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; line-height: 1.5; }
th, td { padding: 0.55rem 1rem 0.55rem 0; text-align: left; vertical-align: top; }
th:last-child, td:last-child { padding-right: 0; }
th { font-weight: 650; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { border-bottom: 1px solid var(--faint); min-width: 6rem; }
td:last-child { min-width: 12rem; }

/* Diagrams: the source until src/mermaid.js draws it */

.diagram-view {
  overflow-x: auto;
  padding: 0.75rem;
  border: 1px solid var(--faint);
  border-radius: 8px;
}
.diagram-view svg { display: block; margin: 0 auto; height: auto; }
.diagram details { margin-top: 0.4rem; font-size: 0.875rem; }
.diagram summary { color: var(--muted); cursor: pointer; width: max-content; }
.diagram details pre { margin: 0.5rem 0 0; }
