/* doc.mu-lang.dev
 *
 * Shares the design tokens of mu-lang.dev (website/assets/css/site.css) so the
 * two read as one site, but the layout is its own: a documentation page is a
 * two-column reference, not a prose page.
 *
 * There is deliberately no highlighting JavaScript here. Code is coloured at
 * generation time by the language's own lexer (internal/doc/highlight.go), so
 * these classes style spans that are already in the HTML.
 */

:root {
  color-scheme: light dark;
  --bg: #f4f1ea;
  --bg-soft: #fbfaf7;
  --bg-code: #f0ece2;
  --ink: #151515;
  --muted: #5e5e5e;
  --accent: #2f87ff;
  --accent-strong: #7047ff;
  --accent-warm: #11d2a8;
  --border: #d8d2c8;
  --shadow: 0 18px 40px rgba(17, 20, 25, 0.12);
  --radius-lg: 8px;
  --radius-md: 8px;
  --radius-sm: 6px;
  --font-sans: "Space Grotesk", "Trebuchet MS", sans-serif;
  --font-serif: "Fraunces", "Georgia", serif;
  --font-mono: "IBM Plex Mono", "Menlo", "Courier New", monospace;

  --syn-keyword: #a626a4;
  --syn-string: #1a7f37;
  --syn-number: #b26100;
  --syn-comment: #7a7568;
  --syn-builtin: #0550ae;
  --syn-call: #2f5fd0;
  --syn-punct: #6a6a6a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --bg-soft: #151a20;
    --bg-code: #10151b;
    --ink: #f1f4f8;
    --muted: #b5bcc7;
    --accent: #2f87ff;
    --accent-strong: #8a46f0;
    --accent-warm: #11d2a8;
    --border: #2a313c;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);

    --syn-keyword: #d68bff;
    --syn-string: #7ee787;
    --syn-number: #ffb454;
    --syn-comment: #7d8590;
    --syn-builtin: #79c0ff;
    --syn-call: #a5c8ff;
    --syn-punct: #9aa4b2;
  }
}

* { box-sizing: border-box; }

/* scroll-padding keeps an anchored declaration clear of the sticky header, so
   it has to track the header's real height -- which is not the same on a phone,
   where the bar is two compact rows. */
html { scroll-behavior: smooth; scroll-padding-top: 5rem; }

@media (max-width: 700px) {
  html { scroll-padding-top: 6.5rem; }
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent-strong); text-decoration: none; }
a:hover, a:focus { text-decoration: underline; text-underline-offset: 0.18em; }

code, pre, .mono { font-family: var(--font-mono); }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 30;
  background: var(--ink); color: #fff; padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
}
.skip-link:focus { left: 1rem; top: 1rem; }

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

.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  width: 94%; max-width: 1180px; margin: 0 auto;
  display: flex; align-items: center; gap: 1rem;
  padding: 0.7rem 0;
  flex-wrap: wrap;
}

.logo { display: flex; align-items: baseline; gap: 0.45rem; color: var(--ink); }
.logo:hover { text-decoration: none; }
.logo-mark { font-family: var(--font-serif); font-size: 1.5rem; font-weight: 700; color: var(--accent-strong); }
.logo-text { font-weight: 600; letter-spacing: 0.02em; }
.logo-sub { color: var(--muted); font-size: 0.85rem; }

.header-nav { margin-left: auto; display: flex; gap: 1rem; flex-wrap: wrap; }
.header-nav a { color: var(--muted); font-size: 0.9rem; }
.header-nav a:hover { color: var(--ink); }

/* --- search --------------------------------------------------------------- */

.search { position: relative; flex: 1 1 18rem; min-width: 12rem; max-width: 30rem; }

.search input {
  width: 100%;
  font: inherit; font-size: 0.92rem;
  padding: 0.42rem 0.7rem;
  color: var(--ink);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.search-hint {
  position: absolute; right: 0.55rem; top: 50%; transform: translateY(-50%);
  font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px; padding: 0 0.3rem;
  pointer-events: none;
}
.search input:focus + .search-hint { display: none; }

.search-results {
  position: absolute; top: calc(100% + 0.4rem); left: 0; right: 0;
  background: var(--bg-soft);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  max-height: 60vh; overflow-y: auto;
  display: none; padding: 0.3rem;
}
.search-results[data-open="true"] { display: block; }

.search-results a {
  display: block; padding: 0.4rem 0.55rem; border-radius: var(--radius-sm);
  color: var(--ink);
}
.search-results a:hover, .search-results a[aria-selected="true"] {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  text-decoration: none;
}
.search-results .r-name { font-family: var(--font-mono); font-size: 0.9rem; }
.search-results .r-layer {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-left: 0.45rem;
}
.search-results .r-syn {
  display: block; font-size: 0.82rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.search-empty { padding: 0.5rem 0.55rem; color: var(--muted); font-size: 0.88rem; }

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

.page {
  width: 94%; max-width: 1180px; margin: 0 auto;
  display: grid; grid-template-columns: minmax(0, 1fr) 15rem; gap: 2.5rem;
  padding: 2rem 0 4rem;
  align-items: start;
}
.page.wide { grid-template-columns: minmax(0, 1fr); }

@media (max-width: 900px) {
  .page { grid-template-columns: minmax(0, 1fr); gap: 1.25rem; padding-top: 1.25rem; }

  /* The index has nowhere to sit as a sidebar, so it becomes a disclosure above
     the content -- one line, not a screenful. Left expanded it pushed the page
     title 536px down: on a phone you scrolled past a full viewport of chrome
     and index before finding out which module you were reading. */
  .toc {
    position: static;
    order: -1;
    max-height: none;
    overflow: visible;
    border-left: none;
    border-bottom: 1px solid var(--border);
    padding: 0 0 0.6rem;
  }

  .toc-inner > summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--muted);
  }

  .toc-inner > summary::-webkit-details-marker { display: none; }
  .toc-inner > summary::after { content: "\25be"; margin-left: auto; font-size: 1rem; }
  .toc-inner[open] > summary::after { content: "\25b4"; }

  /* Expanded it is still bounded and scrollable: process has over ninety
     declarations. */
  .toc-body {
    max-height: 45vh;
    overflow-y: auto;
  }

  .toc h2 { margin-top: 0.5rem; }
  .toc a { padding: 0.25rem 0; display: inline-block; }
}

/* The disclosure is a mobile affordance only: on a wide screen the sidebar is
   always open and has no control. */
@media (min-width: 901px) {
  .toc-inner > summary { display: none; }
}

.toc {
  position: sticky; top: 5rem;
  max-height: calc(100vh - 7rem); overflow-y: auto;
  font-size: 0.88rem;
  border-left: 1px solid var(--border);
  padding-left: 1rem;
}
.toc h2 {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--muted); margin: 0 0 0.6rem;
}
.toc ul { list-style: none; margin: 0 0 1rem; padding: 0; }
.toc li { margin: 0.12rem 0; }
.toc a { font-family: var(--font-mono); font-size: 0.82rem; color: var(--muted); }
.toc a:hover { color: var(--accent-strong); }

/* --- content -------------------------------------------------------------- */

.title-row { display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }

h1 {
  font-family: var(--font-serif); font-weight: 700;
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  margin: 0.2rem 0 0.3rem; line-height: 1.15;
}
h1 .kw { color: var(--muted); font-family: var(--font-mono); font-size: 0.5em; font-weight: 500; }

h2 {
  font-family: var(--font-sans); font-weight: 600;
  font-size: 1.35rem; margin: 2.6rem 0 0.9rem;
  padding-bottom: 0.35rem; border-bottom: 1px solid var(--border);
}

.src-link { font-size: 0.85rem; color: var(--muted); font-family: var(--font-mono); }

.lede { font-size: 1.08rem; color: var(--muted); margin: 0 0 1.4rem; }

.badge {
  display: inline-block; font-size: 0.7rem; letter-spacing: 0.07em;
  text-transform: uppercase; padding: 0.14rem 0.5rem; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted); background: var(--bg-soft);
}
.badge.builtin { border-color: var(--accent); color: var(--accent); }
.badge.prelude { border-color: var(--accent-warm); color: var(--accent-warm); }
.badge.module { border-color: var(--accent-strong); color: var(--accent-strong); }

.doc p { margin: 0 0 0.9rem; }
.doc ul { margin: 0 0 0.9rem; padding-left: 1.2rem; }
.doc li { margin: 0.2rem 0; }
.doc a code { color: inherit; }

.doc code, .sig code, td code {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05em 0.32em;
  font-size: 0.88em;
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.55;
  margin: 0 0 1.1rem;
}
pre code { background: none; border: none; padding: 0; font-size: inherit; }

/* --- declarations --------------------------------------------------------- */

.decl {
  border-top: 1px solid var(--border);
  padding: 1.4rem 0 0.4rem;
  scroll-margin-top: 5rem;
}
.decl:first-of-type { border-top: none; }

.decl h3 { margin: 0 0 0.6rem; font-family: var(--font-mono); font-size: 1rem; font-weight: 600; }
.decl h3 a.anchor { color: var(--muted); opacity: 0; margin-left: 0.4rem; font-weight: 400; }
.decl:hover h3 a.anchor, .decl h3 a.anchor:focus { opacity: 1; }

.sig {
  font-family: var(--font-mono); font-size: 0.95rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-strong);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  margin: 0 0 0.8rem;
  overflow-x: auto;
}

.undocumented { color: var(--muted); font-style: italic; }

details.source { margin: 0.2rem 0 0.4rem; }
details.source > summary {
  cursor: pointer; color: var(--muted); font-size: 0.85rem;
  list-style: none; display: inline-flex; align-items: center; gap: 0.35rem;
}
details.source > summary::-webkit-details-marker { display: none; }
details.source > summary::before { content: "▸"; font-size: 0.7rem; }
details.source[open] > summary::before { content: "▾"; }
details.source > summary:hover { color: var(--accent-strong); }
details.source pre { margin-top: 0.6rem; }

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

.listing { width: 100%; border-collapse: collapse; margin: 0 0 1.5rem; }
.listing td { padding: 0.4rem 0.6rem 0.4rem 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.listing td:first-child { white-space: nowrap; font-family: var(--font-mono); font-size: 0.88rem; }
.listing td:last-child { color: var(--muted); font-size: 0.92rem; width: 100%; }
.listing tr:last-child td { border-bottom: none; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 0.9rem; margin: 0 0 1.6rem; }
.card {
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-soft); padding: 0.85rem 1rem;
}
.card:hover { border-color: var(--accent-strong); }
.card a { font-family: var(--font-mono); font-weight: 500; }
.card p { margin: 0.3rem 0 0; font-size: 0.88rem; color: var(--muted); }

.layer-intro { color: var(--muted); margin: -0.4rem 0 1.1rem; }

.meta-list { list-style: none; padding: 0; margin: 0 0 1.4rem; font-size: 0.9rem; color: var(--muted); }
.meta-list li { margin: 0.15rem 0; }

/* --- footer --------------------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
  padding: 1.6rem 0;
  font-size: 0.86rem; color: var(--muted);
}
.footer-inner {
  width: 94%; max-width: 1180px; margin: 0 auto;
  display: flex; gap: 1rem; justify-content: space-between; flex-wrap: wrap;
}
/* The footer carries the generator's version string, which is one long
   unbreakable token. A flex item will not shrink below its content width
   without min-width:0, so on a narrow screen that one line -- and nothing else
   on the page -- pushed the whole document sideways. */
.footer-inner > * { min-width: 0; }
.site-footer p { margin: 0.15rem 0; overflow-wrap: anywhere; }

/* On a phone this bar wrapped to three rows -- logo, search, then the nav over
   two more -- and it is STICKY, so 195px of a 700px viewport was permanently
   chrome and the page title landed below the fold. Two rows now: identity plus
   search (the thing you actually navigate a reference with), then the sections
   as one row that scrolls sideways rather than wrapping. */
@media (max-width: 700px) {
  .header-inner {
    gap: 0.5rem 0.75rem;
    padding: 0.5rem 0;
  }

  .logo-sub { display: none; }

  .search {
    flex: 1 1 auto;
    max-width: none;
    min-width: 0;
  }

  .search-hint { display: none; }

  .header-nav {
    order: 3;
    flex: 1 0 100%;
    margin-left: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.9rem;
    padding-bottom: 0.15rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .header-nav::-webkit-scrollbar { display: none; }
  .header-nav a { white-space: nowrap; padding: 0.15rem 0; }
  .header-nav a[aria-current="page"] { color: var(--ink); }
}

/* --- small screens ------------------------------------------------------- */

@media (max-width: 700px) {
  .page { width: 100%; padding-left: 3vw; padding-right: 3vw; }

  h1 { font-size: clamp(1.6rem, 7vw, 2.1rem); }
  h2 { font-size: 1.15rem; margin-top: 2rem; }

  .decl { padding-top: 1.1rem; }
  /* The anchor is revealed by :hover, which a touch screen does not have. */
  .decl h3 a.anchor { opacity: 1; }

  pre { font-size: 0.8rem; padding: 0.7rem 0.8rem; }
  .sig { font-size: 0.85rem; }

  .cards { grid-template-columns: minmax(0, 1fr); }

  /* A two-column listing at 390px gives the name a single character per line.
     Stacked, the name is a heading and the summary is its line.

     The table itself has to leave table layout too: a `display: block` cell
     inside a real table still lets the widest row set the table's width, and
     the helper signatures (`_append_buffer(dest, src)`) are nowrap -- so the
     internal-helpers listing pushed the whole page sideways. */
  .listing,
  .listing tbody { display: block; }
  .listing td { display: block; padding: 0; border-bottom: none; }
  .listing td:first-child {
    padding-top: 0.55rem;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .listing td:last-child { padding-bottom: 0.55rem; width: auto; }
  .listing tr { display: block; border-bottom: 1px solid var(--border); }
  .listing tr:last-child { border-bottom: none; }

  .footer-inner { flex-direction: column; }
}

/* --- syntax --------------------------------------------------------------- */

.mu-keyword { color: var(--syn-keyword); }
.mu-string  { color: var(--syn-string); }
.mu-number  { color: var(--syn-number); }
.mu-comment { color: var(--syn-comment); font-style: italic; }
.mu-builtin { color: var(--syn-builtin); }
.mu-call    { color: var(--syn-call); }
.mu-punct   { color: var(--syn-punct); }
