code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--code-emphasis);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  color: var(--text);
}

pre {
  background: var(--code-bg);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  margin: 1em 0;
  font-family: var(--font-mono);
}

pre code {
  background: none;
  padding: 0;
  font-size: var(--font-size-code);
  line-height: var(--line-height-code);
  color: var(--text);
}

figure.highlight {
  background: var(--code-bg);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin: 1em 0;
  position: relative;
}

figure.highlight figcaption {
  display: none;
}

figure.highlight .highlight-bar {
  position: absolute;
  top: 0;
  right: 0;
  padding: 0.3em 0.85em;
  font-size: 0.9rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--code-bg);
  border-bottom-left-radius: var(--radius-md);
  cursor: pointer;
  border: none;
  z-index: var(--z-code-controls);
  transition: color var(--trans-fast);
}

figure.highlight .highlight-bar:hover,
figure.highlight .highlight-bar.copied {
  color: var(--accent);
}

figure.highlight table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
}

figure.highlight td {
  border: none;
  padding: 0;
  text-align: left;
}

figure.highlight .gutter {
  width: 2.5em;
  text-align: right;
  padding: 0.6em 0.5em 0.6em 0;
  color: var(--text-muted);
  user-select: none;
  font-family: var(--font-mono);
  font-size: var(--font-size-code);
  line-height: var(--line-height-code);
  vertical-align: top;
}

figure.highlight .gutter pre {
  margin: 0;
  background: none;
  border-radius: 0;
}

figure.highlight .code {
  padding: 0.6em 1em;
  line-height: var(--line-height-code);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--font-size-code);
  vertical-align: top;
}

figure.highlight .code pre {
  margin: 0;
  background: none;
  border-radius: 0;
}

figure.highlight .comment,
figure.highlight .quote {
  color: var(--hl-comment);
}

figure.highlight .keyword,
figure.highlight .selector-tag,
figure.highlight .addition {
  color: var(--hl-keyword);
}

figure.highlight .string,
figure.highlight .number,
figure.highlight .literal {
  color: var(--hl-string);
}

figure.highlight .title,
figure.highlight .section,
figure.highlight .name {
  color: var(--hl-function);
}

figure.highlight .code-body {
  max-height: var(--code-collapse-height);
  overflow: hidden;
  position: relative;
  isolation: isolate;
  transition: max-height var(--trans-slow) ease;
}

figure.highlight .code-scroll {
  overflow-x: auto;
  overflow-y: hidden;
}

figure.highlight .code-body.collapsible:not(.expanded) .code-scroll {
  -webkit-mask-image: linear-gradient(
    to bottom,
    #000 0,
    #000 calc(var(--code-collapse-height) - 100px),
    transparent calc(var(--code-collapse-height) - 8px)
  );
  mask-image: linear-gradient(
    to bottom,
    #000 0,
    #000 calc(var(--code-collapse-height) - 100px),
    transparent calc(var(--code-collapse-height) - 8px)
  );
}

figure.highlight .code-body.expanded {
  max-height: none;
}

figure.highlight .code-body.collapsible:not(.expanded)::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100px;
  background: linear-gradient(transparent 0%, var(--bg) 85%);
  pointer-events: none;
  z-index: 1;
}

figure.highlight .code-expand {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  z-index: var(--z-code-controls);
  transition: color var(--trans-fast);
}

figure.highlight .code-expand:hover {
  color: var(--accent);
}

figure.highlight .code-expand.hidden {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  figure.highlight .code-body {
    transition: none;
  }
}
