/* ============================================================
   QMCkl site theme
   rustdoc tokens (verified from docs.rs, rustdoc 1.101 nightly)
   x Misanthrope minimalism. Zero JavaScript:
   - dark mode = prefers-color-scheme only
   - code highlighted at build time (Pygments classes below)
   - math is native MathML rendered at build time (latex2mathml)
   ============================================================ */

/* ---------- fonts (self-hosted, SIL OFL) ---------- */
@font-face { font-family: "Source Serif 4"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/SourceSerif4-400.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/SourceSerif4-600.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/SourceSerif4-700.woff2") format("woff2"); }
@font-face { font-family: "Source Code Pro"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/SourceCodePro-400.woff2") format("woff2"); }
@font-face { font-family: "Source Code Pro"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/SourceCodePro-600.woff2") format("woff2"); }

:root {
  color-scheme: light dark;
  --font-body: "Source Serif 4", Georgia, "DejaVu Serif", serif;
  --font-head: "Fira Sans", Arial, "Helvetica Neue", sans-serif;
  --font-code: "Source Code Pro", "DejaVu Sans Mono", monospace;

  /* rustdoc light */
  --bg: #fff;
  --text: #000;
  --muted: #555;
  --border: #e0e0e0;
  --border-head: #ddd;
  --link: #3873ad;
  --sidebar-bg: #f5f5f5;
  --sidebar-hover: #e0e0e0;
  --sidebar-link: #356da4;
  --code-bg: #eaeaea;
  --code-text: #242424;
  --code-link: #2d5a8c;
  --table-alt: #f5f5f5;
  --kbd-bg: #fafbfc;
  --kbd-shadow: #c6cbd1;
  --warn: #ff8e00;

  /* semantic item colors (rustdoc light) */
  --c-type: #ad378a;
  --c-trait: #6e4fc9;
  --c-fn: #ad7c37;
  --c-macro: #068000;
  --c-keyword: #3873ad;

  /* code tokens (rustdoc light, darkened for WCAG AA on --code-bg) */
  --t-kw: #7a4d96;
  --t-kw2: #35609f;
  --t-num: #556900;
  --t-str: #556900;
  --t-lit: #c82829;
  --t-cmt: #666864;
  --t-doc: #4d4d4c;

  /* layout */
  --gutter: clamp(1.25rem, 4vw, 3rem);
  --measure: 76ch;
  --side-w: 20rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* rustdoc dark */
    --bg: #353535;
    --text: #ddd;
    --muted: #b5b5b5;
    --border: #4a4a4a;
    --border-head: #d2d2d2;
    --link: #d2991d;
    --sidebar-bg: #464646;
    --sidebar-hover: #545454;
    --sidebar-link: #fdbf35;
    --code-bg: #2a2a2a;
    --code-text: #ddd;
    --code-link: #d2991d;
    --table-alt: #1d1d1d;
    --kbd-bg: #314559;
    --kbd-shadow: #c6cbd1;

    --c-type: #2dbfb8;
    --c-trait: #b78cf2;
    --c-fn: #2bab63;
    --c-macro: #09bd00;
    --c-keyword: #d2991d;

    --t-kw: #ab8ac1;
    --t-kw2: #769acb;
    --t-num: #83a300;
    --t-str: #83a300;
    --t-lit: #ee6868;
    --t-cmt: #9a9a98;
    --t-doc: #8ca375;
  }
}

/* ---------- reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html {
  font-size: 18px; /* base: everything rem-based scales from here */
  -webkit-text-size-adjust: 100%;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-inline-size: 100%; }

/* ---------- typography ---------- */
h1, h2, h3, h4 {
  font-family: var(--font-head);
  font-weight: 600;
  line-height: 1.15;
}
h1 { font-size: 2.1rem; margin-bottom: 0.35em; }
h2 {
  font-size: 1.5rem;
  margin: 2.2em 0 0.6em;
  padding-bottom: 0.3em;
  border-bottom: 2px solid var(--border-head);
}
h3 { font-size: 1.25rem; margin: 1.6em 0 0.5em; }
h4 { font-size: 1.1rem; margin: 1.4em 0 0.4em; }
p { margin: 0.9em 0; max-inline-size: var(--measure); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: var(--font-code);
  font-size: 0.9em;
  background: var(--sidebar-bg);
  border-radius: 3px;
  padding: 0.1em 0.35em;
}
ul, ol { padding-inline-start: 1.4em; }
li { margin: 0.3em 0; max-inline-size: calc(var(--measure) - 1.4em); }
kbd {
  font-family: var(--font-head);
  font-size: 0.85em;
  background: var(--kbd-bg);
  border-radius: 4px;
  padding: 0.15em 0.45em;
  box-shadow: 0 1px 0 var(--kbd-shadow);
}
blockquote {
  margin: 1.2em 0;
  padding: 0.2em 0 0.2em 1em;
  border-inline-start: 3px solid var(--border-head);
  color: var(--muted);
}
hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }

/* section numbers (org) */
.section-number-2, .section-number-3, .section-number-4 {
  color: var(--muted);
  font-weight: 400;
  margin-inline-end: 0.4em;
}

/* ---------- code blocks (rustdoc style, Pygments classes) ---------- */
figure.code {
  margin: 1.4em 0;
  background: var(--code-bg);
  border-radius: 4px;
  position: relative;
  /* as wide as the widest line: text column for short code, wider for
     long lines, capped at the content column (then the pre scrolls) */
  width: fit-content;
  min-inline-size: var(--measure);
  max-inline-size: 100%;
}
figure.code .lang {
  position: absolute; top: 0.35rem; right: 0.7em;
  font-family: var(--font-head);
  font-size: 0.72rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em;
}
figure.code .lang a {
  color: var(--code-link);
  text-transform: none; letter-spacing: 0;
  text-decoration: none;
}
figure.code .lang a:hover { text-decoration: underline; }
figure.code pre {
  padding: 1.1em 1.2em;
  overflow-x: auto;
  line-height: 1.5;
  tab-size: 4;
}
figure.code code {
  background: none; padding: 0;
  font-family: var(--font-code);
  font-size: 0.95em; color: var(--code-text);
}
.org-src-container { display: contents; }

/* Pygments token classes -> rustdoc token colors.
   Scoped to `code`: the <pre> carries the language as a class token
   (src-c), which must not be matched by token selectors like .c */
.code code .k, .code code .kc, .code code .kd, .code code .kn, .code code .kp, .code code .kr { color: var(--t-kw); }
.code code .kt { color: var(--c-type); }
.code code .na, .code code .nf { color: var(--t-kw2); }
.code code .nb, .code code .bn, .code code .no { color: var(--t-kw2); }
.code code .bp { color: var(--t-lit); }
.code code .s, .code code .s1, .code code .s2, .code code .sc, .code code .sb, .code code .sd, .code code .ss, .code code .sa, .code code .sf, .code code .sr, .code code .sx, .code code .si, .code code .se, .code code .sh { color: var(--t-str); }
.code code .m, .code code .mi, .code code .mf, .code code .mh, .code code .mo, .code code .il { color: var(--t-num); }
.code code .l, .code code .ld, .code code .b, .code code .bb, .code code .bc { color: var(--t-lit); }
.code code .o, .code code .ow { color: var(--text); }
.code code .c, .code code .c1, .code code .cm, .code code .cp, .code code .cs, .code code .c2 { color: var(--t-cmt); }
.code code .err { color: var(--t-lit); text-decoration: underline; }

/* ---------- math (native MathML, rendered at build time) ---------- */
math { font-size: 1.08em; }
.math-inline { white-space: nowrap; }
.math-display {
  margin: 1.4em 0;
  overflow-x: auto;
  overflow-y: hidden;
  text-align: center;
  /* same as figure.code: text column for small equations, as wide as the
     equation for wide ones, capped at the content column */
  width: fit-content;
  min-inline-size: var(--measure);
  max-inline-size: 100%;
}
.math-raw { color: var(--t-lit); background: none; font-size: 0.9em; }

/* ---------- tables (rustdoc style) ---------- */
table { border-collapse: collapse; margin: 1.4em 0; }
th, td {
  border: 1px solid var(--border-head);
  padding: 0.45em 0.9em;
  text-align: left;
}
th { background: var(--sidebar-bg); font-family: var(--font-head); font-weight: 600; }
th[scope="row"] { background: none; font-weight: 400; }
tbody tr:nth-child(even) { background: var(--table-alt); }

/* ---------- figures ---------- */
.figure { margin: 1.5em 0; }
.figure .caption { color: var(--muted); font-size: 0.9rem; margin-top: 0.5em; }

/* ============================================================
   Docs layout: rustdoc-style fixed sidebar + content
   ============================================================ */
.layout { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0;
  align-self: start;
  max-height: 100vh;
  overflow-y: auto;
  background: var(--sidebar-bg);
  border-inline-end: 1px solid var(--border-head);
  padding: 1.1rem 0.4rem 2rem;
  font-family: var(--font-head);
  font-size: 0.9rem;
}
.side-brand {
  padding: 0 1em 0.8em;
  font-size: 1.05rem; font-weight: 600;
  border-bottom: 1px solid var(--border-head);
  margin-bottom: 0.6em;
}
.side-brand a { color: var(--text); }
.side-nav ul, .side-toc ul { list-style: none; padding: 0; }
.side-nav li { margin: 0; }
.side-nav a {
  display: block;
  padding: 0.28em 1em;
  color: var(--sidebar-link);
  border-radius: 4px;
}
.side-nav a:hover { background: var(--sidebar-hover); text-decoration: none; }
.side-nav a[aria-current="page"] {
  font-weight: 600;
  color: var(--text);
  background: var(--sidebar-hover);
}
.side-toc { margin-top: 1.4em; border-top: 1px solid var(--border-head); padding-top: 0.8em; }
.side-toc-title {
  font-size: 0.8rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0 1em 0.4em;
}
.side-toc ul ul { padding-inline-start: 1em; }
.side-toc a { color: var(--sidebar-link); display: block; padding: 0.2em 1em; border-radius: 4px; }
.side-toc a:hover { background: var(--sidebar-hover); text-decoration: none; }
/* org TOC markup, restyled */
#table-of-contents h2 { display: none; }

main#content {
  padding: 1.6rem var(--gutter) 4rem;
  min-width: 0;
}
.doc-head { margin-bottom: 0.5em; }
.doc-head .title {
  font-family: var(--font-head);
  font-size: 2.1rem; font-weight: 600;
  border-bottom: 2px solid var(--border-head);
  padding-bottom: 0.4em;
}
main#content > div:first-of-type { margin-top: 0.6em; }

/* org outline containers keep ids but no visual role */
.outline-2, .outline-3, .outline-4 { margin: 0; }
.outline-text-2 p, .outline-text-3 p, .outline-text-4 p { max-inline-size: var(--measure); }

/* ============================================================
   Landing page
   ============================================================ */
.wrap { padding-inline: var(--gutter); max-inline-size: 52rem; margin-inline: auto; }
header.site {
  padding-block: 2.2rem 1.2rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
header.site .role { color: var(--muted); font-size: 1.05rem; }
header.site .affil { color: var(--muted); font-size: 0.95rem; }
header.site nav { margin-top: 0.9em; font-family: var(--font-head); font-size: 0.95rem; }
header.site nav a { margin-inline-end: 1.1em; }
.hero { padding: 2.6rem 0 0.6rem; }
.hero .logo { float: right; width: 9.5rem; margin: 0.3rem 0 0.8rem 1.4rem; }
.hero h1 { font-family: var(--font-head); font-size: 2.5rem; margin-bottom: 0.2em; }
.hero .tagline { color: var(--muted); font-size: 1.15rem; max-inline-size: 46ch; }
.badges { margin-top: 1.1rem; font-family: var(--font-head); font-size: 0.85rem; }
.badges span {
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15em 0.8em;
  margin-inline-end: 0.5em;
  color: var(--muted);
}
footer.site {
  margin-top: 3rem; padding-block: 1.2rem 2rem;
  border-top: 1px solid var(--border);
  color: var(--muted); font-size: 0.9rem;
}

/* documentation index (rustdoc item list) */
.doclist { list-style: none; padding: 0; margin-top: 1em; }
.doclist li {
  margin: 0;
  padding: 0.6em 0;
  border-bottom: 1px solid var(--border);
}
.doclist .fn {
  font-family: var(--font-code);
  font-size: 0.95em;
  font-weight: 600;
  color: var(--c-keyword);
}
.doclist .fn::before { content: "§ "; color: var(--muted); font-weight: 400; }
.doclist .desc { color: var(--muted); margin-top: 0.15em; max-inline-size: 60ch; }

/* ---------- no-JS / reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- narrow windows: keep the sidebar on the left, shrink it ---------- */
@media (min-width: 36rem) and (max-width: 48rem) {
  :root { --side-w: 15rem; }
}

/* ---------- very narrow: stack the sidebar on top ---------- */
@media (max-width: 36rem) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    max-height: none;
    border-inline-end: 0;
    border-bottom: 1px solid var(--border-head);
  }
  .side-toc { display: none; } /* page TOC is less useful stacked; anchors still work */
  main#content { padding-inline: 1.2rem; }
  .hero .logo { display: none; }
}
