/*
 * Syntax Highlight Overlay
 *
 * Transparent textarea technique: the textarea has transparent text color
 * so the user sees the colored spans in the overlay div behind it, while
 * still being able to type and interact with the native textarea.
 */

.syntax-highlight-container {
  font-family: 'Source Code Pro', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.875rem;
  line-height: 1.5;
}

.syntax-highlight-editor {
  position: relative;
}

/*
 * The overlay and the textarea must lay out every character identically —
 * same box (border/padding/width), same scrollbar gutter, same font weight
 * and style on every span — or the two diverge as the text grows (a wrap
 * decision flips a few characters differently in one layer than the other)
 * and the real caret drifts away from the highlighted text under it. Rather
 * than measure glyphs at runtime to compensate, these rules just make a
 * divergence impossible: no border of its own (the visible border lives on
 * .syntax-highlight-editor, one level up, shared by both layers equally),
 * a stable scrollbar gutter on both regardless of whether either currently
 * scrolls, and highlight classes below that only ever change color/decoration
 * — never weight, style, or spacing, all of which can change a character's
 * advance width depending on the font actually installed on the system.
 */
.syntax-highlight-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  overflow: hidden;
  scrollbar-gutter: stable;
  padding: 0.5rem;
  border: none;
  color: var(--dark-gray);
}

.syntax-highlight-container textarea {
  position: relative;
  z-index: 1;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--dark-gray);
  background: transparent;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  overflow-y: auto;
  scrollbar-gutter: stable;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  border: none;
  padding: 0.5rem;
  width: 100%;
  resize: vertical;
}

/* Highlight classes. Color and background only — font-weight, font-style,
   and letter-spacing are off limits here (see comment above); a header or
   rule line is distinguished by color and, for headers, an underline, never
   by anything that could change how wide the text renders. */
.hl-header {
  color: var(--primary-color-dark);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.hl-quantity {
  color: var(--hl-quantity);
}

.hl-element {
  color: var(--hl-element);
}

.hl-condition {
  color: var(--hl-condition);
}

.hl-rest {
  color: var(--text-muted);
}

.hl-rule {
  color: var(--text-muted);
}

.hl-scaling {
  color: var(--hl-scaling);
}

/* Text the parser skipped. A tint behind the characters, never a color on
   them: the textarea above the overlay is transparent, so the tint shows
   through under whatever the coach typed. */
.hl-error {
  background: color-mix(in oklch, var(--danger-color) 28%, transparent);
  border-radius: 2px;
  box-shadow: 0 0 0 1px color-mix(in oklch, var(--danger-color) 45%, transparent);
}
