@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500&family=STIX+Two+Text:ital,wght@0,400;0,500;0,600;1,400&display=swap");

:root {
  --paper: #ffffff;
  --ink: #111315;
  --muted: #686d72;
  --line: #d9dcde;
  --line-dark: #1a1c1e;
  --wash: #f6f7f6;
  --accent: #174c70;
  --serif: "STIX Two Text", "Times New Roman", serif;
  --sans: "IBM Plex Sans", Arial, sans-serif;
  --mono: "IBM Plex Mono", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--paper);
  color: var(--ink);
  font-size: 18px;
  font-synthesis: none;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--paper);
  font-family: var(--serif);
  line-height: 1.66;
  text-rendering: optimizeLegibility;
}

img {
  max-width: 100%;
}

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

a:hover {
  color: var(--ink);
}

a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.site-shell {
  width: min(calc(100% - 48px), 920px);
  margin-inline: auto;
  padding: 38px 0 92px;
}

.site-masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 17px;
  border-bottom: 1px solid #e9ebec;
}

.masthead-links {
  display: flex;
  align-items: center;
  gap: 22px;
}

.wordmark {
  color: var(--ink);
  font-size: 1.08rem;
  font-weight: 500;
  letter-spacing: -0.012em;
  line-height: 1;
  text-decoration: none;
}

.masthead-portrait {
  display: block;
  width: 46px;
  height: 46px;
  color: inherit;
  text-decoration: none;
}

.masthead-portrait img {
  display: block;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--wash);
  object-fit: cover;
}

.site-nav {
  display: flex;
  gap: 16px;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.045em;
  line-height: 1.4;
  text-transform: uppercase;
}

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

.site-nav a:hover {
  color: var(--accent);
}

.home-content {
  max-width: 820px;
  margin: 66px auto 0;
}

.post-index {
  min-width: 0;
}

.post-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.post-list li {
  margin-bottom: 28px;
}

.post-copy {
  min-width: 0;
}

.post-title {
  color: var(--ink);
  font-size: 1.12rem;
  font-weight: 400;
  letter-spacing: -0.006em;
  line-height: 1.3;
  text-decoration-color: #aeb8bf;
}

.post-title:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

.post-description {
  max-width: 610px;
  margin: 8px 0 0;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.81rem;
  line-height: 1.52;
}

.article-column {
  width: 100%;
  max-width: 720px;
  min-width: 0;
  margin: 72px auto 0;
}

.article-header {
  padding: 0 0 43px;
}

.article-header h1 {
  max-width: 680px;
  margin: 0;
  font-size: clamp(2.05rem, 5vw, 2.7rem);
  font-weight: 400;
  letter-spacing: -0.025em;
  line-height: 1.08;
}

.page-heading {
  padding-bottom: 32px;
}

.page-heading h1 {
  font-size: 2.25rem;
}

.prose {
  width: 100%;
  padding-top: 38px;
}

.prose > :first-child {
  margin-top: 0;
}

.prose p,
.prose li {
  font-size: 1rem;
  line-height: 1.75;
}

.prose p {
  margin: 0 0 1.3em;
}

.page-content p {
  margin-bottom: 1.55em;
}

.page-content p:first-child {
  font-size: 1.08rem;
  line-height: 1.72;
}

.prose h2 {
  margin: 3.3rem 0 1rem;
  font-size: 1.42rem;
  font-weight: 500;
  letter-spacing: -0.012em;
  line-height: 1.28;
}

.prose h2 .section-number {
  display: inline-block;
  min-width: 1.75em;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.66em;
  font-weight: 400;
}

.prose h3 {
  margin: 2.25rem 0 0.75rem;
  font-size: 1.16rem;
  font-weight: 500;
  line-height: 1.3;
}

.prose ul,
.prose ol {
  padding-left: 1.35rem;
}

.prose blockquote {
  margin: 2.2rem 0;
  padding: 2px 0 2px 22px;
  border-left: 2px solid var(--accent);
  color: #34383b;
  font-style: italic;
}

.prose code,
.prose pre {
  font-family: var(--mono);
  font-variant-ligatures: none;
}

.prose :not(pre) > code {
  padding: 0.08em 0.28em;
  border: 1px solid #e1e3e4;
  background: var(--wash);
  font-size: 0.82em;
}

.technical-post > pre,
.code-block,
.technical-post pre.listing {
  overflow-x: auto;
  margin: 1.7rem 0 2rem;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--wash);
}

.technical-post > pre {
  padding: 17px 19px;
  font-size: 0.76rem;
  line-height: 1.62;
  tab-size: 4;
}

.technical-post > pre code {
  display: block;
  min-width: max-content;
}

.code-block {
  overflow: hidden;
}

.code-block figcaption {
  display: flex;
  justify-content: space-between;
  padding: 8px 13px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.65rem;
}

.code-block pre {
  overflow-x: auto;
  margin: 0;
  padding: 17px 19px;
  font-size: 0.76rem;
  line-height: 1.62;
}

.technical-post pre.listing {
  padding: 14px 0;
  counter-reset: line;
  font-size: 0.75rem;
  line-height: 1.58;
}

.technical-post pre.listing code {
  display: block;
  min-width: max-content;
}

.technical-post .code-line {
  position: relative;
  display: block;
  min-height: 1.58em;
  padding: 0 16px 0 54px;
  white-space: pre;
}

.technical-post .code-line::before {
  position: absolute;
  left: 0;
  width: 40px;
  padding-right: 9px;
  border-right: 1px solid var(--line);
  color: #8a8f93;
  content: counter(line);
  counter-increment: line;
  font-size: 0.8em;
  text-align: right;
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: #72777b;
  font-style: italic;
}

.token.punctuation {
  color: #4d5256;
}

.token.namespace {
  opacity: 0.8;
}

.token.property,
.token.tag,
.token.constant,
.token.symbol,
.token.deleted,
.token.number,
.token.boolean {
  color: #8b3148;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
  color: #246348;
}

.token.operator,
.token.entity,
.token.url,
.token.variable {
  color: #6b4c29;
}

.token.atrule,
.token.attr-value,
.token.function,
.token.class-name {
  color: #165b82;
}

.token.keyword,
.token.directive {
  color: #503a91;
  font-weight: 500;
}

.token.regex,
.token.important {
  color: #9b551d;
}

.token.important,
.token.bold {
  font-weight: 600;
}

.token.italic {
  font-style: italic;
}

.katex {
  color: var(--ink);
  font-size: 1.01em;
}

.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  margin: 0.25em 0 !important;
  padding: 0.25em 0;
}

.math-block {
  overflow-x: auto;
  margin: 2rem 0;
  padding: 19px 24px;
  border-block: 1px solid var(--line);
  text-align: center;
}

.technical-post img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 1.7rem auto 2rem;
  border: 1px solid var(--line);
}

.technical-post p:has(> img) {
  text-align: center;
}

.technical-post figure {
  margin: 1.7rem 0 2rem;
}

.technical-post .article-diagram {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: center;
  margin: 1.9rem 0 2.2rem;
}

.technical-post .article-diagram img {
  margin-inline: auto;
  border: 0;
  background: transparent;
}

.graphviz-diagram img {
  width: auto;
  max-width: 100%;
  padding: 0;
  border: 0 !important;
  background: var(--paper) !important;
}

.technical-post .tree-colour-diagram img {
  width: auto;
  max-width: min(520px, 100%);
  padding: 0;
  border: 0 !important;
}

.technical-post p:has(+ .tree-colour-diagram),
.technical-post pre:has(+ p + .tree-colour-diagram) {
  margin-bottom: 0.45rem;
}

.technical-post .tree-colour-diagram {
  margin-top: 0.45rem;
}

.technical-post .tree-colour-diagram.trie-diagram img {
  max-width: min(640px, 100%);
}

.technical-post .tree-colour-diagram.automaton-diagram img {
  max-width: min(680px, 100%);
}

.technical-post table {
  display: block;
  width: 100%;
  overflow-x: auto;
  margin: 1.7rem 0 2rem;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.74rem;
  line-height: 1.45;
}

.technical-post th,
.technical-post td {
  padding: 8px 10px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.technical-post th {
  background: var(--wash);
  font-weight: 500;
}

.tree-matcher-demo {
  display: grid;
  gap: 9px;
  margin: 1.5rem 0 2.2rem;
  padding: 16px;
  border: 1px solid var(--line-dark);
  background: var(--paper);
}

.tree-matcher-demo > input[type="text"] {
  width: 100%;
  min-height: 36px;
  padding: 6px 9px;
  border: 1px solid #8b8e91;
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.tree-matcher-demo > input[type="text"]:focus {
  border-color: var(--accent);
  outline: 1px solid var(--accent);
  outline-offset: 0;
}

.tree-demo-strict {
  display: flex;
  width: max-content;
  align-items: center;
  gap: 6px;
  font-family: var(--sans);
  font-size: 0.74rem;
}

.tree-demo-strict input {
  margin: 0;
}

.tree-demo-result {
  margin-top: 4px;
  overflow-x: auto;
  padding: 13px 12px 9px;
  border-top: 1px solid var(--line);
}

.tree-demo-render {
  min-width: max-content;
  color: #757a7e;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.9;
  white-space: nowrap;
}

.tree-demo-term.is-match {
  background: #e6e8e8;
  color: var(--ink);
  box-shadow: 0 0 0 2px #e6e8e8;
}

.tree-demo-term.is-match[data-match-tone="1"] {
  background: #ced4d7;
  box-shadow: 0 0 0 2px #ced4d7;
}

.tree-demo-status {
  margin: 7px 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.62rem;
  line-height: 1.4;
}

.tree-demo-status.is-error {
  color: #8a2634;
}

.effect-rules {
  display: grid;
  margin: 1.7rem 0 2rem;
  border: 1px solid var(--line);
  border-bottom: 0;
}

.effect-rules > div {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  border-bottom: 1px solid var(--line);
}

.effect-rules span,
.effect-rules code {
  padding: 9px 12px;
}

.effect-rules span {
  color: var(--muted);
  background: var(--wash);
  font-family: var(--mono);
  font-size: 0.66rem;
  text-transform: uppercase;
}

.effect-rules code {
  overflow-x: auto;
  border-left: 1px solid var(--line);
  font-size: 0.74rem;
  white-space: nowrap;
}

@media (max-width: 820px) {
  .site-shell {
    width: min(calc(100% - 36px), 720px);
    padding-top: 34px;
  }
}

@media (max-width: 540px) {
  html {
    font-size: 17px;
  }

  .site-shell {
    width: calc(100% - 28px);
  }

  .site-masthead {
    padding-bottom: 14px;
  }

  .masthead-links {
    gap: 16px;
  }

  .masthead-portrait,
  .masthead-portrait img {
    width: 40px;
    height: 40px;
  }

  .home-content {
    margin-top: 52px;
  }

  .post-list li {
    margin-bottom: 25px;
  }

  .post-title {
    font-size: 1.08rem;
  }

  .post-description {
    font-size: 0.78rem;
  }

  .article-column {
    margin-top: 52px;
  }

  .article-header {
    padding: 0 0 34px;
  }

  .article-header h1 {
    font-size: 1.85rem;
  }

  .prose {
    padding-top: 31px;
  }

  .prose h2 {
    margin-top: 2.8rem;
  }

  .technical-post > pre,
  .code-block pre,
  .technical-post pre.listing {
    font-size: 0.7rem;
  }

  .technical-post .code-line {
    padding-left: 48px;
  }

  .technical-post .code-line::before {
    width: 35px;
  }

  .effect-rules > div {
    grid-template-columns: 72px minmax(0, 1fr);
  }
}
