/* ============================================================================
   CodeMirror — custom "nanovm" theme (GitHub-light) + editor line decorations.
   Own theme class (.cm-s-nanovm, selected via theme:"nanovm" at init) so the
   vendored codemirror.min.css default theme never collides, whatever the load
   order. Bundled on every page by :app but only used on /editor. Theme tokens
   (--nv-*) live in application.css. Split out of editor.css.
   ========================================================================= */
.CodeMirror {
  height: 100% !important;
  font-family: var(--nv-mono);
  font-size: 14px;
  line-height: 1.5;
}

.CodeMirror-scroll {
  overflow-y: auto !important;
  overflow-x: auto !important;
}

.cm-s-nanovm.CodeMirror {
  background-color: var(--nv-bg);
  color: var(--nv-syntax-fg);
}

/* Text cursor in the theme's ink — the vendored default is fixed black and
   vanishes on the dark ground. */
.cm-s-nanovm .CodeMirror-cursor {
  border-left-color: var(--nv-text);
}

/* Gutter + active line — override the vendored light-only defaults with theme
   tokens so both flip with [data-bs-theme="dark"]. */
/* No rule beside the gutter: without line numbers it only holds the lint
   markers and the debugger arrow, and a line there reads as a stray edge. */
.cm-s-nanovm .CodeMirror-gutters {
  background-color: var(--nv-bg);
  border-right: 0;
}
.cm-s-nanovm .CodeMirror-linenumber {
  color: var(--nv-muted);
}
/* Current line: no tinted row — a 4px ink bar instead, starting 20px left of
   the code. It is painted in the gutter (the active-line addon tags the
   line's gutter background): the code starts 4px right of the gutter (line
   padding), so 12px from the gutter's right edge puts the bar's left edge at
   20px. The gutter is 44px wide so this bar and the diff bars (30px, below)
   clear the lint markers and the debugger arrow at its left; .nv-editor's
   padding gives the extra 28px back. */
.cm-s-nanovm .CodeMirror-activeline-background {
  background: transparent;
}

.cm-s-nanovm .CodeMirror-activeline-gutter {
  background: linear-gradient(var(--nv-text), var(--nv-text)) no-repeat right 12px top / 4px 100%;
}

.cm-s-nanovm {
  --nv-gutter-w: 44px;
}

.cm-s-nanovm .CodeMirror-lint-markers {
  width: var(--nv-gutter-w);
}

/* Syntax highlighting tuned for NanoC (GitHub-light palette) */
.cm-s-nanovm .cm-meta {
  color: var(--nv-syntax-comment);
}
.cm-s-nanovm .cm-keyword {
  color: var(--nv-syntax-keyword);
}
.cm-s-nanovm .cm-type {
  color: var(--nv-syntax-type);
  font-style: italic;
}
.cm-s-nanovm .cm-qualifier {
  color: var(--nv-syntax-type);
}
.cm-s-nanovm .cm-builtin {
  color: var(--nv-syntax-type);
}
.cm-s-nanovm .cm-def {
  color: var(--nv-syntax-def);
}
.cm-s-nanovm .cm-variable {
  color: var(--nv-syntax-fg);
}
.cm-s-nanovm .cm-variable-2 {
  color: var(--nv-syntax-type);
}
.cm-s-nanovm .cm-string {
  color: var(--nv-syntax-string);
}
.cm-s-nanovm .cm-string-2 {
  color: var(--nv-syntax-string);
}
.cm-s-nanovm .cm-number {
  color: var(--nv-syntax-type);
}
.cm-s-nanovm .cm-comment {
  color: var(--nv-syntax-comment);
  font-style: italic;
}
.cm-s-nanovm .cm-operator {
  color: var(--nv-syntax-keyword);
}
.cm-s-nanovm .cm-atom {
  color: var(--nv-syntax-type);
}
.cm-s-nanovm .cm-attribute {
  color: var(--nv-syntax-def);
}

/* Error markers */
.error-line {
  background-color: rgba(var(--bs-danger-rgb), 0.1) !important;
}
.error-marker {
  color: var(--bs-danger);
  font-weight: bold;
}

/* Inline version diff (editor.showDiff): no tinted rows, in either theme —
   only a 4px bar starting 30px left of the code. Green beside lines the
   current buffer has over the compared version (the line itself is not
   styled); red beside removed blocks, which hang below the line they
   followed as widgets showing the old text in grey.
   Geometry as for the current-line bar above: the code starts 4px right of
   the gutter, so 22px from the gutter's right edge = 30px left of the code.
   The current-line bar (20px) and a diff bar can share a line. */
.cm-s-nanovm .nv-diff-added {
  background: linear-gradient(var(--bs-success), var(--bs-success)) no-repeat right 22px top / 4px 100%;
}

.cm-s-nanovm .nv-diff-added.CodeMirror-activeline-gutter {
  background:
    linear-gradient(var(--nv-text), var(--nv-text)) no-repeat right 12px top / 4px 100%,
    linear-gradient(var(--bs-success), var(--bs-success)) no-repeat right 22px top / 4px 100%;
}

/* The widget covers the gutter (coverGutter: it starts at the gutter's left
   edge), so the bar can sit left of the code. Padding of one gutter width
   puts the old text back in line with the code; the bar lands 22px from the
   gutter's right edge, like the green one. */
.nv-diff-removed {
  position: relative;
  padding-left: var(--nv-gutter-w);
}

.nv-diff-removed::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--nv-gutter-w) - 26px);
  width: 4px;
  background: var(--bs-danger);
}

.nv-diff-removed pre {
  margin: 0;
  padding: 0 4px;
  font-family: var(--nv-mono);
  font-size: 14px;
  line-height: 1.5;
  color: var(--nv-muted);
  background: transparent;
  white-space: pre;
}

/* Configurators: controls the editor puts over annotated code
   (engine/configurator-layer; markup from app/views/configurators). A
   control covers its code: a box with the name of what it stands for and
   the value, and beside the box the button that shows the source. The box
   is a tinted ground; frame and button show only while it is marked.
   Fields have a line, buttons a hairline; one radius (the theme's) and one height for everything one can
   click. */
.cm-s-nanovm {
  --nv-cfg-h: 20px;
  --nv-cfg-line: var(--bs-tertiary-color);
  /* The editor is the container a control's width is measured against. */
  container-type: inline-size;
}

/* Box and, 10px beside it, the button to the source. Never wider than the
   editor shows, however long its lines are: the box wraps instead. */
.nv-cfg-frame {
  display: inline-flex;
  align-items: flex-start;
  gap: 10px;
  max-width: calc(100cqw - var(--nv-gutter-w) - 16px);
  white-space: normal;
  vertical-align: top;
}

.nv-cfg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-sizing: border-box;
  padding: 0 8px;
  /* No frame until the control is marked; the line keeps the measures. */
  border: 1px solid transparent;
  border-radius: var(--bs-border-radius);
  background: var(--bs-tertiary-bg);
  color: var(--bs-secondary-color);
  font-family: var(--bs-font-sans-serif);
  font-size: 12px;
  white-space: normal;
  vertical-align: top;
}

/* A control is marked while one of its fields holds the focus or the text
   cursor stands on its line (a click on the control puts it there). Only
   then it has its frame and shows the button to the source; the button
   keeps its place, so nothing moves. */
.nv-cfg:focus-within,
.nv-cfg-frame:focus-within > .nv-cfg,
.CodeMirror-activeline .nv-cfg {
  border-color: var(--bs-secondary-color);
}

/* The text cursor right at a control: its frame blinks at the editor's
   pace, in place of the cursor line that would stand at the box's edge. */
.nv-cfg-holds-cursor .CodeMirror-cursor {
  display: none;
}

.CodeMirror-focused .nv-cfg-at-cursor > .nv-cfg {
  animation: nv-cfg-cursor 1.06s steps(1, end) infinite;
}

@keyframes nv-cfg-cursor {
  50% {
    border-color: transparent;
  }
}

@media (prefers-reduced-motion: reduce) {
  .CodeMirror-focused .nv-cfg-at-cursor > .nv-cfg {
    animation: none;
  }
}

.nv-cfg-frame > .nv-cfg-toggle {
  visibility: hidden;
}

.nv-cfg-frame:focus-within > .nv-cfg-toggle,
.CodeMirror-activeline .nv-cfg-frame > .nv-cfg-toggle {
  visibility: visible;
}

/* In place of one statement: 4px of room over and under its controls. The
   line grows with the box; a hair between the boxes of neighbouring lines. */
.nv-cfg--inline {
  height: 28px;
  margin: 1px 0;
}

/* In place of whole lines; may wrap and be higher than a line. */
.nv-cfg--block {
  flex-wrap: wrap;
  margin: 2px 0;
  padding: 7px 8px;
}

/* A note under a line. */
.nv-cfg--below {
  display: flex;
  flex-wrap: wrap;
  margin: 2px 0 4px 4px;
  padding: 10px 8px;
  width: fit-content;
  max-width: calc(100cqw - var(--nv-gutter-w) - 16px);
}

/* The control's name is an identifier of the code. In a line the names
   share a width, so the controls of neighbouring lines line up. */
.nv-cfg-label {
  color: var(--bs-body-color);
  font-family: var(--bs-font-monospace);
  font-weight: 500;
}

.nv-cfg--inline .nv-cfg-label {
  min-width: 10ch;
}

/* A fine line with a grip. */
.nv-cfg-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 140px;
  height: 16px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

.nv-cfg-slider::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--bs-secondary-color);
}

.nv-cfg-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 6px;
  height: 14px;
  margin-top: -6px;
  border: 0;
  border-radius: 1px;
  background: var(--bs-body-color);
}

.nv-cfg-slider::-moz-range-track {
  height: 2px;
  background: var(--bs-secondary-color);
}

.nv-cfg-slider::-moz-range-thumb {
  width: 6px;
  height: 14px;
  border: 0;
  border-radius: 1px;
  background: var(--bs-body-color);
}

/* On and off, with the word behind it. */
.nv-cfg-switch {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 26px;
  height: 14px;
  margin: 0;
  border: 1px solid var(--bs-secondary-color);
  border-radius: var(--bs-border-radius);
  background: var(--bs-body-bg);
  cursor: pointer;
}

.nv-cfg-switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 8px;
  height: 8px;
  border-radius: 1px;
  background: var(--bs-secondary-color);
  transition: transform 0.12s;
}

.nv-cfg-switch:checked {
  border-color: var(--bs-body-color);
  background: var(--bs-body-color);
}

.nv-cfg-switch:checked::before {
  transform: translateX(12px);
  background: var(--bs-body-bg);
}

.nv-cfg-state {
  min-width: 1.8em;
  color: var(--bs-body-color);
}

.nv-cfg-state::after {
  content: "Off";
}

.nv-cfg-switch:checked + .nv-cfg-state::after {
  content: "On";
}

.nv-cfg-text,
.nv-cfg-number,
.nv-cfg-select {
  height: var(--nv-cfg-h);
  padding: 0 4px;
  border: 1px solid var(--nv-cfg-line);
  border-radius: var(--bs-border-radius);
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  font: inherit;
}

/* Inside a line the box is one line high: its fields are a little lower. */
.nv-cfg--inline .nv-cfg-text,
.nv-cfg--inline .nv-cfg-number,
.nv-cfg--inline .nv-cfg-select {
  height: 16px;
}

.nv-cfg-text:focus-visible,
.nv-cfg-number:focus-visible,
.nv-cfg-select:focus-visible,
.nv-cfg-switch:focus-visible,
.nv-cfg-slider:focus-visible {
  border-color: var(--nv-accent);
  outline: 2px solid var(--bs-focus-ring-color);
  outline-offset: 0;
}

.nv-cfg-number {
  width: 4.5em;
}

.nv-cfg-color {
  width: 32px;
  height: var(--nv-cfg-h);
  padding: 0;
  border: 1px solid var(--nv-cfg-line);
  border-radius: var(--bs-border-radius);
  background: none;
  cursor: pointer;
}

.nv-cfg-color::-webkit-color-swatch-wrapper {
  padding: 0;
}

.nv-cfg-color::-webkit-color-swatch {
  border: 0;
  border-radius: 2px;
}

.nv-cfg-color::-moz-color-swatch {
  border: 0;
  border-radius: 2px;
}

/* What a control stands at, written next to it (a colour's hex value, the
   length of a text). */
.nv-cfg-readout {
  font-family: var(--bs-font-monospace);
  font-size: 11px;
}

.nv-cfg-readout--hex {
  text-transform: uppercase;
}

.nv-cfg-cell,
.nv-cfg-field,
.nv-cfg-row {
  display: inline-flex;
  align-items: center;
}

.nv-cfg-field {
  gap: 4px;
}

/* One button shape: hairline, the theme's radius, as high as a field. */
.nv-cfg-button,
.nv-cfg-toggle,
.nv-cfg-remove {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  height: var(--nv-cfg-h);
  padding: 0 6px;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  background: var(--bs-body-bg);
  color: var(--bs-secondary-color);
  font: inherit;
  cursor: pointer;
}

.nv-cfg-button:hover,
.nv-cfg-toggle:hover {
  border-color: var(--bs-body-color);
  color: var(--bs-body-color);
}

.nv-cfg-button i {
  margin-right: 4px;
  font-size: 11px;
}

.nv-cfg-button--icon,
.nv-cfg-toggle {
  width: 24px;
  padding: 0;
}

.nv-cfg-button--icon i {
  margin: 0;
  font-size: 12px;
}

/* Removing belongs to what it removes: joined to its field. */
.nv-cfg-remove {
  width: 18px;
  padding: 0;
  border-color: var(--nv-cfg-line);
  border-left: 0;
  border-radius: 0 var(--bs-border-radius) var(--bs-border-radius) 0;
  font-size: 9px;
}

.nv-cfg-remove:hover {
  color: var(--bs-danger);
}

.nv-cfg-cell:has(.nv-cfg-remove) > :first-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

/* Source and widget switch places through two pictogram buttons, each
   outside the box. */
.nv-cfg-toggle {
  font-size: 13px;
}

/* Level with the first row of the box: in a line, beside a block. */
.nv-cfg--inline + .nv-cfg-toggle {
  margin-top: 5px;
}

.nv-cfg--block + .nv-cfg-toggle {
  margin-top: 10px;
}

/* The way back from the plain source to the control. */
.nv-cfg-toggle--back {
  margin-left: 10px;
  vertical-align: middle;
}

/* An asset in three columns that line up from box to box (and with the
   libs box above them): what it is, its picture with the name it goes by
   and the button that chooses the file, the settings of the next import. */
.nv-cfg--asset {
  align-items: flex-start;
  gap: 8px 12px;
  padding: 10px 8px;
}

.nv-cfg-kind {
  min-width: 7ch;
  color: var(--bs-body-color);
  font-family: var(--bs-font-monospace);
  font-weight: 500;
  line-height: var(--nv-cfg-h);
}

.nv-cfg-picture {
  display: inline-flex;
  gap: 12px;
}

/* Name over button, as high as the picture beside them. */
.nv-cfg-main {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  width: 11em;
}

.nv-cfg-main .nv-cfg-text {
  width: 100%;
}

.nv-cfg-main .nv-cfg-label {
  line-height: var(--nv-cfg-h);
}

.nv-cfg--asset + .nv-cfg-toggle {
  margin-top: 13px;
}

/* The parts of a program. A function: the fold with its name, then what it
   does; the function itself is code under the header, closed by a hair
   line. */
.nv-cfg--function {
  flex-wrap: nowrap;
  gap: 8px;
  min-height: 28px;
  padding: 3px 8px 3px 3px;
}

.nv-cfg-fold {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 5px;
  height: var(--nv-cfg-h);
  padding: 0 5px 0 3px;
  border: 0;
  border-radius: var(--bs-border-radius);
  background: none;
  color: var(--bs-body-color);
  font: inherit;
  font-family: var(--bs-font-monospace);
  font-weight: 500;
  cursor: pointer;
}

.nv-cfg-fold:hover {
  background: var(--bs-secondary-bg);
}

.nv-cfg-fold i {
  font-size: 10px;
  transition: transform 0.12s;
}

.nv-cfg-fold[aria-expanded="true"] i {
  transform: rotate(90deg);
}

@media (prefers-reduced-motion: reduce) {
  .nv-cfg-fold i {
    transition: none;
  }
}

.nv-cfg-descr {
  overflow: hidden;
  font-family: var(--bs-body-font-family);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nv-cfg-tail {
  display: inline-block;
  width: 180px;
  border-top: 1px solid var(--bs-border-color);
  vertical-align: middle;
}

.cm-s-nanovm .CodeMirror-line:has(.nv-cfg-tail) {
  line-height: 9px;
}

/* Hidden lines: a hair of a line in their place. How many they are, and the
   button to the source, show while the marker is marked or pointed at. */
.nv-cfg--hide {
  gap: 8px;
  height: 14px;
  padding: 0 4px;
  background: none;
}

.nv-cfg-hair {
  width: 172px;
  border-top: 1px dashed var(--bs-border-color);
}

.nv-cfg-count {
  font-family: var(--bs-body-font-family);
  font-size: 10px;
  letter-spacing: 0.08em;
  line-height: 12px;
  text-transform: uppercase;
  visibility: hidden;
}

.nv-cfg-frame:has(> .nv-cfg--hide) {
  align-items: center;
}

.nv-cfg-frame:has(> .nv-cfg--hide) > .nv-cfg-toggle {
  height: 14px;
}

.nv-cfg-frame:has(> .nv-cfg--hide):hover > .nv-cfg-toggle,
.nv-cfg-frame:hover .nv-cfg-count,
.nv-cfg-frame:focus-within .nv-cfg-count,
.CodeMirror-activeline .nv-cfg-count {
  visibility: visible;
}

.cm-s-nanovm .CodeMirror-line:has(.nv-cfg--hide) {
  line-height: 16px;
}

.nv-cfg-preview,
.nv-cfg-empty {
  width: 48px;
  height: 48px;
  border: 1px solid var(--nv-cfg-line);
  border-radius: var(--bs-border-radius);
}

/* A shape is drawn in black on white: turned over in the dark theme, it is
   light on dark there. */
.nv-cfg-preview {
  object-fit: contain;
  background: #fff;
}

[data-bs-theme="dark"] .nv-cfg-preview:not(.nv-cfg-preview--pixels) {
  filter: invert(0.92);
}

.nv-cfg-preview--pixels {
  background: var(--bs-body-bg);
  image-rendering: pixelated;
}

.nv-cfg-empty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-style: dashed;
  font-size: 18px;
}

/* What an upload or a rename has to say; a mistake carries the rule. */
.nv-cfg-status:not(:empty) {
  flex-basis: 100%;
}

.nv-cfg-status[data-error]:not(:empty),
.nv-cfg-diagnostic {
  padding-left: 8px;
  border-left: 2px solid var(--bs-danger);
  color: var(--bs-body-color);
}

/* A mistake in a signature, said under its line. */
.nv-cfg-diagnostic {
  width: fit-content;
  max-width: min(calc(100cqw - var(--nv-gutter-w) - 16px), 76ch);
  margin: 1px 0 4px 4px;
  font-family: var(--bs-font-sans-serif);
  font-size: 12px;
  line-height: 1.4;
  white-space: normal;
}

/* The includes of a file, in two columns: left what a row holds (the
   toolchain's libraries, the project's headers), right the headers, three
   to a line. */
.nv-cfg--libs {
  display: inline-grid;
  grid-template-columns: max-content minmax(0, auto);
  align-items: start;
  gap: 8px 12px;
  padding: 8px 8px;
}

.nv-cfg--libs.nv-cfg--below {
  display: grid;
}

.nv-cfg--libs .nv-cfg-row {
  display: contents;
}

.nv-cfg--libs .nv-cfg-label {
  min-width: 7ch;
  line-height: var(--nv-cfg-h);
}

.nv-cfg-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, max-content));
  gap: 4px 6px;
  min-width: 0;
}

.nv-cfg-list .nv-cfg-cell {
  min-width: 0;
}

/* A long name is cut with an ellipsis; its title says it in full. */
.nv-cfg-list .nv-cfg-chip {
  display: block;
  flex: 1;
  min-width: 0;
  line-height: calc(var(--nv-cfg-h) - 2px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nv-cfg-list .nv-cfg-select {
  min-width: 0;
}

.nv-cfg-chip {
  display: inline-flex;
  align-items: center;
  height: var(--nv-cfg-h);
  padding: 0 6px;
  border: 1px solid var(--nv-cfg-line);
  border-radius: var(--bs-border-radius);
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  font-family: var(--bs-font-monospace);
  font-size: 11.5px;
}

/* Debug line highlighting */
.debug-current-line {
  background-color: rgba(var(--bs-warning-rgb), 0.3) !important;
}
.debug-current-gutter {
  color: var(--nv-gold) !important;
  font-weight: bold;
}
.debug-arrow {
  color: var(--nv-gold);
  font-size: 12px;
}
