/* Tokens lifted from the site's index.html so the manual is the same site:
   same dark default, same light override, Inter with system fallbacks and no
   webfont request. */

:root {
  color-scheme: dark light;
  --bg: #07111f;
  --bg-2: #0a1626;
  --surface: rgba(15, 29, 47, .78);
  --surface-strong: #0e1d30;
  --surface-soft: rgba(255, 255, 255, .035);
  --text: #f4f8ff;
  --muted: #9fb0c8;
  --faint: #6f839f;
  --line: rgba(180, 205, 235, .14);
  --line-strong: rgba(180, 205, 235, .24);
  --cyan: #59e4ff;
  --blue: #7aa2ff;
  --green: #73f0bb;
  --amber: #f5c96a;
  --red: #ff8f8f;
  --shadow: 0 24px 70px rgba(0, 0, 0, .28);
  --radius: 22px;
  --radius-sm: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f7fb;
    --bg-2: #eef3f9;
    --surface: rgba(255, 255, 255, .86);
    --surface-strong: #ffffff;
    --surface-soft: rgba(17, 50, 84, .035);
    --text: #0c1a2b;
    --muted: #52657d;
    --faint: #7b8da3;
    --line: rgba(18, 50, 84, .11);
    --line-strong: rgba(18, 50, 84, .18);
    --cyan: #007d99;
    --blue: #365de6;
    --green: #0a9262;
    --amber: #a56200;
    --red: #c23a3a;
    --shadow: 0 24px 70px rgba(40, 72, 107, .13);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 14% 8%, color-mix(in srgb, var(--blue) 11%, transparent), transparent 28rem),
    radial-gradient(circle at 86% 22%, color-mix(in srgb, var(--cyan) 9%, transparent), transparent 26rem),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 52%, var(--bg) 100%);
  font: 16px/1.7 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* A manual is read with a table of contents beside it on a desktop and
   collapsed above it on a phone. One column below 62rem. */
.shell {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  width: 100%;
  max-width: 68rem;
  margin: 0 auto;
  padding: 0 16px 6rem;
}

/* A grid item's min-width is auto, which means it refuses to shrink below the
   min-content width of what it holds. One long line in a <pre> therefore
   inflates the whole column and the page scrolls sideways at phone width -
   the overflow-x on the <pre> never gets a chance, because the column grew
   to fit it instead. min-width: 0 lets the column shrink and hands the
   scrolling back to the <pre>, which is where it belongs. */
.shell > * { min-width: 0; }

@media (min-width: 62rem) {
  .shell { grid-template-columns: 15rem 1fr; gap: 3rem; }
  .toc { position: sticky; top: 1.5rem; align-self: start; max-height: calc(100vh - 3rem); overflow-y: auto; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  max-width: 68rem;
  margin: 0 auto;
  padding: 1.6rem 16px 2rem;
  font-size: .92rem;
}

.topbar a { color: var(--muted); text-decoration: none; }
.topbar a:hover { color: var(--text); }

/* ----------------------------------------------------------------- the toc */

.toc nav { font-size: .88rem; }
.toc .tochead {
  font: 600 .72rem/1 var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 .8rem;
}
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc a {
  display: block;
  padding: .3rem 0 .3rem .75rem;
  border-left: 1px solid var(--line);
  color: var(--muted);
  text-decoration: none;
}
.toc a:hover { color: var(--text); border-left-color: var(--cyan); }
.toc .sub a { padding-left: 1.6rem; font-size: .95em; color: var(--faint); }

/* ---------------------------------------------------------------- the prose */

.kicker {
  font: 600 .74rem/1 var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--cyan);
  margin: 0 0 .9rem;
}

h1 {
  font-size: clamp(1.9rem, 5vw, 2.5rem);
  line-height: 1.15;
  letter-spacing: -.02em;
  margin: 0 0 1rem;
}

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

.byline {
  font: .84rem/1.5 var(--mono);
  color: var(--faint);
  padding-bottom: 1.8rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--line);
}

article h2 {
  font-size: 1.38rem;
  line-height: 1.25;
  letter-spacing: -.01em;
  margin: 3.2rem 0 .9rem;
  padding-top: .6rem;
  border-top: 1px solid var(--line);
  scroll-margin-top: 1.5rem;
}

article h3 {
  font-size: 1.06rem;
  margin: 2rem 0 .6rem;
  scroll-margin-top: 1.5rem;
}

article h4 { font-size: .96rem; margin: 1.5rem 0 .5rem; color: var(--muted); }

article p { margin: 0 0 1.1rem; }

article a { color: var(--blue); text-underline-offset: .18em; }

article ul, article ol { margin: 0 0 1.2rem; padding-left: 1.3rem; }
article li { margin: .35rem 0; }

strong { color: var(--text); font-weight: 650; }

/* ------------------------------------------------------------------- code */

code {
  font: .88em/1.5 var(--mono);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .1em .36em;
}

/* overflow-x on the pre, never the page: one long line in a transcript must
   not widen the document at phone width. */
pre {
  margin: 1.2rem 0;
  padding: 1rem 1.1rem;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  box-shadow: var(--shadow);
}

pre code {
  font-size: .82rem;
  line-height: 1.55;
  background: none;
  border: 0;
  padding: 0;
  white-space: pre;
}

.cmt { color: var(--faint); }
.out { color: var(--muted); }
.warn { color: var(--amber); }
.good { color: var(--green); }
.bad { color: var(--red); }

.prompt { color: var(--cyan); }

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

.tablewrap { overflow-x: auto; margin: 1.3rem 0; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 32rem; }

th, td {
  text-align: left;
  padding: .55rem .7rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  font: 600 .72rem/1.3 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--faint);
}

td code { font-size: .85em; }

/* ------------------------------------------------------------------- cards */

.note, .warnbox {
  margin: 1.4rem 0;
  padding: 1rem 1.15rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 2px solid var(--cyan);
  border-radius: var(--radius-sm);
  font-size: .95rem;
  color: var(--muted);
}

.warnbox { border-left-color: var(--amber); }
.note strong, .warnbox strong { color: var(--text); }
.note :last-child, .warnbox :last-child { margin-bottom: 0; }
.note :first-child, .warnbox :first-child { margin-top: 0; }

/* Two-up quick reference of the eight protocols. */
.ports {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: .7rem;
  margin: 1.4rem 0;
  padding: 0;
  list-style: none;
}

.ports li {
  margin: 0;
  padding: .8rem .9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.ports b { display: block; font-size: .95rem; }
.ports span { font: .8rem/1.5 var(--mono); color: var(--faint); }

/* --------------------------------------------------------------------- foot */

.foot {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--line);
  font-size: .92rem;
  color: var(--muted);
}

.foot a { color: var(--blue); }
