/*
 * code.css - inline code and fenced code blocks.
 *
 * The readability problems this replaces (from the web part this project is
 * based on) were: a hard-coded near-black block background in every theme, a
 * text-shadow over the code, an inset black box-shadow, line-height:0 on the
 * <code> element, and line numbers positioned absolutely so they overlapped
 * long lines. None of that is here: colours come from the theme, the gutter is
 * a sticky column that survives horizontal scrolling, and the numbers are CSS
 * counters so "copy" never picks them up.
 */

/* ------------------------------------------------------------ inline code */

.strata-content code {
  padding: 0.15em 0.35em;
  border: 1px solid var(--strata-code-inline-border, transparent);
  border-radius: var(--strata-radius-sm);
  background-color: var(--strata-code-inline-bg);
  color: var(--strata-code-inline-text);
  font-family: var(--strata-font-mono);
  font-size: var(--strata-code-font-size);
  font-variant-ligatures: none;
}

/* Links and headings keep their own colour for inline code. */
.strata-content a code { color: inherit; }
.strata-content h1 code,
.strata-content h2 code,
.strata-content h3 code,
.strata-content h4 code { font-size: 0.9em; }

/* ------------------------------------------------------------ code blocks */

.strata-code {
  position: relative;
  margin: 0 0 var(--strata-block-gap);
  border: 1px solid var(--strata-code-border);
  border-radius: var(--strata-code-radius);
  background-color: var(--strata-code-bg);
  overflow: hidden;
}

.strata-code-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 14px;
  border-bottom: 1px solid var(--strata-code-header-border, var(--strata-border));
  background-color: var(--strata-code-header-bg);
  font-family: var(--strata-font-mono);
  font-size: 0.75em;
  line-height: 1.4;
  color: var(--strata-text-muted);
}

.strata-code-lang {
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.strata-code-filename {
  color: var(--strata-text);
  font-weight: 600;
}

.strata-code-lang + .strata-code-filename::before {
  content: '\00b7';
  margin-right: 8px;
  color: var(--strata-text-faint);
}

.strata-code-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.strata-code-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border: 1px solid var(--strata-border);
  border-radius: var(--strata-radius-sm);
  background-color: var(--strata-bg-elevated);
  color: var(--strata-text-muted);
  font-family: inherit;
  font-size: 1em;
  line-height: 1.4;
  cursor: pointer;
  transition: color 0.12s ease, background-color 0.12s ease, border-color 0.12s ease;
}

.strata-code-btn:hover {
  background-color: var(--strata-bg-hover);
  border-color: var(--strata-border-strong);
  color: var(--strata-text);
}

.strata-code-btn[data-state='done'] {
  border-color: rgb(var(--strata-color-green));
  color: rgb(var(--strata-color-green));
}

.strata-code-btn[data-state='error'] {
  border-color: rgb(var(--strata-color-red));
  color: rgb(var(--strata-color-red));
}

.strata-code-btn svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* With the header switched off the copy button floats over the block and only
   appears on hover or keyboard focus. */
.strata-code:not(.strata-code--has-header) .strata-code-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.12s ease-in-out;
}

.strata-code:not(.strata-code--has-header):hover .strata-code-actions,
.strata-code:not(.strata-code--has-header):focus-within .strata-code-actions {
  opacity: 1;
}

.strata-code pre {
  margin: 0;
  padding: var(--strata-code-padding);
  overflow-x: auto;
  background-color: transparent;
  counter-reset: strata-line;
  color: var(--strata-code-text);
  font-family: var(--strata-font-mono);
  font-size: var(--strata-code-font-size);
  line-height: var(--strata-code-line-height);
  tab-size: 4;
}

.strata-code pre code {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  white-space: pre;
}

/* One block element per source line. width:max-content + min-width:100% lets
   the sticky gutter stay put while the line scrolls under it. */
.strata-code-line {
  display: block;
  width: max-content;
  min-width: 100%;
  counter-increment: strata-line;
}

.strata-code-ln {
  display: none;
  position: sticky;
  left: 0;
  z-index: 1;
  width: var(--strata-code-gutter-width, 2.5em);
  margin-right: 1em;
  padding-right: 0.75em;
  border-right: 1px solid var(--strata-code-gutter-border, var(--strata-border));
  background-color: var(--strata-code-bg);
  color: var(--strata-code-gutter-text);
  text-align: right;
  user-select: none;
  -webkit-user-select: none;
}

.strata-code-ln::before {
  content: counter(strata-line);
}

.strata-code--numbered .strata-code-ln {
  display: inline-block;
}

.strata-code--numbered pre {
  padding-left: 0;
}

.strata-code--numbered .strata-code-line:hover {
  background-color: var(--strata-code-line-hover, transparent);
}

/* Soft wrap instead of horizontal scrolling. */
.strata-code--wrap pre code,
.strata-code--wrap .strata-code-line {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.strata-code--wrap .strata-code-line {
  width: auto;
}

.strata-code--wrap .strata-code-ln {
  vertical-align: top;
}

/* With numbers shown as well, the text has to keep its wrapped continuations
   clear of the gutter - inline, they start back at the line box's left edge,
   under the numbers. A row does that without a hanging indent, and the gutter
   can stop being sticky here: a wrapped block has nothing scrolling under it.
   min-width on the text is what lets a long unbreakable token wrap instead of
   pushing the line wider than the block. */
.strata-code--wrap.strata-code--numbered .strata-code-line {
  display: flex;
  align-items: flex-start;
}

.strata-code--wrap.strata-code--numbered .strata-code-ln {
  position: static;
  flex: none;
}

.strata-code--wrap.strata-code--numbered .strata-code-line-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Scrollbars inside code blocks should read as part of the block. */
.strata-code pre::-webkit-scrollbar {
  height: 10px;
  width: 10px;
}

.strata-code pre::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 6px;
  background-clip: content-box;
  background-color: var(--strata-scrollbar-thumb, var(--strata-border-strong));
}

.strata-code pre::-webkit-scrollbar-track {
  background-color: transparent;
}
