.running-code-editor {
  --rce-surface: var(--input-surface, var(--settings-card-surface));
  --rce-raised-surface: var(--control-surface, var(--settings-card-surface));
  --rce-raised-hover: var(--control-surface-hover, var(--settings-row-muted-surface));
  --rce-muted-surface: var(--settings-row-muted-surface, var(--settings-card-surface));
  --rce-border: var(--control-border, var(--border));
  --rce-ink: var(--ink);
  --rce-muted: var(--muted);
  --rce-accent: var(--green);
  --rce-focus: color-mix(in srgb, var(--rce-accent) 22%, transparent);
  --rce-selection: color-mix(in srgb, var(--blue, var(--rce-accent)) 24%, transparent);
  --rce-search: color-mix(in srgb, var(--warning-ink, #9b6400) 24%, transparent);
  --rce-search-active: color-mix(in srgb, var(--warning-ink, #9b6400) 42%, transparent);
  --rce-error: var(--danger-ink, var(--ink));
  --rce-error-border: var(--settings-invalid-border, var(--border));
  --rce-error-surface: var(--settings-invalid-surface, var(--settings-row-muted-surface));
  --rce-warning: var(--warning-ink, var(--muted));
  --rce-warning-border: var(--warning-border, var(--border));
  --rce-warning-surface: var(--warning-surface, var(--settings-row-muted-surface));
  --rce-valid: var(--green);
  --rce-line-height: 1.55;
  --rce-editor-padding-block: 12px;
  --rce-editor-padding-inline: 14px;
  display: grid;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  gap: 8px;
  color: var(--rce-ink);
}

.rce-toolbar,
.rce-status-line {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.rce-heading {
  overflow: hidden;
  color: var(--rce-ink);
  font-size: 0.9rem;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rce-toolbar-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.rce-toolbar-hint {
  color: var(--rce-muted);
  font-size: 0.72rem;
  font-weight: 750;
  white-space: nowrap;
}

.rce-find-button,
.rce-format-button {
  min-height: 36px;
  border: 1px solid var(--rce-border);
  border-radius: 8px;
  background: var(--rce-raised-surface);
  color: var(--rce-ink);
  padding: 0 12px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 850;
  cursor: pointer;
  box-shadow: var(--control-shadow, none);
}

.rce-find-button:hover,
.rce-format-button:hover {
  background: var(--rce-raised-hover);
}

.rce-find-button:disabled,
.rce-format-button:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.rce-format-button:focus-visible,
.rce-find-button:focus-visible,
.rce-search-input:focus-visible,
.rce-search-action:focus-visible,
.rce-problem-marker:focus-visible,
.rce-problem:focus-visible,
.rce-completion-option:focus-visible {
  outline: 3px solid var(--rce-focus);
  outline-offset: 2px;
}

.rce-search {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto 36px 36px 36px;
  min-width: 0;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--rce-border);
  border-radius: 8px;
  background: var(--rce-muted-surface);
  padding: 6px;
}

.rce-search[hidden] {
  display: none;
}

.rce-search-input {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--rce-border);
  border-radius: 6px;
  background: var(--rce-surface);
  color: var(--rce-ink);
  padding: 6px 9px;
  font: inherit;
  font-size: 0.82rem;
}

.rce-search-count {
  min-width: 62px;
  color: var(--rce-muted);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  text-align: right;
  white-space: nowrap;
}

.rce-search-action {
  display: grid;
  width: 36px;
  min-width: 36px;
  min-height: 36px;
  place-items: center;
  border: 1px solid var(--rce-border);
  border-radius: 6px;
  background: var(--rce-raised-surface);
  color: var(--rce-ink);
  padding: 0;
  font: inherit;
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
}

.rce-search-action:hover {
  background: var(--rce-raised-hover);
}

.rce-search-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.rce-editor-frame {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  width: 100%;
  min-width: 0;
  height: clamp(340px, 54vh, 620px);
  overflow: hidden;
  border: 1px solid var(--rce-border);
  border-radius: 8px;
  background: var(--rce-surface);
  box-shadow: inset 0 1px 2px color-mix(in srgb, var(--rce-ink) 5%, transparent);
}

.running-code-editor:focus-within .rce-editor-frame {
  border-color: color-mix(in srgb, var(--rce-accent) 48%, var(--rce-border));
  box-shadow: 0 0 0 3px var(--rce-focus);
}

.running-code-editor.has-errors .rce-editor-frame {
  border-color: var(--rce-error-border);
}

.rce-gutter {
  position: relative;
  z-index: 4;
  min-width: calc(35px + var(--rce-line-number-digits, 2) * 0.62em);
  overflow: hidden;
  border-right: 1px solid var(--rce-border);
  background: var(--rce-muted-surface);
  color: var(--rce-muted);
  padding-block: var(--rce-editor-padding-block);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
  line-height: var(--rce-line-height);
  user-select: none;
}

.rce-gutter-lines {
  will-change: transform;
}

.rce-gutter-line {
  display: grid;
  grid-template-columns: 22px minmax(calc(var(--rce-line-number-digits, 2) * 0.62em), auto);
  min-height: calc(1em * var(--rce-line-height));
  align-items: center;
}

.rce-marker-cell {
  display: grid;
  place-items: center;
  width: 22px;
  height: calc(1em * var(--rce-line-height));
}

.rce-line-number {
  display: block;
  padding-right: 8px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rce-problem-marker {
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-radius: 999px;
  background: var(--rce-surface);
  color: var(--rce-error);
  padding: 0;
  cursor: pointer;
}

.rce-problem-marker.is-warning {
  border-radius: 2px;
  color: var(--rce-warning);
  transform: rotate(45deg) scale(0.82);
}

.rce-code-stack {
  position: relative;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  background: var(--rce-surface);
}

.rce-highlight-mirror,
.rce-textarea {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: var(--rce-editor-padding-block) var(--rce-editor-padding-inline);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
  font-variant-ligatures: none;
  line-height: var(--rce-line-height);
  tab-size: 2;
  white-space: pre;
  word-wrap: normal;
}

.rce-highlight-mirror {
  z-index: 1;
  overflow: hidden;
  background: var(--rce-surface);
  color: var(--rce-ink);
  pointer-events: none;
}

.rce-highlight-mirror code {
  display: block;
  min-width: max-content;
  color: inherit;
  font: inherit;
}

.rce-textarea {
  z-index: 2;
  resize: none;
  overflow: auto;
  background: transparent;
  color: transparent;
  caret-color: var(--rce-ink);
  -webkit-text-fill-color: transparent;
  outline: 0;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.rce-textarea::placeholder {
  color: var(--rce-muted);
  -webkit-text-fill-color: var(--rce-muted);
}

.rce-textarea::selection {
  background: var(--rce-selection);
}

.rce-token-keyword {
  color: var(--blue, var(--rce-accent));
  font-weight: 820;
}

.rce-token-definition {
  color: var(--green-dark, var(--rce-accent));
  font-weight: 850;
}

.rce-token-property {
  color: var(--purple, var(--blue, var(--rce-accent)));
}

.rce-token-function {
  color: var(--green-dark, var(--rce-accent));
}

.rce-token-string {
  color: var(--clay, var(--danger-ink, var(--rce-ink)));
}

.rce-token-number {
  color: var(--blue, var(--rce-accent));
}

.rce-token-comment {
  color: var(--rce-muted);
  font-style: italic;
}

.rce-token-operator,
.rce-token-punctuation {
  color: var(--rce-muted);
}

.rce-token-identifier {
  color: var(--rce-ink);
}

.rce-token-unit {
  color: var(--purple, var(--blue, var(--rce-accent)));
  font-weight: 760;
}

.rce-search-match,
.rce-search-match-active {
  border-radius: 2px;
  background: var(--rce-search);
  box-shadow: inset 0 -1px color-mix(in srgb, var(--warning-ink, var(--rce-ink)) 58%, transparent);
}

.rce-search-match-active {
  background: var(--rce-search-active);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--warning-ink, var(--rce-ink)) 72%, transparent);
}

.rce-bracket-match {
  border-radius: 2px;
  background: color-mix(in srgb, var(--rce-accent) 24%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--rce-accent) 72%, transparent);
  color: var(--rce-ink);
  font-weight: 900;
}

.rce-bracket-unmatched {
  border-radius: 2px;
  background: var(--rce-error-surface);
  box-shadow: inset 0 -2px var(--rce-error-border);
  color: var(--rce-error);
  font-weight: 900;
}

.rce-completion-list {
  position: absolute;
  z-index: 10;
  display: grid;
  width: min(360px, calc(100% - 16px));
  max-height: 190px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--rce-border);
  border-radius: 8px;
  background: var(--rce-raised-surface);
  padding: 4px;
  box-shadow: var(--shadow, var(--control-shadow, none));
}

.rce-completion-list[hidden] {
  display: none;
}

.rce-completion-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 36px;
  align-items: center;
  gap: 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--rce-ink);
  padding: 7px 9px;
  text-align: left;
  cursor: pointer;
}

.rce-completion-option:hover,
.rce-completion-option.is-active {
  background: var(--rce-raised-hover);
}

.rce-completion-label {
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.8rem;
  font-weight: 820;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rce-completion-meta {
  color: var(--rce-muted);
  font-size: 0.68rem;
  font-weight: 760;
}

.rce-status-line {
  color: var(--rce-muted);
  font-size: 0.72rem;
  font-weight: 780;
}

.rce-parse-status,
.rce-cursor-status {
  min-width: 0;
}

.rce-reference-help {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  min-width: 0;
  align-items: baseline;
  gap: 8px;
  border: 1px solid var(--rce-border);
  border-radius: 8px;
  background: var(--rce-muted-surface);
  color: var(--rce-muted);
  padding: 7px 9px;
  font-size: 0.72rem;
  line-height: 1.4;
}

.rce-reference-help[hidden] {
  display: none;
}

.rce-reference-label {
  color: var(--rce-ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-weight: 850;
}

.rce-reference-detail {
  min-width: 0;
}

.rce-parse-status.is-valid {
  color: var(--rce-valid);
}

.rce-parse-status.is-error {
  color: var(--rce-error);
}

.rce-parse-status.is-warning {
  color: var(--rce-warning);
}

.rce-cursor-status {
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rce-problems {
  display: grid;
  gap: 6px;
  min-width: 0;
  border: 1px solid var(--rce-border);
  border-radius: 8px;
  background: var(--rce-muted-surface);
  padding: 8px;
}

.rce-problems[hidden] {
  display: none;
}

.rce-problems-heading {
  margin: 0;
  color: var(--rce-ink);
  font-size: 0.78rem;
  font-weight: 900;
}

.rce-problem-list {
  display: grid;
  max-height: 180px;
  gap: 4px;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  overscroll-behavior: contain;
}

.rce-problem {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  width: 100%;
  min-height: 38px;
  align-items: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--rce-ink);
  padding: 7px 9px;
  text-align: left;
  cursor: pointer;
}

.rce-problem:hover {
  background: var(--rce-raised-hover);
}

.rce-problem.is-error {
  border-color: var(--rce-error-border);
  background: color-mix(in srgb, var(--rce-error-surface) 72%, transparent);
}

.rce-problem.is-warning {
  border-color: var(--rce-warning-border);
  background: color-mix(in srgb, var(--rce-warning-surface) 72%, transparent);
}

.rce-problem-location,
.rce-problem-code {
  color: var(--rce-muted);
  font-size: 0.68rem;
  font-weight: 820;
  white-space: nowrap;
}

.rce-problem-message {
  min-width: 0;
  font-size: 0.76rem;
  font-weight: 760;
  line-height: 1.35;
}

@media (max-width: 560px) {
  .running-code-editor {
    gap: 10px;
  }

  .rce-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .rce-toolbar-actions {
    justify-content: space-between;
  }

  .rce-toolbar-hint {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .rce-find-button,
  .rce-format-button,
  .rce-search-input,
  .rce-search-action,
  .rce-completion-option,
  .rce-problem {
    min-height: 44px;
  }

  .rce-search {
    grid-template-columns: minmax(0, 1fr) 44px 44px 44px;
  }

  .rce-search-count {
    grid-column: 1 / -1;
    grid-row: 2;
    min-width: 0;
    text-align: left;
  }

  .rce-search-action {
    width: 44px;
    min-width: 44px;
  }

  .rce-editor-frame {
    height: clamp(300px, 52dvh, 520px);
  }

  .rce-highlight-mirror,
  .rce-textarea,
  .rce-gutter {
    font-size: 16px;
  }

  .rce-gutter {
    min-width: calc(31px + var(--rce-line-number-digits, 2) * 0.62em);
  }

  .rce-gutter-line {
    grid-template-columns: 20px minmax(calc(var(--rce-line-number-digits, 2) * 0.62em), auto);
  }

  .rce-marker-cell {
    width: 20px;
  }

  .rce-completion-list {
    width: calc(100% - 16px);
    max-height: min(210px, 32dvh);
  }

  .rce-status-line {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .rce-cursor-status {
    text-align: left;
  }

  .rce-reference-help {
    grid-template-columns: minmax(0, 1fr);
    gap: 3px;
  }

  .rce-problem {
    grid-template-columns: 1fr auto;
  }

  .rce-problem-message {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rce-gutter-lines,
  .rce-problem-marker {
    transition: none;
  }
}

@media (forced-colors: active) {
  .rce-textarea {
    background: Canvas;
    color: CanvasText;
    -webkit-text-fill-color: CanvasText;
  }

  .rce-highlight-mirror {
    display: none;
  }

  .rce-problem-marker {
    forced-color-adjust: auto;
  }

  .rce-search-match,
  .rce-search-match-active,
  .rce-bracket-match,
  .rce-bracket-unmatched {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }
}
