/* SPDX-License-Identifier: CC0-1.0
   I know nothing about CSS so I just had ChatGPT vibe-code this.
   According to US law, this is not copyrightable. */

/* ---------- Base ---------- */

:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #666;
  --accent: #2a6fdb;
  --border: #ddd;
  --code-bg: #f6f8fa;
  --index-bg: #fafafa;
}

html {
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont,
               "Segoe UI", Roboto, sans-serif;
  line-height: 1.3;
}

body {
  max-width: 100ch;
  margin: 2rem auto;
  padding: 0 1rem;
}

h1, h2, h3 {
  line-height: 1.3;
  margin: 2rem 0 0.75rem;
}

h1 {
  font-size: 2.2rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.25rem;
}

h2 {
  font-size: 1.6rem;
  border-bottom: 1px solid var(--border);
}

h3 {
  font-size: 1.25rem;
}

p {
  margin: 1rem 0;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

b {
  font-weight: 600;
}

/* ---------- Table of contents with CSS counters ---------- */

/* Root counter for the whole TOC */
.toc-list {
  counter-reset: toc;
  list-style: none;
  padding-left: 1.25rem;
  margin: 0.25rem 0;
}

/* Each numbered entry increments the counter */
.toc-numbered {
  counter-increment: toc;
  margin: 0.25rem 0;
  position: relative;
}

/* Display hierarchical numbers like 1, 1.1, 1.2.1 */
.toc-numbered::before {
  content: counters(toc, ".") ". ";
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  position: absolute;
  left: -3rem;
  width: 2.75rem;
  text-align: right;
}

/* Nested TOC lists start a new sub-counter */
.toc-numbered > .toc-list {
  counter-reset: toc;
  margin-top: 0.1rem 0;
}

/* Unnumbered entries do not affect counters */
.toc-unnumbered {
  margin: 0.25rem 0;
}

/* Ensure unnumbered entries show no prefix */
.toc-unnumbered::before {
  content: "";
}

/* Optional: align links nicely */
.toc-ref {
  font-size: 0.95rem;
  display: inline-block;
}

/* ---------- Lists ---------- */

ul {
  padding-left: 1.5rem;
}

li > p {
  margin: 0.5rem 0;
}

/* ---------- Preformatted / blocks ---------- */

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1rem;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
}

/* ---------- EBNF layout: ⩴ column + vertically aligned productions ---------- */

.indexed-ebnf{
  display: grid;
  grid-template-columns: max-content 2ch 1fr; /* LHS | ⩴ | RHS */
  column-gap: 0.75rem;
  row-gap: 0.2rem;
  align-items: baseline;
}

.indexed-ebnf dt.r-name{
  grid-column: 1 / span 2; /* occupy LHS + ⩴ columns */
  display: flex;
  align-items: baseline;
  /* justify-content: space-between; /* push ⩴ to the right edge of col 2 */
  justify-self: end;
  text-align: right;
  gap: 0.75rem;
  margin: 0;
}

.indexed-ebnf dt.r-name::after{
  content: "⩴";
  color: var(--muted);
  font-weight: 400;
}

.indexed-ebnf dd.r-prod{
  grid-column: 3;          /* RHS column */
  margin: 0;               /* override default dd indentation */
  padding: 0;
  font-size: 0.95rem;
}

/* ---------- Non-terminals / ntrefs in Unicode angle brackets ---------- */

.non-terminal::before { content: "⟨"; }
.non-terminal::after  { content: "⟩"; }

/* Optional: keep link underline off the brackets themselves */
a.non-terminal::before,
a.non-terminal::after{
  text-decoration: none;
}

.r-name {
  color: #000;
}

.grammar-star {
  white-space: nowrap;
}

code {
  background: #eee;
  white-space: pre-wrap;
  /* border-radius: 3px; */
}

/* ---------- Grammar “one or more” marker ---------- */

.grammar-plus::after {
  content: "+";
  font-size: 0.7em;
  vertical-align: super;
  margin-left: 0.1em;
}

.grammar-star::after {
  content: "*";
  font-size: 0.7em;
  vertical-align: super;
  margin-left: 0.1em;
}

.grammar-opt::after {
  content: "?";
  font-size: 0.7em;
  vertical-align: super;
  margin-left: 0.1em;
}

/* ---------- Index ---------- */

.index-list {
  list-style: none;
  padding-left: 0;
  background: var(--index-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1rem;
}

.index-list > li {
  margin-bottom: 0.75rem;
}

/* Render index entries inline, comma-separated */

.index-entry-list {
  padding-left: 0;
  margin: 0;
}

.index-entry-list > li {
  display: inline;
}

/* Insert commas between entries */
.index-entry-list > li + li::before {
  content: ", ";
}

/* ---------- Small refinements ---------- */

dl {
  margin: 0;
}

dt + dt {
  margin-top: 1rem;
}

/* -------------------------------------------------------------------------- */
/* Scheme-report-style “feature” blocks                                       */
/* -------------------------------------------------------------------------- */

.feature{
  margin: 1.25rem 0 1.75rem;
  padding: 0.75rem 0 0.25rem;
  border-top: 1px solid var(--border);
}

/* The first line(s): procedure/keyword name + args + returns */
.feature-list{
  list-style: none;
  padding: 0;
  margin: 0 0 0.5rem 0;
}

/* Each clause inside a feature (procedures, etc.) */
.feature-list > li:not(.expression-syntax){
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0.15rem 0;
}

/* Expression syntax rows: control spacing ourselves (no paren gaps) */
.feature-list > li.expression-syntax{
  display: inline-flex;
  align-items: baseline;
  flex-wrap: nowrap;
  gap: 0;                 /* prevents space between '(' / ')' and first/last item */
  margin: 0.15rem 0;
}

/* Keep spacing only between the inner items */
.feature-list > li.expression-syntax > * + *{
  margin-left: 0.15rem;   /* adjust as desired */
}

/* Parens hug the content */
.feature-list > li.expression-syntax::before{
  content: "(";
  font-weight: normal;
  margin-right: 0;
  color: var(--muted);
}
.feature-list > li.expression-syntax::after{
  content: ")";
  margin-left: 0;
  color: var(--muted);
}



/* Procedure name / syntactic keyword */
.procedure-name{
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 400; /* only bold in feature list */
  color: var(--fg);
  white-space: nowrap;
}

/* Bold only inside the feature list */
.feature-list .procedure-name{
  font-weight: 600;
}

/* Opening paren should wrap the whole call: (name args...) */
.feature-list .procedure-name::before{
  content: "(";
  color: var(--muted);
  font-weight: normal;
}

/* Argument / return type atoms */
.procedure-arg{
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  white-space: nowrap;
}

.procedure-returns::after{
  content: ")";
  color: var(--muted);
  font-weight: 400;
}

/* Render argument lists inline */
.procedure-args,
.procedure-returns{
  list-style: none;
  padding: 0;
  margin: 0;
  display: inline;
  font-variant-numeric: tabular-nums;
}

/* Close paren after arguments */
.procedure-args::after{
  content: ")";
  color: var(--muted);
}

/* Arguments separated by spaces */
.procedure-args > li{
  display: inline;
  margin: 0;
  padding: 0;
}
.procedure-args > li + li::before{
  content: " ";
}

/* Repetition/rest/optional groups should not introduce extra vertical layout */
.procedure-repeated,
.procedure-rest,
.procedure-opt{
  list-style: none;
  padding: 0;
  margin: 0;
  display: inline;
}
.procedure-repeated > li,
.procedure-rest > li,
.procedure-opt > li{
  display: inline;
}

/* Repeated arguments should have an ellipsis after them */
.procedure-repeated::after{
  content: " ...";
  color: var(--muted);
}

/* Show “...” for rest arguments; optional groups in brackets */
.procedure-rest::before{
  content: " . ";
  color: var(--muted);
}
.procedure-opt::before{
  content: " [";
  color: var(--muted);
}
.procedure-opt::after{
  content: "]";
  color: var(--muted);
}

/* Returns: show ⇒ and then return specs inline */
.procedure-returns::before{
  content: " ⇒ (";
  color: var(--muted);
  font-weight: 400;
}
.procedure-returns > li{
  display: inline;
  margin: 0;
  padding: 0;
}
.procedure-returns > li + li::before{
  content: " ";
}

/* Body paragraphs: modest indentation like reports */
.feature > p{
  margin: 0.5rem 0 0.75rem;
  padding-left: 1.5rem;
}
.feature > p:first-of-type{
  margin-top: 0.25rem;
}

/* Examples: align with body; avoid double-wrapping borders */
.feature pre{
  margin: 0.5rem 0 0.75rem;
  margin-left: 1.5rem;
}
.feature code > pre{
  margin-left: 1.5rem; /* when wrapped as <code><pre>…</pre></code> */
}

/* If a feature header contains an EBNF block, make it sit flush */
.feature .indexed-ebnf{
  margin: 0.25rem 0;
}
.feature .indexed-ebnf dt.r-name{
  justify-self: start;
  text-align: left;
}
.feature .indexed-ebnf dt.r-name::after{
  content: "⩴";
}

/* Subtle link styling for procedure names in headers (like report PDFs) */
.feature-list .procedure-name{
  text-decoration: none;
}
.feature-list .procedure-name:hover{
  text-decoration: underline;
}
.feature-list a.procedure-name{
  color: var(--fg);
}

/* -------------------------------------------------------------------------- */
/* Scheme-report-style feature header boxes (refined)                          */
/* -------------------------------------------------------------------------- */

.feature-box{
  position: relative;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--index-bg);
  padding: 0.4rem 0.6rem 0.5rem 0.6rem;
}

/* Library name at bottom-right, like RnRS */
.library-name{
  display: block;
  margin-top: 0.25rem;
  text-align: right;
  color: var(--muted);
  font-size: 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
}

/* -------------------------------------------------------------------------- */
/* Header line styling                                                         */
/* -------------------------------------------------------------------------- */

/* Common monospace look */
.expression-syntax,
.identifier-syntax{
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.25;
}

/* Operator / form name */
.expression-syntax-name{
  font-weight: 600;
  white-space: nowrap;
  margin-right: 0.05rem;
  margin-right: 0.15rem;
}

/* Identifier syntax: no extra decoration, compact like procedure names */
.identifier-syntax{
  font-weight: 600;
  white-space: nowrap;
}

.expression-syntax-name a,
.identifier-syntax a{
  color: var(--link);
}


/* Index entry lists should be inline (with space before list) */
.index-entry-list{
  list-style: none;
  padding: 0;
  margin: 0;
  margin-left: 0.5em;
  display: inline;
}
.index-entry-list > li{
  display: inline;
  margin: 0;
  padding: 0;
}
.index-entry-list > li + li::before{
  content: ", ";
  color: var(--muted);
}

/* Subindex lists should not have markers */
.subindex-list{
  list-style: none;
  padding-left: 1.25rem;
  margin: 0.25rem 0 0.75rem;
}
.subindex-list > li{
  margin: 0.15rem 0;
}
