/* Code editor around a textarea (public/assets/lib/code-editor.js).
   The textarea and the coloured <pre> behind it must share every metric that affects layout:
   font, size, line height, padding, tab size and white-space. They all come from here. */

.ce {
  --ce-font-size: 14px;
  --ce-line: 22px;
  --ce-pad: 10px;
  --ce-digits: 2;
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--surface);
}

.ce-gutter {
  flex-shrink: 0;
  width: calc(var(--ce-digits) * 0.62em + 22px);
  overflow: hidden;
  font: var(--ce-font-size) / var(--ce-line) var(--font-mono);
  color: var(--line-soft);
  text-align: right;
  background: var(--surface-2);
  border-right: 1.5px solid #D6DEEE;
  user-select: none;
}
.ce-numbers { padding: var(--ce-pad) 8px var(--ce-pad) 0; white-space: pre; will-change: transform; }
.ce.is-wrapped .ce-gutter { display: none; }

.ce-main { position: relative; flex: 1 1 auto; min-width: 0; overflow: hidden; }

.ce-layer { position: absolute; top: 0; left: 0; pointer-events: none; will-change: transform; }

.ce-highlight,
.ce-input {
  margin: 0;
  padding: var(--ce-pad) 14px;
  font: var(--ce-font-size) / var(--ce-line) var(--font-mono);
  letter-spacing: 0;
  white-space: pre;
  tab-size: 2;
  border: 0;
}

.ce-highlight { position: relative; color: var(--ink); background: transparent; }
.ce.is-wrapped .ce-highlight,
.ce.is-wrapped .ce-input { white-space: pre-wrap; overflow-wrap: anywhere; }

.ce-input {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  overflow: auto;
  color: transparent;
  caret-color: var(--ink);
  background: transparent;
  outline: none;
  resize: none;
}
.ce-input::selection { color: transparent; background: rgba(29, 78, 216, 0.22); }
.ce-input::placeholder { color: var(--line-soft); }
/* Very large documents are shown without colours: the textarea draws its own text. */
.ce.is-plain .ce-input { color: var(--ink); }
.ce.is-plain .ce-input::selection { color: var(--ink); }

.ce-key { color: #7A1F5C; }
.ce-str { color: #0F6B37; }
.ce-num { color: #1D4ED8; }
.ce-bool { color: #9D174D; font-weight: 700; }
.ce-null { color: #5B6475; font-style: italic; }
.ce-punct { color: #5B6B86; }

.ce-marks { position: absolute; inset: 0; }
.ce-mark { position: absolute; left: 0; right: 0; }
.ce-mark-error { background: #FFE3E3; box-shadow: inset 3px 0 0 #E03131; }
.ce-mark-added { background: #D3F9D8; box-shadow: inset 3px 0 0 #2F9E44; }
.ce-mark-removed { background: #FFE3E3; box-shadow: inset 3px 0 0 #E03131; }
.ce-mark-changed { background: #FFF3BF; box-shadow: inset 3px 0 0 #F08C00; }
.ce-mark-found { background: rgba(255, 107, 44, 0.25); }

/* Phones: 16px stops iOS from zooming in when the editor gets focus. */
@media (max-width: 640px) {
  .ce { --ce-font-size: 16px; --ce-line: 24px; }
}
