/* Tokens: the homepage's paper, ink and one signal colour */
:root {
  --paper-2: #e5e1d9;
  --ink-2: #2b2926;
  --code: #151412;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  font-synthesis: none;
  color: var(--ink);
  color-scheme: light;
  background: var(--paper);
}
* {
  box-sizing: border-box;
}
html,
body {
  min-width: 280px;
  margin: 0;
}
html {
  scroll-padding-top: 24px;
}
body {
  font-size: 16px;
  line-height: 1.5;
  background: var(--paper);
}
a {
  color: inherit;
  text-decoration: none;
}
::selection {
  color: #fff;
  background: var(--signal);
}
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 3px;
}

.langs {
  display: flex;
  gap: 2px;
  padding-left: 18px;
  border-left: 1px solid var(--hair);
}
.langs a {
  padding: 1px 5px;
  color: var(--muted);
}
.langs a[aria-current] {
  color: var(--paper);
  background: var(--ink);
}
.langs a[aria-current]::after {
  display: none;
}

/* Index masthead: the word, with a signal full stop */
.masthead {
  padding: clamp(24px, 4vw, 56px) 0 clamp(20px, 2.6vw, 36px);
}
.masthead h1 {
  display: flex;
  gap: 0.06em;
  align-items: flex-end;
  margin: 0 0 -0.05em -0.04em;
  font-size: clamp(64px, 17.4vw, 280px);
  font-weight: 700;
  line-height: 0.8;
  letter-spacing: -0.075em;
}
.stop {
  flex: none;
  width: 0.19em;
  aspect-ratio: 1;
  margin-bottom: 0.02em;
  background: var(--signal);
  border-radius: 50%;
}

/* Lead: one sentence and the feed */
.lead {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 20px;
  align-items: start;
  padding: 18px 0 0;
  border-top: 2px solid var(--line);
}
.lead p {
  margin: 0;
}
.lead > p:first-child {
  grid-column: 1 / span 7;
  max-width: 26em;
  font-size: clamp(20px, 2vw, 30px);
  font-weight: 500;
  line-height: 1.22;
  letter-spacing: -0.02em;
  text-wrap: pretty;
}
.lead-actions {
  display: flex;
  grid-column: 9 / span 4;
  justify-content: flex-end;
}
.pill {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  min-height: 46px;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 500;
  border: 2px solid var(--line);
  border-radius: 999px;
  transition:
    background 0.2s,
    color 0.2s;
}
.pill:hover {
  color: var(--paper);
  background: var(--ink);
}

/* Section labels: mono caps on a heavy rule */
.block {
  margin-top: clamp(40px, 5vw, 72px);
}
.label {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding-top: 10px;
  margin: 0 0 4px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-top: 2px solid var(--line);
}
.label a:hover {
  color: var(--signal);
}

/* Series: big numbered tiles */
.cycles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  gap: 20px;
  margin-top: 16px;
}
.cycle {
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 10px;
  min-height: 300px;
  padding: 20px 22px 22px;
  background: var(--paper-2);
  border: 2px solid var(--line);
  transition:
    background 0.25s,
    color 0.25s;
}
.cycle-no {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
}
.cycle strong,
.cycle h3 {
  max-width: 14em;
  font-size: clamp(28px, 3vw, 44px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
}
.cycle-desc {
  max-width: 34em;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink-2);
}
.cycle-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cycle:hover {
  color: var(--paper);
  background: var(--ink);
}
.cycle:hover .cycle-desc {
  color: #cfcac2;
}
.progress {
  display: inline-flex;
  gap: 3px;
}
.progress i {
  width: 18px;
  height: 8px;
  border: 1.5px solid currentcolor;
}
.progress i.on {
  background: var(--signal);
  border-color: var(--signal);
}

/* Post rows, as in the homepage columns */
.rows {
  padding: 0;
  margin: 0;
  list-style: none;
}
.rows > li {
  border-bottom: 1px solid var(--hair);
}
.row {
  position: relative;
  display: flex;
  gap: 24px;
  align-items: baseline;
  justify-content: space-between;
  padding: 16px 0;
  transition:
    color 0.2s,
    padding 0.3s var(--ease);
}
.row-main {
  display: grid;
  gap: 4px;
  max-width: 52em;
}
.row-kicker {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.row-title {
  font-size: clamp(19px, 1.7vw, 24px);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.row-sub {
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink-2);
}
.row-meta {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 2px;
  align-items: flex-end;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.row::before {
  position: absolute;
  top: 29px;
  left: 0;
  width: 8px;
  height: 8px;
  content: "";
  background: var(--signal);
  border-radius: 50%;
  opacity: 0;
  transform: translateX(-4px);
  transition:
    opacity 0.2s,
    transform 0.3s var(--ease);
}
.row:hover {
  padding-left: 18px;
}
.row:hover .row-title {
  color: var(--signal);
}
.row:hover::before {
  opacity: 1;
  transform: none;
}
.empty {
  margin: 12px 0;
  color: var(--muted);
}

/* Post and series header */
.post-head {
  display: grid;
  gap: 16px;
  padding: clamp(28px, 4vw, 64px) 0 clamp(20px, 2.6vw, 32px);
  border-bottom: 2px solid var(--line);
}
.kicker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.kicker a {
  color: var(--signal);
}
.kicker a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.kicker span {
  color: var(--muted);
}
.post-head h1 {
  max-width: 16em;
  margin: 0;
  font-size: clamp(38px, 6vw, 96px);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.05em;
  text-wrap: balance;
}
.post-desc {
  max-width: 36em;
  margin: 0;
  font-size: clamp(18px, 1.6vw, 23px);
  font-weight: 500;
  line-height: 1.3;
  color: var(--ink-2);
  letter-spacing: -0.015em;
  text-wrap: pretty;
}
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  align-items: center;
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tag::before {
  content: "#";
}

/* Post grid: sidebar on the left three columns, text in the next seven */
.post-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 20px;
  padding-top: clamp(24px, 3vw, 44px);
}
.post-side {
  position: sticky;
  top: 24px;
  display: grid;
  grid-row: 1;
  grid-column: 1 / span 3;
  gap: 32px;
  align-content: start;
  align-self: start;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.series-page .post-side {
  gap: 0;
}
.post-body {
  grid-row: 1;
  grid-column: 4 / span 7;
  min-width: 0;
  max-width: 700px;
}
.side-block ol {
  padding: 0;
  margin: 6px 0 0;
  list-style: none;
}
.parts li,
.toc-item {
  font-size: 14px;
  line-height: 1.35;
  border-bottom: 1px solid var(--hair);
}
.parts a,
.parts .soon {
  display: grid;
  grid-template-columns: 2ch minmax(0, 1fr);
  gap: 2px 10px;
  padding: 9px 0;
}
.part-no {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}
.parts a:hover {
  color: var(--signal);
}
.parts a[aria-current] {
  font-weight: 600;
}
.parts a[aria-current] .part-no {
  color: var(--signal);
}
.parts .soon {
  color: var(--muted);
}
.parts .soon em {
  grid-column: 2;
  font-family: var(--mono);
  font-size: 11px;
  font-style: normal;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.toc-link {
  display: block;
  padding: 7px 0;
}
.toc-item.d3 .toc-link {
  padding-left: 14px;
  color: var(--muted);
}
.toc-link:hover {
  color: var(--signal);
}
.series-box {
  display: none;
  margin-bottom: 28px;
  border-top: 2px solid var(--line);
  border-bottom: 1px solid var(--hair);
}
.series-box summary {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.series-box-part {
  flex: none;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 400;
  color: var(--signal);
  text-transform: uppercase;
}

/* Prose */
.prose {
  font-size: 18px;
  line-height: 1.65;
  color: var(--ink-2);
  overflow-wrap: break-word;
}
.prose > :first-child {
  margin-top: 0;
}
.prose a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-decoration-color: var(--signal);
  text-underline-offset: 0.2em;
}
.prose a:hover {
  color: var(--signal);
}
.prose strong {
  font-weight: 600;
  color: var(--ink);
}
.prose :is(h2, h3, h4) {
  margin: 2em 0 0.55em;
  line-height: 1.15;
  color: var(--ink);
  letter-spacing: -0.025em;
  text-wrap: balance;
}
.prose h2 {
  padding-top: 18px;
  margin-top: 2.6em;
  font-size: clamp(26px, 2.4vw, 34px);
  font-weight: 700;
  border-top: 2px solid var(--line);
}
.prose h2::before {
  display: block;
  width: 28px;
  height: 6px;
  margin-bottom: 14px;
  content: "";
  background: var(--signal);
}
.prose :is(h2, h3, h4) + :is(h3, h4) {
  margin-top: 0.8em;
}
.prose h3 {
  font-size: 22px;
  font-weight: 650;
}
.prose h4 {
  font-size: 18px;
  font-weight: 650;
}
.prose :is(p, ul, ol, table, blockquote) {
  margin: 0 0 1.15em;
}
.prose :is(ul, ol) {
  padding-left: 1.4em;
}
.prose li + li {
  margin-top: 0.35em;
}
.prose li::marker {
  font-family: var(--mono);
  font-size: 0.85em;
  color: var(--signal);
}
.prose li > :is(ul, ol) {
  margin: 0.35em 0 0;
}
.prose li > p {
  margin: 0 0 0.4em;
}
.prose code {
  padding: 0.1em 0.35em;
  font-family: var(--mono);
  font-size: 0.85em;
  color: var(--ink);
  background: var(--paper-2);
  border-radius: 3px;
}
.prose pre {
  padding: 16px 20px;
  margin: 1.5em 0 1.6em;
  overflow-x: auto;
  font-size: 14px;
  line-height: 1.6;
  color: #e8e4dc;
  scrollbar-color: #555 transparent;
  scrollbar-width: thin;
  background: var(--code);
  border-radius: 0;
}

/* Code blocks: a file tab, and long blocks folded to their first lines */
.code {
  position: relative;
  margin: 1.5em 0 1.6em;
  background: var(--code);
}
.prose .code pre {
  margin: 0;
}
.code-head {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 9px 20px;
  font-family: var(--mono);
  font-size: 12px;
  color: #a8a29a;
  border-bottom: 1px solid #ffffff1a;
}
.code-file {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #f2efe9;
  white-space: nowrap;
}
.code-file::before {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 10px;
  vertical-align: 1px;
  content: "";
  background: var(--signal);
  border-radius: 50%;
}
.code-lang {
  flex: none;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.code-toggle {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  clip-path: inset(50%);
}
.folds .code-toggle:not(:checked) + pre {
  /* PREVIEW lines of code plus the top padding */
  max-height: calc(10 * 1.6em + 16px);
  overflow: hidden;
  mask-image: linear-gradient(#000 45%, transparent);
}
.code-more {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 20px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: #f2efe9;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  user-select: none;
  border-top: 1px solid #ffffff1a;
  transition:
    background 0.2s,
    color 0.2s;
}
.code-more::after {
  content: "↓";
  transition: transform 0.25s var(--ease);
}
.code-more:hover {
  color: #fff;
  background: var(--signal);
}
.code-toggle:focus-visible ~ .code-more {
  outline: 2px solid var(--signal);
  outline-offset: -2px;
}
.code-toggle:checked ~ .code-more::after {
  transform: rotate(180deg);
}
.code-more-close,
.code-toggle:checked ~ .code-more .code-more-open {
  display: none;
}
.code-toggle:checked ~ .code-more .code-more-close {
  display: inline;
}
.prose pre code {
  padding: 0;
  font-size: inherit;
  color: inherit;
  background: none;
}
.prose blockquote {
  padding: 2px 0 2px 20px;
  margin-left: 0;
  font-size: 20px;
  font-weight: 500;
  line-height: 1.45;
  color: var(--ink);
  border-left: 3px solid var(--signal);
}
.prose table {
  display: block;
  max-width: 100%;
  margin: 1.5em 0 1.6em;
  overflow-x: auto;
  font-size: 15px;
  line-height: 1.45;
  border-collapse: collapse;
}
.prose :is(th, td) {
  padding: 9px 14px 9px 0;
  vertical-align: top;
  text-align: left;
  border-bottom: 1px solid var(--hair);
}
.prose th {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--line);
}
.prose img {
  max-width: 100%;
  height: auto;
}
.prose hr {
  margin: 2.5em 0;
  border: 0;
  border-top: 2px solid var(--line);
}

/* Code: Shiki writes both themes as variables; blocks are always dark ink. */
.prose pre.shiki {
  background: var(--code) !important;
}
.prose .shiki span {
  color: var(--shiki-dark);
}

/* Formulas */
.prose .katex {
  font-size: 1.05em;
}
.prose .katex-display {
  padding: 4px 0;
  margin: 0 0 1.1em;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Callouts */
.callout {
  padding: 16px 20px 18px;
  margin: 1.5em 0;
  font-size: 17px;
  line-height: 1.6;
  background: var(--paper-2);
  border-left: 3px solid var(--ink);
}
.callout > :last-child {
  margin-bottom: 0;
}
.callout:is(.note, .warning, .tldr)::before {
  display: block;
  margin-bottom: 8px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.callout.tldr::before {
  content: "TL;DR";
}
.callout.note::before {
  content: "Note";
}
.callout.warning::before {
  content: "Careful";
}
:lang(ru) .callout.tldr::before {
  content: "Коротко";
}
:lang(ru) .callout.note::before {
  content: "Заметка";
}
:lang(ru) .callout.warning::before {
  content: "Осторожно";
}
.prose > .callout.tldr:first-child {
  margin-top: 0;
}
.callout.note {
  border-left-color: #2f5fd0;
}
.callout.warning {
  border-left-color: #e0a100;
}
.callout.tldr {
  border-left-color: var(--signal);
}
.callout.proof {
  border-left-color: var(--muted);
}
.callout summary {
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.callout[open] summary {
  margin-bottom: 0.6em;
}

/* Footnotes */
.prose .footnotes {
  margin-top: 3em;
  font-size: 15px;
  color: var(--muted);
}
.prose .footnotes h2 {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  counter-increment: none;
}
.prose .footnotes h2::before {
  display: none;
}
.prose .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.prose sup a {
  text-decoration: none;
}

/* Previous and next part */
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 56px;
  border-top: 2px solid var(--line);
}
.pager-link {
  display: grid;
  gap: 6px;
  align-content: start;
  padding: 14px 0 4px;
  transition: color 0.2s;
}
.pager-link.next {
  text-align: right;
}
.pager-label {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.pager-title {
  font-size: 19px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.015em;
}
.pager-link:hover {
  color: var(--signal);
}

@media (max-width: 1100px) {
  .post-side {
    grid-column: 1 / span 4;
  }
  .post-body {
    grid-column: 5 / span 8;
  }
}
@media (max-width: 900px) {
  .lead > p:first-child,
  .lead-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
  .post-grid {
    display: flex;
    flex-direction: column;
  }
  .post-side {
    display: none;
  }
  .series-page .post-side {
    position: static;
    display: block;
    order: 2;
    max-height: none;
    margin-top: 24px;
  }
  .post-body {
    max-width: none;
  }
  .series-box {
    display: block;
  }
}
@media (max-width: 560px) {
  .langs {
    padding-left: 10px;
  }
  .masthead h1 {
    font-size: 24vw;
  }
  .prose {
    font-size: 17px;
  }
  .prose > pre,
  .code {
    margin-right: calc(-1 * var(--gutter));
    margin-left: calc(-1 * var(--gutter));
  }
  .prose pre,
  .code-head,
  .code-more {
    padding-right: var(--gutter);
    padding-left: var(--gutter);
  }
  .prose pre {
    font-size: 13px;
  }
  .row {
    flex-direction: column;
    gap: 8px;
  }
  .row-meta {
    flex-direction: row;
    gap: 12px;
  }
  .cycle {
    min-height: 0;
  }
  .pager {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .pager-link.next {
    text-align: left;
  }
}

/* Diagrams: ```mermaid rendered to inline SVG at build time. */
.prose .diagram {
  margin: 2em 0;
  overflow-x: auto;
  text-align: center;
}
.prose .diagram svg {
  max-width: 100%;
  height: auto;
}
.prose .diagram .edge-label text {
  fill: var(--ink-2);
}

/* News widget: digest stories on the post's topic (::news in Markdown). */
.prose .news-widget {
  margin: 2.2em 0;
  font-size: 16px;
  line-height: 1.5;
  border-top: 2px solid var(--line);
  border-bottom: 1px solid var(--hair);
}
.prose .news-widget p {
  margin: 0;
}
.prose .news-head {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  justify-content: space-between;
  padding: 10px 0 12px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.prose .news-kicker {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}
.prose .news-dot {
  width: 8px;
  height: 8px;
  background: var(--signal);
  border-radius: 50%;
}
.prose .news-topic {
  color: var(--muted);
}
.prose .news-list {
  padding: 0;
  margin: 0;
  list-style: none;
}
.prose .news-item {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  padding: 14px 0;
  margin: 0;
  border-top: 1px solid var(--hair);
}
.prose .news-no {
  padding-top: 3px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--signal);
}
.prose .news-main {
  min-width: 0;
}
.prose a.news-title {
  display: block;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.35;
  text-decoration: none;
}
.prose a.news-title:hover {
  color: var(--signal);
}
.prose .news-text {
  margin-top: 4px;
  color: var(--ink-2);
}
.prose .news-meta,
.prose .news-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}
.prose .news-meta {
  margin-top: 6px;
}
.prose .news-foot {
  justify-content: space-between;
  padding: 10px 0 12px;
  border-top: 1px solid var(--hair);
}
.prose .news-foot a {
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-decoration: none;
}
@media (max-width: 560px) {
  .prose .news-item {
    grid-template-columns: 28px 1fr;
    gap: 8px;
  }
  .prose .news-text {
    font-size: 15px;
  }
}
