/* Code panel (nc/code). Colours come from the shell tokens (--nc-*); the fallbacks only matter when
   nc_viewer.css is absent. Syntax colours are local (--ncc-*) with a dark set under
   :root[data-theme="dark"]. Motion words (G0/G1/G2/G3) and gutter markers use the 3D motion colours
   (nc/model MOTION_COLORS_BY_THEME), which the module sets on the panel as --ncc-c-rapid/-cut/-arcmove;
   the words mix them a little toward the text colour so they stay >= 4.5:1 on every line band.
   The playback line uses the shared "where the machine is now" colour (nc/model PLAYBACK_COLORS),
   set by the module as --ncc-play-fill/-outline.
   Line bands never stack (readability round RU-05): a line shows at most one fill (selection or the
   op band); the playback line adds only a 3px bar, a filled gutter cell with ▶ and a bold number. */

.nc-code-panel {
  --ncc-bg: var(--nc-panel, #ffffff);
  --ncc-bg-2: var(--nc-panel-2, #f5f7fa);
  --ncc-border: var(--nc-border, #d8e0e9);
  --ncc-border-strong: var(--nc-border-strong, #8a96a8);
  --ncc-text: var(--nc-text, #172033);
  --ncc-dim: var(--nc-text-dim, #566377);
  --ncc-accent: var(--nc-accent, #0d73d9);
  --ncc-warning: var(--nc-warning, #9a5a00);
  --ncc-danger: var(--nc-danger, #d0303c);
  --ncc-info: var(--nc-accent, #0d73d9);
  --ncc-font: var(--nc-mono, ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "D2Coding", monospace);
  --ncc-fs: var(--nc-fs-sm, 12px);
  --ncc-lh: 18px;
  --ncc-gutter-w: 48px;
  --ncc-gdiag-w: 14px;
  --ncc-op: #1f5fd1;

  /* Selected line: accent fill with thin edges. Playback line: a bar in the playback colour. */
  --ncc-sel-bg: color-mix(in srgb, var(--ncc-accent) 14%, transparent);
  --ncc-sel-edge: color-mix(in srgb, var(--ncc-accent) 70%, transparent);
  --ncc-play-fill: #f5b700;
  --ncc-play-outline: #111827;
  --ncc-op-mix: 9%;
  --ncc-motion-mix: 80%;
  --ncc-flash-mix: 55%;
  /* Search hits: a light fill plus an edge, so syntax colours keep >= 4.5:1 on a hit too. */
  --ncc-hit-bg: rgb(250 204 21 / 0.35);
  --ncc-hit-edge: rgb(202 138 4 / 0.65);
  --ncc-hit-cur-bg: #c2410c;
  --ncc-hit-cur-fg: #ffffff;
  /* Changed-line bars (D-05): changed = warning, added = success. */
  --ncc-chg-mod: var(--nc-warning, #8f5400);
  --ncc-chg-add: var(--nc-success, #127556);

  /* Motion colours (overridden from nc/model by the module) */
  --ncc-c-rapid: #6b7280;
  --ncc-c-cut: #1f5fd1;
  --ncc-c-arcmove: #7a3ac9;
  /* G-code */
  --ncc-c-lno: #556276;
  --ncc-c-g: var(--ncc-text);
  --ncc-c-m: #a21caf;
  --ncc-c-axis: #0e6d66;
  --ncc-c-arc: #6d28d9;
  --ncc-c-feed: #9d4808;
  /* Red means danger here (breakouts, errors): tool words are brown, % and MPR sections blue (B-14). */
  --ncc-c-tool: #9a3412;
  --ncc-c-par: #436c0d;
  --ncc-c-prog: #7e22ce;
  --ncc-c-com: #5b616d;
  --ncc-c-pct: #1e40af;
  --ncc-c-num: #03669d;
  --ncc-c-var: #ad3a0b;
  --ncc-c-kw: #6d28d9;
  --ncc-c-op: #5b616d;
  --ncc-c-word: #374151;
  /* MPR */
  --ncc-c-sec: #1e40af;
  --ncc-c-cont: #ad3a0b;
  --ncc-c-mac: #1d4ed8;
  --ncc-c-macn: #6d28d9;
  --ncc-c-el: #0d6a83;
  --ncc-c-kind: #86198f;
  --ncc-c-key: #0e6d66;
  --ncc-c-dkey: #556276;
  --ncc-c-str: #8b5506;
  /* XML */
  --ncc-c-tag: #1d4ed8;
  --ncc-c-tagp: #5b616d;
  --ncc-c-attr: #7e22ce;
  --ncc-c-aval: #046e50;
  --ncc-c-text: var(--ncc-text);
  --ncc-c-ent: #ad3a0b;
  --ncc-c-decl: #5b616d;

  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ncc-bg);
  color: var(--ncc-text);
  color-scheme: light;
}

:root[data-theme="dark"] .nc-code-panel {
  --ncc-bg: var(--nc-panel, #141a22);
  --ncc-bg-2: var(--nc-panel-2, #19202a);
  --ncc-border: var(--nc-border, #29323e);
  --ncc-border-strong: var(--nc-border-strong, #5d6b7e);
  --ncc-text: var(--nc-text, #e1e7ef);
  --ncc-dim: var(--nc-text-dim, #8e9aab);
  --ncc-accent: var(--nc-accent, #3d95f2);
  --ncc-warning: var(--nc-warning, #f0b03c);
  --ncc-danger: var(--nc-danger, #f06a74);
  --ncc-info: var(--nc-accent, #3d95f2);
  --ncc-op: #6ea8ff;

  --ncc-sel-bg: color-mix(in srgb, var(--ncc-accent) 22%, transparent);
  --ncc-sel-edge: color-mix(in srgb, var(--ncc-accent) 80%, transparent);
  --ncc-play-fill: #ffd23f;
  --ncc-play-outline: #111827;
  --ncc-op-mix: 15%;
  --ncc-motion-mix: 72%;
  --ncc-flash-mix: 40%;
  --ncc-hit-bg: rgb(90 68 0 / 0.55);
  --ncc-hit-edge: rgb(250 204 21 / 0.7);
  --ncc-hit-cur-bg: #fb923c;
  --ncc-hit-cur-fg: #111827;
  --ncc-chg-mod: var(--nc-warning, #f0b03c);
  --ncc-chg-add: var(--nc-success, #3ccb92);

  --ncc-c-rapid: #8b95a7;
  --ncc-c-cut: #6ea8ff;
  --ncc-c-arcmove: #b894ff;
  --ncc-c-lno: #a3adbb;
  --ncc-c-m: #f0abfc;
  --ncc-c-axis: #5eead4;
  --ncc-c-arc: #c4b5fd;
  --ncc-c-feed: #fbbf24;
  --ncc-c-tool: #e0a370;
  --ncc-c-par: #bef264;
  --ncc-c-prog: #d8b4fe;
  --ncc-c-com: #a5acba;
  --ncc-c-pct: #a5b4fc;
  --ncc-c-num: #7dd3fc;
  --ncc-c-var: #fdba74;
  --ncc-c-kw: #c4b5fd;
  --ncc-c-op: #a5acba;
  --ncc-c-word: #d1d5db;
  --ncc-c-sec: #a5b4fc;
  --ncc-c-cont: #fdba74;
  --ncc-c-mac: #93c5fd;
  --ncc-c-macn: #c4b5fd;
  --ncc-c-el: #67e8f9;
  --ncc-c-kind: #f0abfc;
  --ncc-c-key: #5eead4;
  --ncc-c-dkey: #9facbf;
  --ncc-c-str: #fcd34d;
  --ncc-c-tag: #93c5fd;
  --ncc-c-tagp: #a5acba;
  --ncc-c-attr: #d8b4fe;
  --ncc-c-aval: #86efac;
  --ncc-c-ent: #fdba74;
  --ncc-c-decl: #a5acba;

  color-scheme: dark;
}

/* ---------------------------------------------------------------- header */

/* One band (B-23·B-26): "6,648줄 · NC" as an area label (12/600 dim, the count in the text colour),
   the 3D 미반영 pill, then 검색 · 편집 · ⋯ in the shell's small ghost buttons (B-27). */
.nc-code-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
  box-sizing: border-box;
  height: var(--nc-band-h, 34px);
  padding: 0 6px 0 10px;
  border-bottom: 1px solid var(--ncc-border);
  background: var(--ncc-bg);
}

.nc-code-meta {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--ncc-dim);
  font-size: var(--nc-fs-sm, 12px);
  font-weight: var(--nc-fw-semibold, 600);
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
}

.nc-code-count {
  color: var(--ncc-text);
}

.nc-code-dirty {
  flex: none;
  padding: 0 6px;
  border: 1px solid color-mix(in srgb, var(--ncc-warning) 55%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--ncc-warning) 12%, var(--ncc-bg));
  color: var(--ncc-warning);
  font-size: var(--nc-fs-sm, 12px);
  font-weight: var(--nc-fw-semibold, 600);
  line-height: 16px;
  white-space: nowrap;
  cursor: help;
}

.nc-code-dirty[hidden] {
  display: none;
}

.nc-code-actions {
  display: flex;
  flex: none;
  gap: 4px;
  margin-left: auto;
}

/* Buttons are the shell's .nc-btn.nc-btn-sm.nc-btn-ghost; the panel adds its pressed state and
   24px squares for icon buttons. */
.nc-code-panel .nc-code-btn[aria-pressed="true"],
.nc-code-panel .nc-code-btn[aria-expanded="true"]:not(.nc-code-rtoggle) {
  border-color: color-mix(in srgb, var(--ncc-accent) 55%, transparent);
  background: var(--nc-accent-soft, color-mix(in srgb, var(--ncc-accent) 12%, transparent));
  color: var(--nc-accent-strong, var(--ncc-accent));
}

.nc-code-panel .nc-code-btn:focus-visible,
.nc-code-opt:focus-visible,
.nc-code-menu-item:focus-visible {
  outline: 2px solid var(--ncc-accent);
  outline-offset: 1px;
}

.nc-code-panel .nc-code-btn.nc-code-icon {
  width: 24px;
  min-width: 24px;
  padding: 0;
  font-size: var(--nc-fs-sm, 12px);
  line-height: 1;
}

/* ---------------------------------------------------------------- search */

/* Find row: [› replace] [field with Aa 단어 .*] [count] [↑] [↓] [✕]; the replace row under it. */
.nc-code-search {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: none;
  padding: 4px 8px 4px 4px;
  border-bottom: 1px solid var(--ncc-border);
  background: var(--ncc-bg-2);
}

.nc-code-search-row,
.nc-code-replace-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

/* The replace input lines up with the find field (after the 24px toggle and the gap). */
.nc-code-replace-row {
  padding-left: 28px;
}

.nc-code-search[hidden],
.nc-code-replace-row[hidden],
.nc-code-notice[hidden],
.nc-code-menu[hidden],
.nc-code-tip[hidden],
.nc-code-hint[hidden] {
  display: none;
}

.nc-code-panel .nc-code-rtoggle {
  border-color: transparent;
  color: var(--ncc-dim);
  font-size: var(--nc-fs-md, 13px);
}

.nc-code-field {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  min-width: 0;
}

.nc-code-search-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 24px;
  box-sizing: border-box;
  padding: 0 7px;
  border: 1px solid var(--ncc-border-strong);
  border-radius: 5px;
  background: var(--ncc-bg);
  color: var(--ncc-text);
  font-family: var(--ncc-font);
  font-size: var(--ncc-fs);
}

/* Room for the three option toggles inside the find field. */
.nc-code-field .nc-code-search-input {
  padding-right: 76px;
}

.nc-code-search-input::placeholder {
  color: var(--ncc-dim);
  opacity: 1;
}

.nc-code-search-input:focus {
  outline: none;
}

.nc-code-search-input:focus-visible {
  border-color: var(--ncc-accent);
  outline: 2px solid var(--ncc-accent);
  outline-offset: 1px;
}

.nc-code-opts {
  position: absolute;
  top: 2px;
  right: 2px;
  bottom: 2px;
  display: flex;
  gap: 1px;
}

.nc-code-opt {
  min-width: 20px;
  height: 20px;
  padding: 0 3px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--ncc-dim);
  font: inherit;
  font-family: var(--ncc-font);
  font-size: var(--nc-fs-micro, 11px);
  font-weight: var(--nc-fw-semibold, 600);
  line-height: 18px;
  white-space: nowrap;
  cursor: pointer;
}

/* 단어 is Korean: the UI face, at least 12px. */
.nc-code-opt:nth-child(2) {
  font-family: inherit;
  font-size: var(--nc-fs-sm, 12px);
}

.nc-code-opt:hover {
  background: var(--nc-hover, color-mix(in srgb, var(--ncc-text) 6%, transparent));
  color: var(--ncc-text);
}

/* On: the header toggles' pressed look (tint + ring, U2-23), so it does not read as a hover. */
.nc-code-opt[aria-pressed="true"],
.nc-code-opt[aria-pressed="true"]:hover {
  border-color: transparent;
  background: var(--nc-accent-soft, color-mix(in srgb, var(--ncc-accent) 12%, transparent));
  color: var(--nc-accent-strong, var(--ncc-accent));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ncc-accent) 80%, transparent);
}

.nc-code-search-count {
  flex: none;
  min-width: 40px;
  color: var(--ncc-dim);
  font-size: var(--nc-fs-sm, 12px);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.nc-code-search-count.is-none {
  color: var(--ncc-danger);
}

.nc-code-search-count.is-goto {
  color: var(--ncc-text);
}

/* Narrow panels (the default 320px, text size 1.25): the field gets the whole first line and the
   options, count and arrows go to the second, so the query is never hidden behind the toggles. */
.nc-code-search {
  container: ncc-search / inline-size;
  font-size: var(--nc-fs-sm, 12px); /* the em of the queries below; every child sets its own size */
}

@container ncc-search (max-width: 380px) {
  .nc-code-search-row {
    flex-wrap: wrap;
    row-gap: 4px;
  }

  .nc-code-field {
    display: contents;
  }

  .nc-code-field .nc-code-search-input {
    flex: 1 1 calc(100% - 28px);
    padding-right: 7px;
  }

  .nc-code-opts {
    position: static;
    margin-left: 28px;
  }

  .nc-code-search-count {
    margin-left: auto;
  }
}

/* U2-23: where the labelled 바꾸기 · 모두 바꾸기 would leave the replace input under ~140px (a 280px
   panel, or 320px at text size 1.25), they become ↵ · ↵↵ (names and titles unchanged). The labels
   grow with the text size: 1em here is the buttons' 12px × the text size setting. */
@container ncc-search (max-width: calc(176px + 9.4em)) {
  .nc-code-panel .nc-code-glyph-btn {
    min-width: 24px;
    padding: 0 5px;
  }

  .nc-code-glyph-btn .nc-btn-label {
    display: none;
  }

  .nc-code-glyph-btn .nc-code-glyph {
    display: inline;
  }
}

.nc-code-glyph {
  display: none;
  font-family: var(--ncc-font);
  font-size: var(--nc-fs-md, 13px);
  letter-spacing: -0.15em;
  line-height: 1;
}

/* ------------------------------------------------------------------ menu */

/* ⋯ menu under the head's right end (줄 이동 · 바꾸기 · 원본으로 되돌리기). */
.nc-code-menu {
  position: absolute;
  top: calc(var(--nc-band-h, 34px) - 2px);
  right: 6px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  min-width: 220px;
  max-width: calc(100% - 12px);
  box-sizing: border-box;
  padding: 4px;
  border: 1px solid var(--ncc-border);
  border-radius: var(--nc-radius, 6px);
  background: var(--ncc-bg);
  box-shadow: var(--nc-shadow, 0 10px 28px rgba(15, 23, 42, 0.14));
  font-size: var(--nc-fs-md, 13px);
}

.nc-code-menu-item {
  display: flex;
  align-items: baseline;
  gap: 12px;
  width: 100%;
  min-height: 28px;
  padding: 4px 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ncc-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.nc-code-menu-item:hover:not(:disabled),
.nc-code-menu-item:focus-visible {
  background: var(--nc-hover, color-mix(in srgb, var(--ncc-text) 6%, transparent));
}

.nc-code-menu-item:disabled {
  color: var(--ncc-dim);
  cursor: default;
}

.nc-code-menu-label {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
}

.nc-code-menu-why {
  color: var(--ncc-dim);
  font-size: var(--nc-fs-sm, 12px);
}

.nc-code-menu-keys {
  flex: none;
  color: var(--ncc-dim);
  font-size: var(--nc-fs-sm, 12px);
}

.nc-code-menu-sep {
  height: 1px;
  margin: 4px 2px;
  background: var(--ncc-border);
}

.nc-code-menu-note,
.nc-code-menu-text {
  margin: 2px 8px 4px;
  color: var(--ncc-dim);
  font-size: var(--nc-fs-sm, 12px);
  line-height: 1.45;
}

.nc-code-menu-text {
  max-width: 260px;
  color: var(--ncc-text);
}

.nc-code-menu-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding: 2px 4px 2px;
}

.nc-code-panel .nc-code-menu-ok {
  border-color: var(--ncc-accent);
  background: var(--ncc-accent);
  color: var(--nc-accent-contrast, #ffffff);
}

.nc-code-panel .nc-code-menu-ok:hover:not(:disabled) {
  background: var(--nc-accent-strong, var(--ncc-accent));
}

.nc-code-notice {
  flex: none;
  padding: 4px 10px;
  border-bottom: 1px solid var(--ncc-border);
  background: color-mix(in srgb, var(--ncc-warning) 12%, var(--ncc-bg));
  color: var(--ncc-text);
  font-size: var(--nc-fs-sm, 12px);
}

/* ------------------------------------------------------------------ body */

.nc-code-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--ncc-bg);
}

.nc-code-view {
  position: absolute;
  inset: 0;
}

.nc-code-view[hidden],
.nc-code-editor[hidden],
.nc-code-empty[hidden] {
  display: none;
}

.nc-code-view:focus {
  outline: none;
}

.nc-code-view:focus-visible {
  outline: 2px solid var(--ncc-accent);
  outline-offset: -2px;
}

.nc-code-scroller {
  position: absolute;
  inset: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.nc-code-scroller::-webkit-scrollbar-corner,
.nc-code-textarea::-webkit-scrollbar-corner {
  background: var(--ncc-bg);
}

.nc-code-canvas {
  position: relative;
}

/* The listing and the editor share font metrics exactly, so the editor's text lands on the
   listing's glyphs: no ligatures, no kerning, no letter spacing. */
.nc-code-layer,
.nc-code-textarea {
  font-family: var(--ncc-font);
  font-size: var(--ncc-fs);
  font-kerning: none;
  font-variant-ligatures: none;
  letter-spacing: 0;
  line-height: var(--ncc-lh);
  tab-size: 4;
}

.nc-code-layer {
  position: sticky;
  top: 0;
  left: 0;
  overflow: hidden;
}

.nc-code-gutter {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  width: var(--ncc-gutter-w);
  border-right: 1px solid var(--ncc-border);
  background: var(--ncc-bg-2);
  cursor: pointer;
  user-select: none;
}

.nc-code-text {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: var(--ncc-gutter-w);
  overflow: hidden;
}

.nc-code-textin {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  will-change: transform;
}

.nc-code-probe {
  position: absolute;
  top: -100px;
  left: 0;
  visibility: hidden;
  white-space: pre;
  pointer-events: none;
}

.nc-code-line {
  position: absolute;
  right: 0;
  left: 0;
  height: var(--ncc-lh);
  padding-left: 8px;
  box-sizing: border-box;
  color: var(--ncc-text);
  white-space: pre;
  cursor: default;
}

.nc-code-src {
  white-space: pre;
}

/* Korean text: no synthetic italic (Menlo has no Hangul, so a slant would be faked). */
.nc-code-trunc {
  color: var(--ncc-dim);
  font-style: normal;
}

/* More text to the right: a 12px fade at the right edge of the text column (RU-18). */
.nc-code-fade {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  width: 12px;
  background: linear-gradient(to right, color-mix(in srgb, var(--ncc-bg) 0%, transparent), var(--ncc-bg));
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms linear;
}

.nc-code-panel.has-more-right .nc-code-fade {
  opacity: 1;
}

.nc-code-gline {
  position: absolute;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  height: var(--ncc-lh);
  color: var(--ncc-c-lno);
  font-size: var(--ncc-fs);
  font-variant-numeric: tabular-nums;
}

/* The diagnostic column is 14px only in files with line diagnostics; otherwise 4px (RU-18). */
.nc-code-gdiag {
  flex: none;
  width: var(--ncc-gdiag-w);
  height: 100%;
  position: relative;
}

.nc-code-gdiag.is-info::after,
.nc-code-gdiag.is-warning::after,
.nc-code-gdiag.is-error::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 3px;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--ncc-info);
}

.nc-code-gdiag.is-warning::after {
  left: 2px;
  width: 0;
  height: 0;
  margin-top: -4.5px;
  border-right: 5px solid transparent;
  border-bottom: 9px solid var(--ncc-warning);
  border-left: 5px solid transparent;
  border-radius: 0;
  background: none;
}

.nc-code-gdiag.is-error::after {
  width: 7px;
  height: 7px;
  margin-top: -3.5px;
  border-radius: 1px;
  background: var(--ncc-danger);
  transform: rotate(45deg);
}

.nc-code-gnum {
  flex: 1 1 auto;
  padding-right: 4px;
  text-align: right;
}

.nc-code-gmark {
  flex: none;
  width: 10px;
  height: 100%;
  position: relative;
}

.nc-code-gmark.is-on::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 1px;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background: var(--ncc-mark, currentColor);
}

/* Lines changed from the text first opened (D-05): a 3px bar on the gutter's right edge — changed
   in the warning colour, added in green — and a notch where lines were removed. */
.nc-code-gline.chg-mod::after,
.nc-code-gline.chg-add::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 3px;
  background: var(--ncc-chg-mod);
  pointer-events: none;
}

.nc-code-gline.chg-add::after {
  background: var(--ncc-chg-add);
}

.nc-code-gline.chg-del::before,
.nc-code-gline.chg-del-end::before {
  content: "";
  position: absolute;
  top: -4px;
  right: 0;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-right: 6px solid var(--ncc-chg-mod);
  border-bottom: 4px solid transparent;
  pointer-events: none;
}

.nc-code-gline.chg-del-end::before {
  top: auto;
  bottom: -4px;
}

/* Ops the program turns off (D-18: MPR ?? false, PGI enable="0") and G-code "/" blocks: dimmed
   text and a struck-through line number (the gutter title says why). */
.nc-code-line.is-off .nc-code-src {
  opacity: 0.55;
}

.nc-code-gline.is-off .nc-code-gnum {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

/* PGI / XML op summary and MPR computed values at the right edge of a line (D-15/D-16), view mode
   only. A chip the line's text would reach is hidden (U3-20), so it never covers code — except on the
   selected and the playback line, where it shows over the code with a fade (`is-over`, below).
   `right` and `max-width` are nc/code HINT_RIGHT / HINT_INSET (hintFits). */
.nc-code-hints {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.nc-code-hint {
  position: absolute;
  right: 14px;
  max-width: calc(100% - 40px);
  height: var(--ncc-lh);
  box-sizing: border-box;
  overflow: hidden;
  padding: 0 6px;
  border-radius: 3px;
  background: var(--ncc-bg-2);
  color: var(--ncc-dim);
  font-family: var(--nc-font, inherit);
  font-size: var(--nc-fs-sm, 12px);
  line-height: var(--ncc-lh);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Over the code (selected / playback line, U3-20): a 14px fade from the line into the chip on its
   left, inside the chip (its own overflow clips anything outside), so the text visibly runs under it
   whatever band the line has. Measured widths are the plain chip's (nc/code drops the class first). */
.nc-code-hint.is-over {
  padding-left: 18px;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(to right, color-mix(in srgb, var(--ncc-bg-2) 0%, transparent), var(--ncc-bg-2) 14px);
}

/* Parameter tooltip (D-15/D-17): one at a time, under (or over) the hovered line. */
.nc-code-tip {
  position: absolute;
  z-index: 7;
  max-width: min(440px, calc(100% - 8px));
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid var(--ncc-border);
  border-radius: var(--nc-radius, 6px);
  background: var(--ncc-bg);
  box-shadow: var(--nc-shadow, 0 10px 28px rgba(15, 23, 42, 0.14));
  color: var(--ncc-text);
  font-size: var(--nc-fs-sm, 12px);
  line-height: 1.45;
  pointer-events: none;
}

.nc-code-tip-line b,
.nc-code-tip-table th {
  font-family: var(--ncc-font);
  font-weight: var(--nc-fw-semibold, 600);
}

.nc-code-tip-value {
  font-family: var(--ncc-font);
}

.nc-code-tip-line .nc-code-tip-value {
  color: var(--ncc-dim);
}

.nc-code-tip-table {
  border-collapse: collapse;
}

.nc-code-tip-table th,
.nc-code-tip-table td {
  padding: 1px 8px 1px 0;
  text-align: left;
  vertical-align: baseline;
  white-space: nowrap;
}

.nc-code-tip-table .nc-code-tip-note {
  color: var(--ncc-dim);
  white-space: normal;
}

.nc-code-tip-table tr.is-active > * {
  background: var(--nc-accent-soft, color-mix(in srgb, var(--ncc-accent) 12%, transparent));
}

.nc-code-tip-more {
  margin-top: 2px;
  color: var(--ncc-dim);
}

/* --------------------------------------------------------------- highlights */

/* One fill per line at most: the selection fill replaces the op band, and the playback line adds
   no fill of its own (RU-05). Syntax colours are tuned for >= 4.5:1 on each single fill. */
.nc-code-line.in-op {
  background: color-mix(in srgb, var(--ncc-op) var(--ncc-op-mix), transparent);
}

.nc-code-gline.in-op {
  box-shadow: inset 3px 0 0 var(--ncc-op);
}

.nc-code-line.is-sel {
  background: var(--ncc-sel-bg);
  box-shadow: inset 0 1px 0 var(--ncc-sel-edge), inset 0 -1px 0 var(--ncc-sel-edge);
}

.nc-code-gline.is-sel {
  background: var(--ncc-sel-bg);
  color: var(--ncc-text);
  font-weight: var(--nc-fw-bold, 700);
}

.nc-code-gline.in-op.is-sel {
  box-shadow: inset 3px 0 0 var(--ncc-op);
}

/* Playback line: a 3px bar in the playback colour (with its outline, which carries the contrast
   on a light panel), the gutter number and marker cells filled in the same colour with ▶ and a
   bold number. The bar joins the gutter cell across the gutter border into one marker. */
.nc-code-line.is-cur {
  box-shadow: inset 3px 0 0 var(--ncc-play-fill), inset 4px 0 0 var(--ncc-play-outline);
}

.nc-code-line.is-cur.is-sel {
  box-shadow:
    inset 3px 0 0 var(--ncc-play-fill),
    inset 4px 0 0 var(--ncc-play-outline),
    inset 0 1px 0 var(--ncc-sel-edge),
    inset 0 -1px 0 var(--ncc-sel-edge);
}

.nc-code-gline.is-cur {
  color: var(--ncc-play-outline);
  font-weight: var(--nc-fw-bold, 700);
}

.nc-code-gline.is-cur .nc-code-gnum,
.nc-code-gline.is-cur .nc-code-gmark {
  background: var(--ncc-play-fill);
}

.nc-code-gline.is-cur .nc-code-gmark::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  width: 0;
  height: 0;
  margin-top: -4px;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 6px solid var(--ncc-play-outline);
  border-radius: 0;
  background: none;
}

/* Far follow jump: the playback line blinks once (300 ms) so the eye finds it after the jump. */
.nc-code-line.is-flash {
  animation: ncc-flash 300ms ease-out;
}

@keyframes ncc-flash {
  from {
    background-color: color-mix(in srgb, var(--ncc-play-fill) var(--ncc-flash-mix), transparent);
  }
}

/* Reduced motion: no fade, a static highlight for the same short moment instead. */
@media (prefers-reduced-motion: reduce) {
  .nc-code-panel .nc-code-line.is-flash {
    animation: none;
    background-color: color-mix(in srgb, var(--ncc-play-fill) var(--ncc-flash-mix), transparent);
  }

  .nc-code-fade {
    transition: none;
  }
}

/* While playing, the playback line wins: the selected line keeps only a thin dashed outline. */
.nc-code-panel.is-playing .nc-code-line.is-sel:not(.is-cur) {
  background: none;
  box-shadow: none;
  outline: 1px dashed color-mix(in srgb, var(--ncc-accent) 65%, transparent);
  outline-offset: -1px;
}

.nc-code-panel.is-playing .nc-code-line.in-op.is-sel:not(.is-cur) {
  background: color-mix(in srgb, var(--ncc-op) var(--ncc-op-mix), transparent);
}

.nc-code-panel.is-playing .nc-code-line.is-sel.is-cur {
  background: none;
  box-shadow: inset 3px 0 0 var(--ncc-play-fill), inset 4px 0 0 var(--ncc-play-outline);
}

.nc-code-panel.is-playing .nc-code-line.in-op.is-sel.is-cur {
  background: color-mix(in srgb, var(--ncc-op) var(--ncc-op-mix), transparent);
}

.nc-code-panel.is-playing .nc-code-gline.is-sel:not(.is-cur) {
  background: none;
  font-weight: var(--nc-fw-regular, 400);
}

/* Current search hit line in the editor (the textarea selection marks the hit itself). */
.nc-code-line.is-hit {
  outline: 1px solid var(--ncc-hit-cur-bg);
  outline-offset: -1px;
}

.nc-code-hit {
  border-radius: 2px;
  background: var(--ncc-hit-bg);
  box-shadow: inset 0 0 0 1px var(--ncc-hit-edge);
  color: inherit;
}

.nc-code-hit.is-current {
  background: var(--ncc-hit-cur-bg);
  box-shadow: 0 0 0 1px var(--ncc-hit-cur-bg);
}

.nc-code-hit.is-current,
.nc-code-hit.is-current > * {
  color: var(--ncc-hit-cur-fg);
}

/* ---------------------------------------------------------------- syntax */

.ncc-lno { color: var(--ncc-c-lno); }
.ncc-g { color: var(--ncc-c-g); font-weight: 600; }
.ncc-g0 { color: color-mix(in srgb, var(--ncc-c-rapid) var(--ncc-motion-mix), var(--ncc-text)); font-weight: 700; }
.ncc-g1 { color: color-mix(in srgb, var(--ncc-c-cut) var(--ncc-motion-mix), var(--ncc-text)); font-weight: 700; }
.ncc-g23 { color: color-mix(in srgb, var(--ncc-c-arcmove) var(--ncc-motion-mix), var(--ncc-text)); font-weight: 700; }
.ncc-m { color: var(--ncc-c-m); font-weight: 600; }
.ncc-axis { color: var(--ncc-c-axis); }
.ncc-arc { color: var(--ncc-c-arc); }
.ncc-feed { color: var(--ncc-c-feed); }
.ncc-tool { color: var(--ncc-c-tool); font-weight: 600; }
.ncc-par { color: var(--ncc-c-par); }
.ncc-prog { color: var(--ncc-c-prog); font-weight: 700; }
.ncc-com { color: var(--ncc-c-com); }
.ncc-pct { color: var(--ncc-c-pct); font-weight: 700; }
.ncc-bd { color: var(--ncc-c-pct); font-weight: 700; }
.ncc-num { color: var(--ncc-c-num); }
.ncc-var { color: var(--ncc-c-var); }
.ncc-kw { color: var(--ncc-c-kw); font-weight: 600; }
.ncc-op { color: var(--ncc-c-op); }
.ncc-word { color: var(--ncc-c-word); }
.ncc-sec { color: var(--ncc-c-sec); font-weight: 700; }
.ncc-cont { color: var(--ncc-c-cont); font-weight: 700; }
.ncc-mac { color: var(--ncc-c-mac); font-weight: 700; }
.ncc-macn { color: var(--ncc-c-macn); }
.ncc-el { color: var(--ncc-c-el); font-weight: 600; }
.ncc-kind { color: var(--ncc-c-kind); font-weight: 700; }
.ncc-key { color: var(--ncc-c-key); }
.ncc-dkey { color: var(--ncc-c-dkey); }
.ncc-str { color: var(--ncc-c-str); }
.ncc-end { color: var(--ncc-c-sec); font-weight: 700; }
.ncc-tag { color: var(--ncc-c-tag); }
.ncc-tagp { color: var(--ncc-c-tagp); }
.ncc-attr { color: var(--ncc-c-attr); }
.ncc-aval { color: var(--ncc-c-aval); }
.ncc-text { color: var(--ncc-c-text); }
.ncc-ent { color: var(--ncc-c-ent); }
.ncc-decl { color: var(--ncc-c-decl); }
.ncc-cdata { color: var(--ncc-c-com); }

/* Screen-reader-only announcement of the picked line (MU-13). */
.nc-code-live {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  border: 0;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ empty */

.nc-code-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--ncc-dim);
  font-size: var(--nc-fs-md, 13px);
  text-align: center;
}

/* ----------------------------------------------------------------- editor */

/* The textarea covers the text column; the listing under it keeps drawing highlighted text,
   line numbers and bands. Weight and slant are dropped while editing so every glyph keeps the
   advance of the textarea's regular face. */
.nc-code-editor {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: var(--ncc-gutter-w);
  z-index: 2;
  /* Relayout boundary: typing lays out the textarea only, not the page around it. */
  contain: strict;
}

.nc-code-panel.is-editing .nc-code-scroller {
  overflow: hidden;
}

.nc-code-panel.is-editing .nc-code-line,
.nc-code-panel.is-editing .nc-code-line * {
  font-style: normal;
  font-weight: 400;
}

.nc-code-textarea {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0 8px var(--ncc-lh);
  border: 0;
  border-radius: 0;
  outline: none;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  font-style: normal;
  font-weight: 400;
  white-space: pre;
  overflow-wrap: normal;
  resize: none;
  caret-color: var(--ncc-text);
}

.nc-code-textarea::selection {
  background: color-mix(in srgb, var(--ncc-accent) 30%, transparent);
  color: transparent;
  -webkit-text-fill-color: transparent;
}

.nc-code-textarea:focus-visible {
  outline: 2px solid var(--ncc-accent);
  outline-offset: -2px;
}

/* Large programs: a plain textarea shows its own text; the listing only draws bands. */
.nc-code-panel.is-plain-edit .nc-code-textarea,
.nc-code-panel.is-plain-edit .nc-code-textarea::selection {
  color: var(--ncc-text);
  -webkit-text-fill-color: currentColor;
}

/* UX3-18: F8's diagnostic under its line keeps the message's own line breaks. */
.nc-code-tip-diag {
  white-space: pre-line;
}

/* UX3-35: the editor's ring sits inside its box (the panel clips anything outside); the shell's
   `#nc-app :focus-visible` offset must not win over it. The listing's ring is drawn over its rows
   and the gutter (an outline of the wrapper is painted under the gutter, z-index 1). */
#nc-app .nc-code-textarea:focus-visible {
  outline-offset: -2px;
}

#nc-app .nc-code-view:focus-visible {
  outline: none;
}

.nc-code-view:focus-visible::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border: 2px solid var(--nc-focus-color, var(--ncc-accent));
  pointer-events: none;
}

/* UX3-27: on a touch screen the panel's controls are finger-sized (40–44 px); the code lines keep
   their height (they are read and scrolled, the selection is the 3D's or the keys'). */
@media (pointer: coarse) {
  .nc-code-head {
    height: auto;
    min-height: 44px;
  }

  .nc-code-panel .nc-code-btn {
    min-width: 40px;
    min-height: 40px;
  }

  .nc-code-panel .nc-code-btn.nc-code-icon {
    width: 40px;
    min-width: 40px;
  }

  .nc-code-search-input {
    height: 40px;
  }

  .nc-code-opt {
    min-width: 32px;
    height: 32px;
    line-height: 30px;
  }

  .nc-code-menu-item {
    min-height: 44px;
  }

  /* The replace input and the wrapped options line up after the 40px toggle. */
  .nc-code-replace-row {
    padding-left: 44px;
  }

  @container ncc-search (min-width: 381px) {
    .nc-code-field .nc-code-search-input {
      padding-right: 104px; /* three 32px options inside the field */
    }
  }

  /* Narrow panels: the field and the 40px toggle share the first line, options · count · arrows
     the second (as with the mouse); the replace glyph buttons are finger-wide too. REV-P-09: the
     second line stays one line — tighter gaps, and the count gives way (its title has it whole)
     before ✕ would wrap to a line of its own. */
  @container ncc-search (max-width: 380px) {
    .nc-code-search-row {
      column-gap: 2px;
    }

    .nc-code-field .nc-code-search-input {
      flex-basis: calc(100% - 42px);
    }

    .nc-code-opts {
      margin-left: 0;
    }

    /* Basis 0: the count never pushes ✕ to a line of its own; it fills what the line leaves. */
    .nc-code-search-count {
      flex: 1 1 0;
      min-width: 0;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }

  @container ncc-search (max-width: calc(176px + 9.4em)) {
    .nc-code-panel .nc-code-glyph-btn {
      min-width: 40px;
    }
  }

  /* REV-P-13: a narrow head while editing with 3D 미반영 showing — the line count alone (`6,648`,
     its format in the title) and 「끝내기」, so the count is never cut to `6,…`. */
  .nc-code-head {
    container: ncc-head / inline-size;
  }

  @container ncc-head (max-width: 340px) {
    .nc-code-head:has(> .nc-code-dirty:not([hidden])) .nc-code-meta-rest,
    .nc-code-head:has(> .nc-code-dirty:not([hidden])) .nc-code-lbl-drop {
      display: none;
    }
  }
}

/* UX3-30: a long press on the panel's head, search options or menu selects no text and opens no
   callout (the code itself stays selectable for copying). */
.nc-code-head,
.nc-code-opts,
.nc-code-menu {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* UX5-43 (K3-08): while a press drags a text selection in the listing (nc/code onDragMove → release),
   only the listing's text can be selected — Chrome otherwise puts the selection's end under the
   pointer anywhere on the page (DRO, playback bar, header) until the release. Like the width drag's
   `body.nc-resizing *`. The pointer also passes through everything but the listing's text, the 3D
   view and the right panel: over the DRO, the header or the status bar Chrome then takes the
   listing's edge line as the end (and keeps scrolling), as past the window's edge; over the 3D view
   and the right panel the end stays on the line beside the pointer (measured: impl-P dbg_drag_variants). */
body.nc-code-text-drag,
body.nc-code-text-drag *:not(.nc-code-textin, .nc-code-textin *) {
  -webkit-user-select: none;
  user-select: none;
  pointer-events: none;
}

body.nc-code-text-drag .nc-code-textin {
  -webkit-user-select: text;
  user-select: text;
  pointer-events: auto;
}

body.nc-code-text-drag #nc-viewport,
body.nc-code-text-drag #nc-viewport *,
body.nc-code-text-drag #nc-right,
body.nc-code-text-drag #nc-right * {
  pointer-events: auto;
}

/* UX3-36: Windows high contrast drops fills and shadows: the selected line, the playback line,
   the current search hit and pressed buttons get system-colour outlines / fills; the gutter's
   diagnostic and motion marks keep their own colours (they are signs, like the op swatches). */
@media (forced-colors: active) {
  .nc-code-line.is-cur {
    outline: 2px dashed CanvasText;
    outline-offset: -2px;
  }

  .nc-code-line.is-sel,
  .nc-code-gline.is-sel,
  .nc-code-panel.is-playing .nc-code-line.is-sel:not(.is-cur) {
    outline: 2px solid Highlight;
    outline-offset: -2px;
  }

  .nc-code-line.is-hit {
    outline: 1px solid Highlight;
  }

  .nc-code-hit {
    outline: 1px solid CanvasText;
  }

  /* Highlight fills take forced-color-adjust: none — else the text backplate (Canvas) hides the
     HighlightText letters. */
  .nc-code-hit.is-current,
  .nc-code-hit.is-current > * {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }

  .nc-code-panel .nc-code-btn[aria-pressed="true"],
  .nc-code-panel .nc-code-btn[aria-expanded="true"]:not(.nc-code-rtoggle),
  .nc-code-opt[aria-pressed="true"],
  .nc-code-opt[aria-pressed="true"]:hover {
    forced-color-adjust: none;
    border-color: HighlightText;
    background: Highlight;
    color: HighlightText;
  }

  .nc-code-gdiag::after,
  .nc-code-gmark.is-on::after,
  .nc-code-gline.is-cur .nc-code-gmark::after {
    forced-color-adjust: none;
  }
}
