/* #region tokens */
/* palette */
:root {
  --c-paprika: #be5532;
  --c-blue: #0076d1;
  --c-green: #04724d;
}

/* light */
:root {
  --bg: #fbfbfd;
  --surface: #ffffff;
  --fg: #17171f;
  --muted: #5c5c69;
  --border: #e7e7ec;

  --brand: var(--c-blue); /* primary, decorative */
  --accent: #1670c9; /* readable blue for text links */
  --accent-soft: color-mix(in srgb, var(--c-blue) 12%, transparent);

  --tip: var(--c-green);
  --warn: color-mix(in srgb, var(--c-paprika) 90%, black);
  --note: var(--c-blue);

  --tok-kw: #c02a39;
  --tok-fn: #3a58b5;
  --tok-str: #157a0e;
  --tok-num: #a4014e;
  --tok-com: #6a6a72;
  --tok-punct: #2f2f38;
  --tok-esc: #14606a;
}

/* metrics: components.css and the scroll-spy derive from these */
:root {
  /*
    Relative so it still scales with the reader's own font size; 112.5% of the
    usual 16px default is 18px. Media queries resolve rem against that default
    rather than this, so the TOC breakpoint is in px.
  */
  --root-size: 112.5%;
  --max: 46rem; /* reading column */
  --pad-x: 1.25rem; /* gutter, shared by header, main and footer */
  --pad-top: 3.5rem; /* main's top padding; the TOC aligns to it */
  --pad-bottom: 5rem;
  --header-h: 3.5rem; /* authoritative: the header is sized to this */
  --toc-w: 11rem; /* margin sidebar; feeds the TOC breakpoint */
  --ann-w: 13rem; /* annotation column in the right margin */
  --gap: 1.25rem;
  --radius: 10px;
  --radius-sm: 6px;
  --below-header: calc(var(--header-h) + var(--gap));
}

/* dark */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #04040d;
    --surface: #0c0c18;
    --fg: #e9e9f1;
    --muted: #9595a6;
    --border: #1e1e2b;

    --accent: #77aed6;
    --accent-soft: color-mix(in srgb, var(--c-blue) 22%, transparent);

    --tip: color-mix(in srgb, var(--c-green) 62%, white);
    --warn: color-mix(in srgb, var(--c-paprika) 78%, white);
    --note: color-mix(in srgb, var(--c-blue) 80%, white);

    --tok-kw: #ff7d8a;
    --tok-fn: #82aaff;
    --tok-str: #a5d66f;
    --tok-num: #ffa168;
    --tok-com: #8b8fa3;
    --tok-punct: #ccd0dc;
    --tok-esc: #7bd4f0;
  }
}

/* #endregion */

/* #region base */

/*
  Nothing here may cause a horizontal scrollbar at phone widths. Fix the
  offending element (scale it, wrap it, or let it scroll on its own axis);
  never reach for overflow-x: hidden on a container, which hides genuinely
  overflowing content from anyone who needs to reach it.
*/

* {
  box-sizing: border-box;
}

html {
  font-size: var(--root-size);
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial,
    sans-serif;
  font-size: 1rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 20;
  padding: 0.5rem 0.9rem;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--brand);
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus {
  left: 0;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 3px;
}

/* #endregion */

/* #region header: blue, dithered seam, black */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  isolation: isolate;
  --seam: 135deg; /* 135deg gradient => 45deg color boundary */
  --seam-at: 50%; /* where the blue gives way, along the gradient line */
  --spread: 1; /* multiplier on the dither band's width */
  --sq: 4px;
  /*
    The band widens with the header and would eventually reach the nav, so cap
    it at ~40% of the reading column. Lengths are along the gradient line, which
    is 45deg, so a horizontal span is 1.414x these.
  */
  --band-far: calc(var(--max) * 0.14);
  --band-near: calc(var(--max) * 0.065);
  background: linear-gradient(
    var(--seam),
    var(--c-blue) 0 var(--seam-at),
    var(--bg) var(--seam-at) 100%
  );
}
/*
  Blue squares poke past the seam and background squares poke back into the
  blue, over a narrow band. An approximation: CSS can't threshold per
  pixel, so this isn't a true ordered dither.
*/
.site-header::before,
.site-header::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-size: calc(var(--sq) * 2) calc(var(--sq) * 2);
  pointer-events: none;
}
.site-header::before {
  background-image: conic-gradient(var(--c-blue) 0 25%, #0000 0 50%, var(--c-blue) 0 75%, #0000 0);
  -webkit-mask: linear-gradient(
    var(--seam),
    #0000 calc(var(--seam-at) - min(6% * var(--spread), var(--band-near))),
    #000 var(--seam-at),
    #0000 calc(var(--seam-at) + min(13% * var(--spread), var(--band-far)))
  );
  mask: linear-gradient(
    var(--seam),
    #0000 calc(var(--seam-at) - min(6% * var(--spread), var(--band-near))),
    #000 var(--seam-at),
    #0000 calc(var(--seam-at) + min(13% * var(--spread), var(--band-far)))
  );
}
.site-header::after {
  background-image: conic-gradient(var(--bg) 0 25%, #0000 0 50%, var(--bg) 0 75%, #0000 0);
  background-position: var(--sq) 0;
  -webkit-mask: linear-gradient(
    var(--seam),
    #0000 calc(var(--seam-at) - min(13% * var(--spread), var(--band-far))),
    #000 var(--seam-at),
    #0000 calc(var(--seam-at) + min(6% * var(--spread), var(--band-near)))
  );
  mask: linear-gradient(
    var(--seam),
    #0000 calc(var(--seam-at) - min(13% * var(--spread), var(--band-far))),
    #000 var(--seam-at),
    #0000 calc(var(--seam-at) + min(6% * var(--spread), var(--band-near)))
  );
}

.site-header-inner {
  max-width: var(--max);
  margin-inline: auto;
  min-height: var(--header-h);
  padding-inline: var(--pad-x);
  display: flex;
  align-items: center;
  gap: var(--gap);
}

.brand {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
  text-decoration: none;
  text-shadow: 0 1px 2px rgba(2, 2, 11, 0.35);
}
.brand:hover {
  opacity: 0.85;
}

.site-header nav {
  margin-left: auto;
  display: flex;
  gap: var(--gap);
  font-size: 0.95rem;
}
.site-header nav a {
  color: var(--muted);
  text-decoration: none;
}
.site-header nav a:hover {
  color: var(--fg);
}

/* The band scales with the header, so tighten it as the nav closes in. */
@media (max-width: 420px) {
  .site-header {
    --seam-at: 44%;
    --spread: 0.5;
  }
}

/*
  Below this even a tightened band can't fit between the brand and the nav, so
  the header drops to a solid one. Nav text has to be fully opaque: white at any
  alpha falls under 4.5:1 on the blue.
*/
@media (max-width: 340px) {
  .site-header {
    background: var(--c-blue);
  }
  .site-header::before,
  .site-header::after {
    display: none;
  }
  .site-header nav a,
  .site-header nav a:hover {
    color: #fff;
  }
  .site-header nav a:hover {
    text-decoration: underline;
  }
}

/* #endregion */

/* #region layout */
main {
  position: relative; /* anchor for a #toc() floated into the left margin */
  max-width: var(--max);
  margin-inline: auto;
  padding: var(--pad-top) var(--pad-x) var(--pad-bottom);
}

main > :first-child {
  margin-top: 0;
}

/* #endregion */

/* #region typography */
h1,
h2,
h3,
h4 {
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.015em;
}
h1 {
  font-size: 1.85rem;
  margin: 0 0 1.25rem;
} /* #title() */
h2 {
  font-size: 1.35rem;
  margin: 2.5rem 0 0.6rem;
} /* `=` in Typst */
h3 {
  font-size: 1.1rem;
  margin: 2rem 0 0.5rem;
} /* `==` in Typst */
h4 {
  font-size: 1rem;
  margin: 1.75rem 0 0.4rem;
}

p,
ul,
ol {
  margin: 0 0 1.15rem;
}
li {
  margin: 0.2rem 0;
}

/* Color alone isn't enough; site chrome opts out with its own text-decoration. */
a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 65%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
a:hover {
  text-decoration-color: var(--accent);
}

strong {
  font-weight: 650;
}
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

table {
  width: 100%;
  margin: 1.5rem 0;
  border-collapse: collapse;
  font-size: 0.92rem;
}
th,
td {
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
thead th {
  font-weight: 650;
}
table tr:last-child td {
  border-bottom: none;
}

/* #endregion */

/* #region code */
code {
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.86em;
}
:not(pre) > code {
  background: var(--accent-soft);
  padding: 0.14em 0.4em;
  border-radius: 5px;
}
pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin: 1.5rem 0;
  overflow-x: auto;
  line-height: 1.5;
  font-size: 0.9rem;
}
pre code {
  background: none;
  padding: 0;
}

/* Token classes the build swaps in for Typst's inline colors. */
.tok-kw {
  color: var(--tok-kw);
}
.tok-fn {
  color: var(--tok-fn);
}
.tok-str {
  color: var(--tok-str);
}
.tok-num {
  color: var(--tok-num);
}
.tok-com {
  color: var(--tok-com);
  font-style: italic;
}
.tok-punct {
  color: var(--tok-punct);
}
.tok-esc {
  color: var(--tok-esc);
}

/* #endregion */

/* #region buttons */
button {
  font: inherit;
  font-size: 0.9rem;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--brand);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.9rem;
  margin-right: 0.4rem;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s;
}
button:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
button:active {
  transform: translateY(1px);
}

/* #endregion */

/* #region ascii boat */
.boat {
  width: fit-content;
  margin: 0 auto 2.5rem;
  padding: 0;
  border: none;
  background: none;
  /*
    Undo the code-block pre rule: its overflow-x makes both axes scrollable,
    which gives the art its own scrollbars. Sized to fit, so nothing to clip.
  */
  overflow: visible;
  color: var(--brand);
  /* Must be monospace or the art shears; a bare pre inherits the body font. */
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  /*
    The art is a fixed 46 characters, so size it against the viewport to keep
    it inside the column on a phone. ~0.6em per character: 46 * 0.6 * 3.1vw
    stays under the available width down to a 320px screen.
  */
  font-size: clamp(0.5rem, 3.1vw, 0.85rem);
  line-height: 1.1;
  white-space: pre;
  user-select: none;
}

/* #endregion */

/* #region post lists */
.posts {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
}
.post {
  padding: var(--gap) 0;
  border-top: 1px solid var(--border);
}
.post:last-child {
  border-bottom: 1px solid var(--border);
}
.post-title {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.3;
}
@supports (text-box-trim: trim-start) {
  .post-title {
    text-box-trim: trim-start;
    text-box-edge: cap alphabetic;
  }
}

/* Read as a link rather than a bold heading. */
.post-link {
  font-weight: 650;
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 55%, transparent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}
.post-link:hover {
  text-decoration-color: var(--accent);
}
.post-meta {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
.post-desc {
  margin: 0.5rem 0 0;
  color: var(--muted);
}
.more-posts {
  margin: 1.25rem 0 0;
  font-size: 0.95rem;
}

:is(h1, h2, h3, h4)[id] {
  scroll-margin-top: var(--below-header);
}

/* #endregion */

/* #region footer */
.site-footer .sep {
  margin: 0 0.55em;
  opacity: 0.6;
}
.site-footer {
  max-width: var(--max);
  margin: var(--pad-bottom) auto 0;
  padding: 2rem var(--pad-x) 3rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

/* #endregion */
