/* docs.css: the xs docs, in the look of www.cross.stream. Built the same
   way as that page's site.css: every value is a token, raw tags are styled
   once and make most of the page, and a class names a block, never a look.
   Fonts and colour ramps come from the splash page's stellar.css, and the
   colours, spaces and light mode both share from its base.css. */

/* ---- tokens -------------------------------------------------------------- */

:root {
  --brand-amber: var(--named-amber-0);

  --leading: 1.6;
  --leading-code: 1.7;
  --bar: 2.25rem;      /* a terminal's title bar */
  --term-h: 55vh;      /* the terminal, when open */
  --view: 100dvh;      /* the height the page is seen in */
  /* the top bar's height, from its parts: its padding, the crumb's line (its
     tallest item) and its border. The bar takes it as its height, and the
     sidebar and every jump to a heading leave room for it. An item taller
     than the crumb goes into this sum too. */
  --header: calc(2 * var(--space-3) + var(--font-size-2) * var(--leading) + var(--line));

  --side: 16rem;       /* the sidebar */
  --toc: 15rem;        /* the page's contents, on a wide window */
  --measure: 46rem;    /* a line of prose */
  --dot: 0.65rem;
}

/* Light mode: the colours are in base.css. Code is olive in daylight, and
   the name catches the sun rather than glowing. */
@media (prefers-color-scheme: light) {
  :root { --brand-amber: #56682a; }
  .wordmark > span { text-shadow: 0 0 1px color-mix(in srgb, var(--glow) 60%, transparent); }
}

/* ---- raw tags ------------------------------------------------------------ */

* { box-sizing: border-box; }
/* The window is a column, always: the page on top, scrolling in a box of
   its own, and under it the terminal, when it is open. A jump to a heading
   leaves the bar and, under it, the gap the sidebar leaves above its first
   heading, so the two line up. */
body { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
body > .page { flex: 1; min-height: 0; overflow-y: auto; outline: none; scroll-padding-top: calc(var(--header) + var(--space-4)); scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { body > .page { scroll-behavior: auto; } }
body:has(#term:not([hidden])) { --view: calc(100dvh - var(--term-h)); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: var(--font-size-0)/var(--leading) var(--font-mono);
  -webkit-font-smoothing: antialiased;
  --gutter: clamp(var(--space-3), 4vw, var(--space-5));
}
h1, h2, h3, h4 { font-weight: normal; color: var(--fg); line-height: 1.3; margin: var(--space-6) 0 var(--space-3); }
h1 { font-size: var(--font-size-4); margin-top: 0; }
h2 { font-size: var(--font-size-2); color: var(--accent); padding-bottom: var(--space-2); border-bottom: var(--line) solid var(--line-c); }
h3 { font-size: var(--font-size-0); color: var(--brand-amber); margin-top: var(--space-5); }
h4 { font-size: var(--font-size-0); color: var(--fg-quiet); }
p, ul, ol, table, blockquote, figure, pre, mux-player { margin: 0 0 var(--space-3); }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-strong); }
strong { font-weight: normal; color: var(--accent-strong); }
code { font: inherit; color: var(--brand-amber); }
small { font-size: var(--font-size-0); color: var(--fg-quiet); }
hr { border: 0; border-top: var(--line) solid var(--line-c); margin: var(--space-5) 0; }
img { max-width: 100%; height: auto; border-radius: var(--radius); }
li + li { margin-top: var(--space-1); }
ul ul, ol ol, li > ul, li > ol { margin: var(--space-1) 0 0; }

/* code: a terminal pane, without the title bar unless it is a session */
pre {
  font: var(--font-size-0)/var(--leading-code) var(--font-mono);
  background: var(--term-bg);
  border: var(--line) solid var(--line-c);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
}
pre code { color: var(--fg); }
/* every code block's copy button, at the end of its first line; a check
   shows for a moment once it has copied */
pre { position: relative; }
pre > .copy { position: absolute; top: var(--space-3); right: var(--space-4); height: calc(var(--font-size-0) * var(--leading-code)); padding: 0; border: 0; background: none; color: var(--fg-quiet); cursor: pointer; }
pre > .copy:hover { color: var(--fg); }
pre > .copy > svg + svg, pre > .copy[data-copied] > svg:first-child { display: none; }
pre > .copy[data-copied] > svg + svg { display: inline; }
/* syntax.css colours the code, on a background of its own: the pane wins */
pre.code, pre .code { background: var(--term-bg); }

table { border-collapse: collapse; font-size: var(--font-size-0); display: block; overflow-x: auto; }
th, td { padding: var(--space-1) var(--space-3); border: var(--line) solid var(--line-c); text-align: left; vertical-align: top; }
th { font-weight: normal; color: var(--accent); background: var(--surface); }

blockquote {
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: var(--line) solid var(--line-c);
  border-radius: var(--radius);
}
blockquote > :last-child { margin-bottom: 0; }

button {
  font: var(--font-size-0) var(--font-mono);
  color: var(--fg);
  background: var(--bg);
  border: var(--line) solid var(--line-c);
  border-radius: calc(var(--radius) / 2);
  padding: var(--space-1) var(--space-3);
  cursor: pointer;
  transition: border-color var(--fade), color var(--fade);
}
button:hover { border-color: var(--accent); }

/* ---- the name: cross.stream, the "stream" glowing ------------------------ */

.wordmark { color: var(--fg); text-decoration: none; letter-spacing: 0.02em; }
.wordmark > span {
  background: linear-gradient(45deg, var(--glow), var(--accent), var(--accent-strong), var(--accent), var(--glow)) 0 50% / 200% 200%;
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  text-shadow: 0 0 10px color-mix(in srgb, var(--glow) 60%, transparent), 0 0 24px color-mix(in srgb, var(--glow) 40%, transparent);
  animation: flow var(--flow) ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) { .wordmark > span { animation: none; } }

/* ---- search: a field in the bar, the results under it --------------------- */

search { position: relative; flex: 0 1 18rem; margin-right: auto; }
search input {
  width: 100%;
  font: var(--font-size-0) var(--font-mono);
  color: var(--fg);
  background: var(--surface);
  border: var(--line) solid var(--line-c);
  border-radius: calc(var(--radius) / 2);
  padding: var(--space-1) var(--space-3);
}
search input:focus { outline: none; border-color: var(--accent); }
#results:not(:empty) {
  position: absolute; top: calc(100% + var(--space-2)); left: 0; width: min(32rem, 90vw);
  max-height: 70vh; overflow-y: auto;
  background: var(--surface); border: var(--line) solid var(--line-c); border-radius: var(--radius);
  box-shadow: 0 var(--space-3) var(--space-5) color-mix(in srgb, black 50%, transparent);
  padding: var(--space-2);
}
#results ul { list-style: none; margin: 0; padding: 0; }
#results li + li { margin-top: 0; }
#results a { display: block; padding: var(--space-2) var(--space-3); border-radius: calc(var(--radius) / 2); color: var(--fg); text-decoration: none; }
#results a:hover, #results a:focus { background: var(--surface-2); }
#results a > span { color: var(--accent); }
#results p { margin: var(--space-1) 0 0; font-size: var(--font-size-0); color: var(--fg-quiet); }
#results > p { padding: var(--space-2) var(--space-3); margin: 0; font-size: var(--font-size-0); color: var(--fg-quiet); }

/* ---- the page: a bar across the top, the sidebar, the page ---------------- */

.page {
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  min-height: 100%;
}
.page > header {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap;
  padding: var(--space-3) var(--gutter);
  border-bottom: var(--line) solid var(--line-c);
  background: var(--bg);
  position: sticky; top: 0; z-index: 2; block-size: var(--header);
}
/* where you are: the site, then the docs under it */
.crumb { font-size: var(--font-size-2); color: var(--fg-quiet); white-space: nowrap; }

.page > header > a { color: var(--fg-quiet); text-decoration: none; font-size: var(--font-size-0); }
.crumb > a:not(.wordmark) { color: inherit; text-decoration: none; }
.page > header > a:hover, .crumb > a:not(.wordmark):hover { color: var(--accent); }

#pages {
  padding: var(--space-4) var(--space-4) var(--space-6) var(--gutter);
  border-right: var(--line) solid var(--line-c);
  font-size: var(--font-size-0);
  position: sticky; top: var(--header); align-self: start; max-height: calc(var(--view) - var(--header)); overflow-y: auto;
}
#pages h2 { font-size: var(--font-size-0); color: var(--fg-quiet); border: 0; padding: 0; margin: var(--space-4) 0 var(--space-2); text-transform: lowercase; }
#pages h2:first-child { margin-top: 0; }
#pages ul { list-style: none; margin: 0; padding: 0; }
#pages li + li { margin-top: 0; }
#pages a { display: block; padding: var(--space-1) var(--space-2); margin-left: calc(-1 * var(--space-2)); border-radius: calc(var(--radius) / 2); color: var(--fg); text-decoration: none; }
#pages a:hover { color: var(--accent); }
#pages a[aria-current] { color: var(--accent); background: var(--surface); }

main { padding: var(--space-5) var(--gutter) var(--space-7); max-width: calc(var(--measure) + 2 * var(--space-6)); }
main > h1 { margin-bottom: var(--space-4); }

/* ---- the home page: the contents, every page by section ----------------- */

.lede { font-size: var(--font-size-2); max-width: var(--measure); }
.contents { display: grid; grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr)); gap: var(--space-5) var(--space-6); margin-top: var(--space-6); }
.contents h2 { margin-top: 0; }
.contents section > p { color: var(--fg-quiet); }
.contents ul { list-style: none; padding: 0; }
.contents li + li { margin-top: var(--space-2); }
.contents li > span { display: block; font-size: var(--font-size-0); color: var(--fg-quiet); }

/* ---- blocks the renderer draws -------------------------------------------- */

/* tabs: a row of keys over the panes, only the picked pane taking room. Groups
   with the same tabs switch together, so a group above you can change height:
   the clicked tab puts itself back where it was (markdown.nu) */
.tabs { margin: 0 0 var(--space-3); }
.tabs > [role=tabpanel][aria-hidden]:not([aria-hidden=false]) { display: none; }
.tabs [role=tablist] { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
.tabs [role=tab][aria-selected]:not([aria-selected=false]) { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* a command and its output: one terminal, with the title bar and its dots */
figure.session {
  position: relative;
  background: var(--term-bg);
  border: var(--line) solid var(--line-c);
  border-radius: var(--radius);
  padding-top: var(--bar);
  overflow: hidden;
}
figure.session::before {
  content: "";
  position: absolute; z-index: 1; top: calc((var(--bar) - var(--dot)) / 2); left: var(--space-3);
  width: var(--dot); height: var(--dot); border-radius: 50%;
  background: var(--dot-red);
  box-shadow: calc(var(--dot) * 1.6) 0 var(--dot-amber), calc(var(--dot) * 3.2) 0 var(--dot-green);
}
figure.session::after {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: var(--bar);
  background: var(--surface-2);
  border-bottom: var(--line) solid var(--line-c);
}
figure.session pre { margin: 0; border: 0; border-radius: 0; }
/* the command's prompt, drawn by the page, so a copy or a selection never
   takes it */
figure.session > pre:first-child code::before { content: "$ "; color: var(--fg-quiet); }
/* the command and its output close together, the dashed line between */
figure.session > pre:first-child { padding-bottom: var(--space-2); }
figure.session pre + pre { border-top: var(--line) dashed var(--line-c); color: var(--fg-quiet); padding-top: var(--space-2); }
/* output's lines close enough that a table's bars join */
figure.session pre + pre { line-height: 1.25; }
figure.session pre + pre code { color: var(--fg-quiet); }

mux-player {
  display: block; width: 100%; aspect-ratio: 863 / 540;
  border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 0 30px color-mix(in srgb, var(--glow) 45%, transparent);
}

/* a diagram: drawn by mermaid in the browser, on the page itself */
pre.mermaid { background: none; border: 0; padding: 0; text-align: center; color: var(--fg-quiet); }

/* the demo page: the Markdown and the code, then what they render */
pre.source { background: var(--surface); }
.rendered { border: var(--line) dashed var(--line-c); border-radius: var(--radius); padding: var(--space-4); }

/* the home page has no sidebar: the contents are its body */
body.home .page { display: block; }
body.home main { max-width: 72rem; margin: 0 auto; }

/* ---- wide: the page's own contents on the right --------------------------- */

#toc { display: none; }
@media (min-width: 1300px) {
  .page:has(> #toc) { grid-template-columns: var(--side) minmax(0, 1fr) var(--toc); }
  #toc {
    display: block; font-size: var(--font-size-0);
    padding: var(--space-5) var(--gutter) var(--space-6) var(--space-3);
    position: sticky; top: var(--header); align-self: start; max-height: calc(var(--view) - var(--header)); overflow-y: auto;
  }
  #toc h2 { font-size: var(--font-size-0); color: var(--fg-quiet); border: 0; padding: 0; margin: 0 0 var(--space-2); text-transform: lowercase; }
  #toc ul { list-style: none; margin: 0; padding: 0; }
  #toc a { display: block; padding: var(--space-1) 0; color: var(--fg-quiet); text-decoration: none; }
  #toc a:hover { color: var(--accent); }
  #toc .l3 a { padding-left: var(--space-3); }
}

/* ---- narrow: one column, the page first, the sidebar after it ------------- */

@media (max-width: 760px) {
  .page { grid-template-columns: minmax(0, 1fr); }
  .page > header { gap: var(--space-2) var(--space-4); }
  .crumb { margin-right: auto; }
  search { order: 3; flex: 1 1 100%; margin-right: 0; }
  #pages { grid-row: 3; position: static; max-height: none; border-right: 0; border-top: var(--line) solid var(--line-c); padding-left: var(--gutter); }
  main { padding-top: var(--space-4); }
  pre, figure.session, mux-player { margin-inline: calc(-1 * var(--gutter)); border-radius: 0; border-inline: 0; }
  /* the bar wraps and scrolls away here, so it keeps its own height and
     nothing needs to leave room for it */
  :root { --header: 0px; }
  .page > header { position: static; block-size: auto; }
}

/* on the home page, a card saying what the Terminal button does, as a callout
   on a flyer: tilted, glowing like the video, with a fat arrow bending up
   from it into the button. No script measures anything: the card is pinned
   the same distance from the page's right edge as the button, which the bar
   keeps 184px in at every width (GitHub and Discord after it), so the arrow is
   a fixed picture in the card. Change the bar's links, and the arrow needs
   redrawing. Only where there's room beside the title and opening lines. */
.term-note { display: none; }
@media (min-width: 1300px) {
  .term-note {
    display: block; position: absolute;
    top: calc(var(--header) + var(--space-5)); right: 184px; width: 17rem;
  }
  .term-note > p {
    position: relative; z-index: 1; margin: 0; padding: var(--space-3) var(--space-4);
    background: var(--surface); border: var(--line) solid color-mix(in srgb, var(--glow) 70%, transparent); border-radius: var(--radius);
    box-shadow: 0 0 30px color-mix(in srgb, var(--glow) 45%, transparent);
    font-size: var(--font-size-0); color: var(--fg);
    rotate: -2deg;
  }
  /* up from the card.s top and over into the button.s left
     side, 98px left of the card's right edge */
  /* above the bar (z-index 2), which it reaches into */
  .term-note > svg { position: absolute; z-index: 3; right: 102px; bottom: calc(100% + 2px); width: 128px; height: 66px; overflow: visible; }
  .term-note > svg path { fill: none; stroke: var(--accent); stroke-width: calc(4 * var(--line)); stroke-linecap: round; }
  .term-note > svg path.head { fill: var(--accent); stroke: none; }
}

/* the arrow from a tip that links to the Terminal button, up to the button
   (www/term/term.js) */
#term-arrow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
#term-arrow path { fill: none; stroke: var(--accent); stroke-width: calc(2 * var(--line)); }
#term-arrow marker path { fill: var(--accent); stroke: none; }

/* ---- the terminal: the bottom of the window, opened from the top bar ----- */

#term {
  flex: none; height: var(--term-h); display: flex; flex-direction: column;
  background: var(--surface); border-top: var(--line) solid var(--line-c);
  box-shadow: 0 calc(-1 * var(--space-3)) var(--space-5) color-mix(in srgb, black 30%, transparent);
  padding: var(--space-2) var(--space-3);
}
#term[hidden] { display: none; }
#term > p { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin: 0 0 var(--space-2); font: var(--font-size-0) var(--font-mono); color: var(--fg); }
.term-screen { flex: 1; min-height: 0; }
