/* Module Documentation viewer.
   Hand-written, no build step. The .md files are the source of truth; this
   stylesheet only dresses what marked renders. */

:root {
  --bg:        #ffffff;
  --bg-soft:   #f6f7f9;
  --bg-sunk:   #eef0f3;
  --fg:        #1c1f23;
  --fg-soft:   #5b636d;
  --fg-faint:  #868e99;
  --rule:      #e2e5ea;
  --rule-firm: #cfd4dc;
  --accent:    #c8102e;
  --accent-sv: #9c0d24;
  --link:      #0b5bd3;
  --code-bg:   #f3f4f6;
  --mark:      #fff3b0;
  --sidebar-w: 19rem;
  --aside-w:   14rem;
  --topbar-h:  3.5rem;
  --measure:   46rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #15181c;
    --bg-soft:   #1b1f24;
    --bg-sunk:   #22272d;
    --fg:        #e6e8eb;
    --fg-soft:   #a8b0ba;
    --fg-faint:  #7b838e;
    --rule:      #2b3137;
    --rule-firm: #3a424a;
    --accent:    #ff5a70;
    --accent-sv: #ff8292;
    --link:      #7ab3ff;
    --code-bg:   #1f242a;
    --mark:      #5a4a00;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent); }

.muted { color: var(--fg-faint); }
.mono  { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .875em; }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 50;
  background: var(--accent); color: #fff; padding: .6rem 1rem;
}
.skip:focus { left: 0; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}

.topbar__nav {
  display: none;
  width: 2.25rem; height: 2.25rem; flex: 0 0 auto;
  background: none; border: 1px solid var(--rule-firm); border-radius: 6px;
  cursor: pointer; padding: .5rem .45rem;
  flex-direction: column; justify-content: space-between;
}
.topbar__nav span { display: block; height: 2px; background: var(--fg-soft); border-radius: 2px; }

.topbar__home { text-decoration: none; color: inherit; display: block; min-width: 0; }
.topbar__home strong {
  display: block; font-size: .95rem; letter-spacing: .01em;
  border-left: 3px solid var(--accent); padding-left: .6rem;
}
.topbar__home span {
  display: block; font-size: .75rem; color: var(--fg-faint); padding-left: .6rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.search { margin-left: auto; position: relative; display: flex; align-items: center; }
.search input {
  width: 15rem; max-width: 40vw;
  padding: .45rem 2.1rem .45rem .7rem;
  font: inherit; font-size: .875rem;
  color: var(--fg); background: var(--bg-soft);
  border: 1px solid var(--rule-firm); border-radius: 6px;
}
.search input:focus { outline: 2px solid var(--link); outline-offset: 1px; background: var(--bg); }
.search kbd {
  position: absolute; right: .5rem; pointer-events: none;
  font: inherit; font-size: .7rem; color: var(--fg-faint);
  border: 1px solid var(--rule-firm); border-radius: 4px;
  padding: 0 .3rem; line-height: 1.3;
}
.search input:focus ~ kbd, .search input:not(:placeholder-shown) ~ kbd { display: none; }

/* ----------------------------------------------------------------- shell */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--aside-w);
  align-items: start;
}

.sidebar {
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg-soft);
  border-right: 1px solid var(--rule);
}
.sidebar__inner { padding: 1.25rem 1rem 4rem; }

.sidebar h2 {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--fg-faint); margin: 1.6rem 0 .4rem;
}
.sidebar h2:first-child { margin-top: 0; }
.sidebar h3 {
  font-size: .72rem; font-weight: 600; letter-spacing: .04em;
  color: var(--fg-soft); margin: 1rem 0 .25rem;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { margin: 0; }
.sidebar a {
  display: block; padding: .3rem .55rem; border-radius: 5px;
  color: var(--fg-soft); text-decoration: none; font-size: .875rem;
  border-left: 2px solid transparent;
}
.sidebar a:hover { background: var(--bg-sunk); color: var(--fg); }
.sidebar a[aria-current="page"] {
  background: var(--bg); color: var(--fg); font-weight: 600;
  border-left-color: var(--accent);
}
.sidebar .tag {
  font-size: .65rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--fg-faint); margin-left: .4rem; font-weight: 400;
}
.sidebar a.is-hidden { display: none; }

/* ------------------------------------------------------------------ main */

.main { min-width: 0; padding: 2.5rem 3rem 6rem; }
.doc  { max-width: var(--measure); }
.doc:focus { outline: none; }

.docfoot {
  max-width: var(--measure); margin-top: 4rem;
  padding-top: 1rem; border-top: 1px solid var(--rule);
  font-size: .8rem; color: var(--fg-faint);
}
.docfoot p { margin: 0; }

/* ------------------------------------------------------- rendered markdown */

.doc > :first-child { margin-top: 0; }

.doc h1 {
  font-size: 2rem; line-height: 1.2; letter-spacing: -.01em;
  margin: 0 0 1.5rem; padding-bottom: .75rem;
  border-bottom: 1px solid var(--rule);
}
.doc h2 {
  font-size: 1.35rem; line-height: 1.3; margin: 2.75rem 0 .75rem;
  padding-top: .5rem;
}
.doc h3 { font-size: 1.08rem; margin: 2rem 0 .5rem; }
.doc h4 { font-size: .95rem; margin: 1.5rem 0 .4rem; color: var(--fg-soft); }

.doc h1, .doc h2, .doc h3, .doc h4 { scroll-margin-top: calc(var(--topbar-h) + 1rem); }

.anchor {
  float: left; margin-left: -1.1rem; width: 1.1rem;
  text-align: left; text-decoration: none; color: var(--fg-faint);
  opacity: 0; font-weight: 400;
}
h1:hover .anchor, h2:hover .anchor, h3:hover .anchor, h4:hover .anchor,
.anchor:focus { opacity: 1; }

.doc p, .doc ul, .doc ol { margin: 0 0 1.1rem; }
.doc li { margin: .3rem 0; }
.doc li > ul, .doc li > ol { margin: .3rem 0 .3rem; }

.doc blockquote {
  margin: 1.2rem 0; padding: .1rem 0 .1rem 1.1rem;
  border-left: 3px solid var(--rule-firm);
  color: var(--fg-soft);
}
.doc blockquote p:last-child { margin-bottom: 0; }

.doc hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

.doc code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .86em;
  background: var(--code-bg); border: 1px solid var(--rule);
  border-radius: 4px; padding: .1em .35em;
}
.doc pre {
  background: var(--code-bg); border: 1px solid var(--rule); border-radius: 8px;
  padding: .9rem 1rem; overflow-x: auto; margin: 0 0 1.2rem;
  font-size: .86rem; line-height: 1.55;
}
.doc pre code { background: none; border: 0; padding: 0; font-size: 1em; }

.doc table {
  border-collapse: collapse; width: 100%; margin: 0 0 1.4rem;
  font-size: .9rem; display: block; overflow-x: auto;
}
.doc thead th {
  text-align: left; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--fg-soft);
  border-bottom: 2px solid var(--rule-firm); padding: .5rem .7rem;
  white-space: nowrap;
}
.doc tbody td { border-bottom: 1px solid var(--rule); padding: .55rem .7rem; vertical-align: top; }
.doc tbody tr:hover { background: var(--bg-soft); }
.doc td code { white-space: nowrap; }

/* Figures. The capture script writes one PNG per module; they are wide. */
.doc img {
  max-width: 100%; height: auto; display: block;
  border: 1px solid var(--rule); border-radius: 8px;
  background: var(--bg-sunk);
}
.doc figure { margin: 1.5rem 0 1.8rem; }
.doc figcaption {
  font-size: .8rem; color: var(--fg-faint); margin-top: .5rem;
  padding-left: .1rem;
}

.doc .note {
  background: var(--bg-soft); border: 1px solid var(--rule);
  border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0;
  padding: .9rem 1rem; margin: 1.4rem 0;
}
.doc .note > :last-child { margin-bottom: 0; }

.doc .missing {
  background: var(--bg-soft); border: 1px dashed var(--rule-firm);
  border-radius: 8px; padding: 2rem; text-align: center; color: var(--fg-faint);
}

/* ---------------------------------------------------------- on this page */

.onthispage {
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto; overscroll-behavior: contain;
}
.onthispage__inner { padding: 2.5rem 1.25rem 4rem 0; }
.onthispage__label {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--fg-faint); margin: 0 0 .5rem;
}
.onthispage a {
  display: block; padding: .18rem 0 .18rem .6rem;
  font-size: .8rem; line-height: 1.4; color: var(--fg-soft);
  text-decoration: none; border-left: 2px solid var(--rule);
}
.onthispage a:hover { color: var(--fg); border-left-color: var(--rule-firm); }
.onthispage a[aria-current="true"] {
  color: var(--fg); font-weight: 600; border-left-color: var(--accent);
}
.onthispage a[data-level="3"] { padding-left: 1.3rem; }
.onthispage a[data-level="4"] { padding-left: 2rem; }
.onthispage:has(#toc:empty) { visibility: hidden; }

/* -------------------------------------------------------------- results */

.results { max-width: var(--measure); margin-bottom: 2rem; }
.results h2 { font-size: 1rem; margin: 0 0 1rem; color: var(--fg-soft); }
.results ol { list-style: none; margin: 0; padding: 0; }
.results li { margin: 0 0 .25rem; }
.results a {
  display: block; padding: .7rem .9rem; border-radius: 8px;
  border: 1px solid var(--rule); text-decoration: none; color: inherit;
  background: var(--bg-soft);
}
.results a:hover { border-color: var(--rule-firm); background: var(--bg); }
.results .where { font-size: .72rem; color: var(--fg-faint); display: block; }
.results .what  { font-weight: 600; font-size: .92rem; display: block; margin: .1rem 0 .25rem; }
.results .snip  { font-size: .82rem; color: var(--fg-soft); display: block; }
.results mark   { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 .1em; }

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

@media (max-width: 1180px) {
  .shell { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .onthispage { display: none; }
  .main { padding: 2.25rem 2.25rem 6rem; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .topbar__nav { display: flex; }
  .topbar__home strong { font-size: .9rem; }
  .topbar__home span { display: none; }
  .sidebar {
    display: none; position: fixed; inset: var(--topbar-h) 0 0 0;
    width: auto; height: auto; z-index: 25; border-right: 0;
  }
  body.nav-open .sidebar { display: block; }
  body.nav-open { overflow: hidden; }
  .main { padding: 1.75rem 1.25rem 5rem; }
  .search input { width: 9rem; }
  .doc h1 { font-size: 1.6rem; }
}

/* ---------------------------------------------------------------- print */

@media print {
  .topbar, .sidebar, .onthispage, .docfoot, .results, .skip { display: none !important; }
  .shell { display: block; }
  .main  { padding: 0; }
  .doc   { max-width: none; }
  .doc a { color: inherit; text-decoration: none; }
  .doc pre, .doc img { page-break-inside: avoid; }
  .doc h1, .doc h2, .doc h3 { page-break-after: avoid; }
}
