/* The whole stylesheet. No webfonts, no imports, no external requests.
 *
 * System sans prose, monospace code. The page is cold-tinted rather than white
 * (snow in shade, not snow in sun), with a deep navy accent and one warm
 * contrast hue for literals; everything else is greyscale. Every foreground
 * colour clears WCAG AA against the surface it actually lands on.
 *
 * LIGHT ONLY, by decision rather than by omission: the palette is carrying the
 * site's identity, and a dark page does not read as snow. `color-scheme: light`
 * declares that, so a browser's own inverter applies predictably and form
 * controls do not render half-dark. Anyone who needs a dark page will be using
 * such an inverter, and declaring our scheme is what makes it work cleanly.
 */

:root {
  color-scheme: light;
  --bg: #e4edf3;
  --fg: #0f1e29;
  --muted: #4b6172;
  /* One step quieter than --muted and no further: the footer aside is the only
   * thing that uses it, and AA is the floor even for a closing line. */
  --dim: #516675;
  --accent: #0d3557;
  --contrast: #8a3d1c;
  --rule: #c6d7e2;
  --fill: #d6e4ed;
}

/* Readers who ask their system for more contrast get it. Costs everyone else
 * nothing, since the query is off by default. */
@media (prefers-contrast: more) {
  :root {
    --bg: #ffffff;
    --fg: #000000;
    --muted: #2b3f4f;
    --dim: #2b3f4f;
    --accent: #06263f;
    --contrast: #6d2d10;
    --rule: #8ea6b6;
    --fill: #eef4f8;
  }
}

html {
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* A percentage, never px: this scales with the reader's own default font
   * size, which a px value would silently override. */
  font-size: 112.5%;
  line-height: 1.6;
  /* Nothing on this site is wide enough to justify a horizontal page scroll. */
  overflow-wrap: break-word;
}

/* Keyboard focus must be obvious. `:focus-visible` rather than `:focus`, so a
 * mouse click never paints a ring. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* The skip link: parked above the viewport until it takes focus, so it is the
 * first thing a keyboard reaches and the last thing a mouse ever sees. Plain
 * `:focus`, not `:focus-visible` - this element exists only for keyboard and
 * assistive navigation, so it should appear however focus arrives. */
.skip {
  background: var(--bg);
  border: 1px solid var(--accent);
  color: var(--accent);
  left: 0.75rem;
  padding: 0.5rem 0.9rem;
  position: fixed;
  top: -5rem;
  z-index: 10;
}

.skip:focus {
  top: 0.75rem;
}

body {
  margin: 0 auto;
  max-width: 40rem;
  padding: 2rem 1.25rem 4rem;
}

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

header {
  align-items: baseline;
  border-bottom: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin-bottom: 2.5rem;
  padding-bottom: 0.75rem;
}

.wordmark {
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  text-decoration: none;
}

.site-nav ul {
  display: flex;
  gap: 1.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-nav a {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--fg);
}

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

h1,
h2,
h3,
h4 {
  font-weight: 600;
  line-height: 1.25;
  margin: 2.5rem 0 0.75rem;
}

h1 {
  font-size: 1.9rem;
  margin-top: 0;
}

h2 {
  font-size: 1.35rem;
}

h3 {
  font-size: 1.1rem;
}

h4 {
  font-size: 1rem;
}

/* A heading's own anchor, when the renderer emits one, stays out of the way. */
h1 a,
h2 a,
h3 a,
h4 a {
  color: inherit;
}

p,
ul,
ol,
blockquote,
table {
  margin: 0 0 1.1rem;
}

ul,
ol {
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.3rem;
}

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

blockquote {
  border-left: 2px solid var(--rule);
  color: var(--muted);
  padding-left: 1rem;
}

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

/* Wide content scrolls inside its own box rather than widening the page. */
table {
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--rule);
  padding: 0.4rem 0.9rem 0.4rem 0;
  text-align: left;
  vertical-align: top;
}

th {
  font-weight: 600;
}

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

code,
pre {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

code {
  background: var(--fill);
  border-radius: 2px;
  padding: 0.1em 0.3em;
}

pre {
  background: var(--fill);
  border-left: 2px solid var(--rule);
  line-height: 1.5;
  margin: 0 0 1.4rem;
  overflow-x: auto;
  padding: 0.9rem 1rem;
}

pre code {
  background: none;
  padding: 0;
}

/* Syntax classes, the contract tools/front/highlight.hk emits. Two hues in
 * total: the accent carries the structure, the contrast hue carries literals,
 * and everything else is text or muted. An ordinary identifier gets no class,
 * so it inherits the body colour. */
.kw {
  color: var(--accent);
  font-weight: 600;
}

.ty {
  color: var(--accent);
}

.fnb {
  color: var(--fg);
  font-weight: 600;
}

.str,
.num {
  color: var(--contrast);
}

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

.op,
.pn {
  color: var(--muted);
}

/* --- table of contents -------------------------------------------------- */

.toc {
  border-left: 2px solid var(--rule);
  font-size: 0.85rem;
  list-style: none;
  margin: 0 0 2.5rem;
  padding: 0.2rem 0 0.2rem 1rem;
}

.toc li {
  margin-bottom: 0.15rem;
}

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

.toc a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* --- pager and footer --------------------------------------------------- */

.pager {
  border-top: 1px solid var(--rule);
  display: flex;
  font-size: 0.9rem;
  gap: 1.5rem;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 1rem;
}

.pager a[rel="prev"]::before {
  content: "\2190\00a0";
}

.pager a[rel="next"] {
  margin-left: auto;
  text-align: right;
}

.pager a[rel="next"]::after {
  content: "\00a0\2192";
}

footer {
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 3rem;
  padding-top: 1rem;
}

footer p {
  margin: 0 0 0.3rem;
}

/* The closing line sits below the provenance line and steps back from it:
 * smaller, dimmer, and the last thing on the page. Dimmer via a real colour,
 * never `opacity` - opacity composites against the background and silently
 * drops the contrast ratio (0.72 here landed at 3.09:1, under AA), where a
 * declared colour can be measured. */
footer .aside {
  color: var(--dim);
  font-size: 0.78rem;
  margin: 0;
}

.pager + footer {
  border-top: 0;
  margin-top: 1.5rem;
}

/* --- narrow screens ----------------------------------------------------- */

@media (max-width: 30rem) {
  html {
    font-size: 106.25%;
  }

  body {
    padding: 1.5rem 1rem 3rem;
  }

  h1 {
    font-size: 1.6rem;
  }
}
