:root {
  color-scheme: light dark;
  --bg: #f8f8f5;
  --fg: #202124;
  --muted: #6d6d64;
  --line: #d9d8cf;
  --link: #0b5cad;
  --panel: #ffffff;
  --code-bg: #f1f3f5;
  --code-fg: #24292f;
  --code-muted: #6e7781;
  --code-keyword: #cf222e;
  --code-string: #0a3069;
  --code-number: #0550ae;
  --code-name: #8250df;
  --code-operator: #0550ae;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151515;
    --fg: #eeeeea;
    --muted: #aaa99f;
    --line: #33332f;
    --link: #8ab4f8;
    --panel: #1d1d1b;
    --code-bg: #202124;
    --code-fg: #e8eaed;
    --code-muted: #9aa0a6;
    --code-keyword: #ff7b72;
    --code-string: #a5d6ff;
    --code-number: #79c0ff;
    --code-name: #d2a8ff;
    --code-operator: #79c0ff;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 17px/1.65 Helvetica, Arial, sans-serif;
  overflow-wrap: break-word;
}

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

img {
  max-width: 100%;
  height: auto;
}

.wrap {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.site-header .wrap {
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0;
}

.site-title {
  color: var(--fg);
  font-weight: 700;
  text-decoration: none;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  font-size: 0.92rem;
}

.top-quote {
  padding-top: 18px;
  color: var(--muted);
  font-size: 0.95rem;
}

.top-quote[hidden] {
  display: none;
}

.top-quote p {
  margin: 0;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.top-quote cite {
  display: block;
  margin-top: 4px;
  font-style: normal;
}

.top-quote cite:not(:empty)::before {
  content: "- ";
}

.page {
  padding: 42px 0 56px;
}

h1,
h2,
h3 {
  line-height: 1.2;
  overflow-wrap: break-word;
}

h1 {
  font-size: clamp(2rem, 6vw, 3.4rem);
  margin: 0 0 16px;
}

h2 {
  margin-top: 36px;
}

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

.post-summary {
  padding: 26px 0;
  border-top: 1px solid var(--line);
}

.post-summary h2 {
  margin: 0 0 6px;
  font-size: 1.35rem;
}

.post-summary h2 a {
  color: var(--fg);
  text-decoration: none;
  overflow-wrap: break-word;
}

.pagination {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 30px 0 0;
  border-top: 1px solid var(--line);
}

.pagination a {
  color: var(--fg);
  font-weight: 700;
  text-decoration: none;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 0.92rem;
}

.post-header {
  margin-bottom: 34px;
  border-bottom: 1px solid var(--line);
}

.content {
  max-width: 780px;
}

.content pre {
  overflow-x: auto;
  padding: 16px;
  border: 1px solid var(--line);
  background: var(--code-bg);
  color: var(--code-fg);
}

.content code {
  font-size: 0.92em;
}

.content :not(pre) > code {
  padding: 0.12em 0.28em;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--code-bg);
  color: var(--code-fg);
}

.highlight {
  margin: 1.2em 0;
}

.highlight pre {
  margin: 0;
}

.highlight code,
.chroma {
  background: transparent;
  color: var(--code-fg);
}

.chroma .c,
.chroma .ch,
.chroma .cm,
.chroma .c1,
.chroma .cs,
.chroma .cp {
  color: var(--code-muted);
}

.chroma .k,
.chroma .kc,
.chroma .kd,
.chroma .kn,
.chroma .kp,
.chroma .kr,
.chroma .kt,
.chroma .nt {
  color: var(--code-keyword);
}

.chroma .s,
.chroma .sa,
.chroma .sb,
.chroma .sc,
.chroma .dl,
.chroma .sd,
.chroma .s2,
.chroma .se,
.chroma .sh,
.chroma .si,
.chroma .sx,
.chroma .sr,
.chroma .s1,
.chroma .ss {
  color: var(--code-string);
}

.chroma .m,
.chroma .mb,
.chroma .mf,
.chroma .mh,
.chroma .mi,
.chroma .il,
.chroma .mo {
  color: var(--code-number);
}

.chroma .na,
.chroma .nb,
.chroma .nc,
.chroma .nd,
.chroma .ne,
.chroma .nf,
.chroma .fm,
.chroma .nx {
  color: var(--code-name);
}

.chroma .o,
.chroma .ow {
  color: var(--code-operator);
}

.diagram {
  margin: 1.8em 0;
  overflow-x: auto;
  padding: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.diagram pre.mermaid {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg);
}

.diagram svg {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.diagram figcaption {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.diagram-pipeline {
  padding: 12px;
}

.diagram-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.diagram-toolbar[hidden] {
  display: none;
}

.diagram-size-toggle {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--link);
  font: inherit;
  font-size: 0.85rem;
  padding: 5px 10px;
  cursor: pointer;
}

.diagram-size-toggle:focus-visible,
.diagram-viewport:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 3px;
}

.diagram-viewport {
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.diagram-pipeline pre.mermaid {
  overflow: visible;
}

.diagram-pipeline .cluster rect {
  fill: var(--code-bg) !important;
  stroke: var(--line) !important;
}

@media print {
  .diagram-toolbar {
    display: none;
  }
  .diagram-pipeline svg {
    width: 100% !important;
    max-width: 100% !important;
  }
}

.table-scroll {
  overflow-x: auto;
  margin: 1.5em 0;
}

.table-scroll table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88em;
  font-variant-numeric: tabular-nums;
}

.table-scroll th,
.table-scroll td {
  padding: 0.7em 0.9em;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.table-scroll th {
  background: var(--code-bg);
  line-height: 1.35;
}

.table-scroll[aria-label="Decode throughput comparison"] td {
  text-align: right;
  white-space: nowrap;
}

.table-scroll[aria-label="Decode throughput comparison"] td:first-child {
  text-align: left;
  white-space: normal;
}

.algorithm-detail {
  margin: 1.5em 0;
  padding: 0.8em 1em;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.algorithm-detail summary {
  cursor: pointer;
  font-weight: 600;
}

.algorithm-detail .academic-algorithm {
  margin-bottom: 0.4em;
}

.academic-algorithm {
  margin: 2em 0;
  border-top: 2px solid var(--fg);
  border-bottom: 2px solid var(--fg);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.55;
}

.academic-algorithm h4 {
  margin: 0;
  padding: 0.55em 0.4em;
  border-bottom: 1px solid var(--fg);
  font-size: 1em;
  font-weight: normal;
}

.algorithm-specification {
  padding: 0.5em 0.4em;
}

.algorithm-specification p {
  margin: 0.15em 0;
}

.algorithm-scroll {
  overflow-x: auto;
}

.algorithm-lines {
  list-style: none;
  counter-reset: algorithm-line;
  margin: 0;
  padding: 0.4em 0.5em 0.6em 0;
  min-width: 0;
}

.algorithm-lines li {
  position: relative;
  counter-increment: algorithm-line;
  padding-left: calc(2.5em + var(--algorithm-depth, 0) * 1.25em);
  margin: 0.1em 0;
}

.algorithm-lines li::before {
  content: counter(algorithm-line);
  position: absolute;
  left: 0;
  width: 1.65em;
  text-align: right;
  color: var(--muted);
  font-size: 0.85em;
  line-height: 1.8;
  font-variant-numeric: tabular-nums;
}

.algorithm-invariant {
  border-top: 1px solid var(--line);
  margin: 0;
  padding: 0.5em 0.4em;
}

/* Keep long formulas scrollable within a line without widening the algorithm. */
.academic-algorithm .katex {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  vertical-align: middle;
}

@media (max-width: 680px) {
  .algorithm-lines li {
    padding-left: calc(2.1em + var(--algorithm-depth, 0) * 0.85em);
  }
}

@media print {
  .algorithm-lines {
    min-width: 0;
  }
}

.terms {
  padding: 0;
  list-style: none;
}

.terms li {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.site-footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer .wrap {
  padding: 24px 0;
}

@media (max-width: 680px) {
  .wrap {
    width: min(920px, calc(100% - 40px));
  }

  .site-header .wrap {
    align-items: flex-start;
    flex-direction: column;
  }
}
