code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  font-feature-settings: "liga" 0;
}

/* Inline code stays part of the prose. */
:not(pre) > code {
  background: var(--code-inline-surface);
  border: 1px solid var(--code-border);
  border-radius: var(--radius-sm);
  padding: 0.12em 0.36em;
  color: var(--ink);
  word-break: break-word;
}

/* --- the code card -------------------------------------------------------- */

/* A code card is a distinct surface rather than part of the page, so it stays dark
   in both themes the way an editor or a terminal does. That also means one set of
   syntax colours instead of two that have to be kept in balance. */
.code {
  --code-bg: #14171c;
  --code-chrome: #1b1f26;
  --code-hairline: #2b313b;
  --code-gutter: #4d5666;

  margin: var(--space-6) 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--code-bg);
  border: 1px solid var(--code-hairline);
  box-shadow: var(--shadow-sm);
}

.code__header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--code-chrome);
  border-bottom: 1px solid var(--code-hairline);
}

.code__file {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: #b9c1cd;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code__lang {
  margin-left: auto;
  flex: none;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--code-gutter);
}

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

.code__pre {
  margin: 0;
  padding: var(--space-4) var(--space-4) var(--space-4) 0;
  background: none;
  border: 0;
  border-radius: 0;
  font-size: var(--text-sm);
  line-height: 1.6;
  tab-size: 2;
}

.code__pre code {
  display: block;
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
  /* The counter drives the gutter, so selecting the code copies the code and not
     a column of line numbers. */
  counter-reset: line;
  /* The highlighter separates its line spans with real newlines. Inside a <pre>
     those are preserved and each one paints an extra empty line box on top of the
     block-level span, which double-spaces the whole block. Collapsing whitespace
     here and restoring it on the line itself is what keeps the spacing right. */
  white-space: normal;
}

.code__pre .line {
  display: block;
  white-space: pre;
  padding-right: var(--space-4);
  min-height: 1.5em;
}

.code__pre .line::before {
  counter-increment: line;
  content: counter(line);
  display: inline-block;
  width: 3.25rem;
  padding-right: var(--space-4);
  margin-right: var(--space-4);
  text-align: right;
  color: var(--code-gutter);
  border-right: 1px solid var(--code-hairline);
  user-select: none;
  -webkit-user-select: none;
}

/* A single-line snippet reads better without a gutter at all. */
.code__pre code:has(.line:only-child) .line::before {
  content: none;
  border-right: 0;
  width: 0;
  padding: 0;
  margin: 0;
}

.code__pre code:has(.line:only-child) .line {
  padding-left: var(--space-4);
}

/* Fallback for a block the highlighter did not recognise. */
.code__pre > code:not(:has(.line)) {
  display: block;
  padding-left: var(--space-4);
  color: #d7dce5;
  white-space: pre;
}

@media (max-width: 40rem) {
  .code__pre .line::before {
    width: 2rem;
    padding-right: var(--space-2);
    margin-right: var(--space-3);
  }
}
