/* Playback bar (#nc-transport) and DRO (#nc-dro) for the NC viewer — owned by nc/player.
   Colours come from the shell tokens (--nc-*); the fallbacks only matter when nc_viewer.css is absent.
   Dark values switch on :root[data-theme="dark"] (the shell resolves the theme setting). */

#nc-transport.nc-player-transport,
#nc-dro.nc-dro-root {
  --ncp-panel: var(--nc-panel, #ffffff);
  --ncp-panel-2: var(--nc-panel-2, #f5f7fa);
  --ncp-border: var(--nc-border, #d8e0e9);
  --ncp-text: var(--nc-text, #111827);
  --ncp-dim: var(--nc-text-dim, #5b6678);
  --ncp-accent: var(--nc-accent, #0d73d9);
  --ncp-font: var(--nc-font, -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif);
  --ncp-mono: var(--nc-mono, ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace);
  --ncp-shadow: 0 6px 20px rgb(15 23 42 / 0.16), 0 1px 3px rgb(15 23 42 / 0.12);
  --ncp-rail: color-mix(in srgb, var(--ncp-dim) 32%, transparent);
  --ncp-x: #c2261d;
  --ncp-y: #0f7b3e;
  --ncp-z: #1f5fd1;
  /* "Where the machine is now" (nc/model PLAYBACK_COLORS); nc/player sets them per theme. */
  --ncp-play-fill: #f5b700;
  --ncp-play-outline: #111827;
  /* Type scale from the shell (:root, readability round); the fallbacks keep the same sizes. */
  --ncp-fs-micro: var(--nc-fs-micro, 11px);
  --ncp-fs-sm: var(--nc-fs-sm, 12px);
  --ncp-fs-lg: var(--nc-fs-lg, 14px);
  --ncp-fs-xl: var(--nc-fs-xl, 18px);
  --ncp-fw-medium: var(--nc-fw-medium, 500);
  --ncp-fw-semibold: var(--nc-fw-semibold, 600);
  --ncp-fw-bold: var(--nc-fw-bold, 700);
}

:root[data-theme="dark"] #nc-transport.nc-player-transport,
:root[data-theme="dark"] #nc-dro.nc-dro-root {
  --ncp-panel: var(--nc-panel, #141a22);
  --ncp-panel-2: var(--nc-panel-2, #19202a);
  --ncp-border: var(--nc-border, #29323e);
  --ncp-text: var(--nc-text, #e5e9ef);
  --ncp-dim: var(--nc-text-dim, #9aa6b6);
  --ncp-accent: var(--nc-accent, #3d95f2);
  --ncp-shadow: 0 6px 20px rgb(0 0 0 / 0.45), 0 1px 3px rgb(0 0 0 / 0.35);
  --ncp-rail: color-mix(in srgb, var(--ncp-dim) 38%, transparent);
  --ncp-x: #ff7a70;
  --ncp-y: #4cc38a;
  --ncp-z: #6ea8ff;
  --ncp-play-fill: #ffd23f;
}

/* ------------------------------------------------------------------ transport */

/* Full-width, click-through strip at the bottom of the viewport; only the bar takes pointer input. */
#nc-transport.nc-player-transport {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  z-index: 6;
  display: flex;
  justify-content: center;
  padding: 0 12px;
  box-sizing: border-box;
  pointer-events: none;
}

#nc-transport.nc-player-transport[data-empty] {
  display: none;
}

.nc-player-bar {
  position: relative;
  pointer-events: auto;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 960px;
  min-height: 40px;
  padding: 4px 8px 4px 4px;
  border: 1px solid var(--ncp-border);
  border-radius: 10px;
  background: var(--ncp-panel);
  background: color-mix(in srgb, var(--ncp-panel) 92%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  box-shadow: var(--ncp-shadow);
  color: var(--ncp-text);
  font: var(--ncp-fs-sm)/1.2 var(--ncp-font);
  user-select: none;
  -webkit-user-select: none;
}

.nc-player-bar[data-layout="compact"] {
  min-height: 36px;
  gap: 4px;
  padding: 2px 4px;
}

/* Idle: not playing, pointer away, no keyboard focus → only the surface steps back so the 3D
   shows through; text and icons keep full contrast (the blur keeps them readable). */
.nc-player-bar[data-idle] {
  border-color: color-mix(in srgb, var(--ncp-border) 45%, transparent);
  background: color-mix(in srgb, var(--ncp-panel) 55%, transparent);
  box-shadow: none;
}

.nc-player-group {
  display: flex;
  align-items: center;
  gap: 1px;
  flex: none;
}

.nc-player-group:empty {
  display: none;
}

.nc-player-extras {
  gap: 6px;
}

.nc-player-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ncp-text);
  font: inherit;
  cursor: pointer;
}

.nc-player-btn[hidden] {
  display: none;
}

.nc-player-btn svg {
  display: block;
  fill: currentColor;
}

/* «op / op»: the double chevron plus the word, so op steps never read as start / end (MW-10). */
.nc-player-btn.has-text {
  width: auto;
  min-width: 40px;
  gap: 1px;
  padding: 0 5px 0 3px;
  grid-auto-flow: column;
}

.nc-player-btn-nextOp.has-text {
  padding: 0 3px 0 5px;
}

.nc-player-btn-word {
  font-size: var(--ncp-fs-sm);
  font-weight: var(--ncp-fw-semibold);
  line-height: 1;
}

.nc-player-btn:hover:not(:disabled) {
  background: var(--ncp-panel-2);
}

.nc-player-btn:active:not(:disabled) {
  background: color-mix(in srgb, var(--ncp-accent) 18%, transparent);
}

.nc-player-btn:focus-visible,
.nc-player-speed:focus-visible,
.nc-player-scrub:focus-visible,
.nc-player-future-btn:focus-visible {
  outline: 2px solid var(--ncp-accent);
  outline-offset: 2px;
}

.nc-player-btn:disabled {
  color: var(--ncp-dim);
  cursor: default;
}

.nc-player-btn-toggle {
  width: 32px;
  height: 32px;
  margin: 0 2px;
  border-radius: 50%;
  /* Accent icon on a tint of itself: readable whatever accent the shell picks, light or dark. */
  background: color-mix(in srgb, var(--ncp-accent) 16%, transparent);
  color: var(--ncp-accent);
}

.nc-player-btn-toggle:hover:not(:disabled) {
  background: color-mix(in srgb, var(--ncp-accent) 26%, transparent);
}

.nc-player-btn-toggle:disabled {
  background: transparent;
}

.nc-player-btn-toggle .nc-player-icon-pause,
.nc-player-bar[data-playing] .nc-player-btn-toggle .nc-player-icon-play {
  display: none;
}

.nc-player-bar[data-playing] .nc-player-btn-toggle .nc-player-icon-pause {
  display: inline;
}

/* Scrubber: 24 px hit area, 6 px rail, op blocks (canvas), thumb. --p is the progress 0..1 on the
   play timeline (nc/player). The rail shows through the gaps: the hidden-link moves between ops. */
.nc-player-scrub {
  position: relative;
  flex: 1 1 240px;
  min-width: 120px;
  height: 24px;
  margin: 0 4px;
  border-radius: 4px;
  cursor: pointer;
  touch-action: none;
}

.nc-player-bar[data-layout="compact"] .nc-player-scrub {
  min-width: 72px;
  margin: 0 2px;
}

.nc-player-scrub[aria-disabled="true"] {
  cursor: default;
}

.nc-player-rail {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 6px;
  margin-top: -3px;
  overflow: hidden;
  border-radius: 1px;
  background: var(--ncp-rail);
}

/* Played part of the rail: neutral, so only the op blocks carry colour. */
.nc-player-fill {
  width: calc(var(--p, 0) * 100%);
  height: 100%;
  background: color-mix(in srgb, var(--ncp-dim) 70%, transparent);
}

/* Op blocks: 6 px in the op colours, the current one framed in the playback colour (2 + 1 px). */
.nc-player-blocks {
  position: absolute;
  left: 0;
  top: 50%;
  width: 100%;
  height: 14px;
  margin-top: -7px;
  pointer-events: none;
}

.nc-player-thumb {
  position: absolute;
  top: 50%;
  left: calc(var(--p, 0) * 100%);
  box-sizing: border-box;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid var(--ncp-play-outline);
  border-radius: 50%;
  background: var(--ncp-play-fill);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.35);
  pointer-events: none;
}

.nc-player-scrub:hover .nc-player-thumb,
.nc-player-bar[data-scrubbing] .nc-player-thumb {
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
}

.nc-player-preview {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  z-index: 2;
  max-width: 320px;
  overflow: hidden;
  padding: 4px 8px;
  border: 1px solid var(--ncp-border);
  border-radius: 6px;
  background: var(--ncp-panel);
  box-shadow: var(--ncp-shadow);
  color: var(--ncp-text);
  font-size: var(--ncp-fs-sm);
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
}

.nc-player-preview[hidden] {
  display: none;
}

.nc-player-time {
  flex: none;
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  font-family: var(--ncp-mono);
  font-size: var(--ncp-fs-sm);
  font-variant-numeric: tabular-nums;
  color: var(--ncp-dim);
  white-space: nowrap;
  cursor: default;
}

.nc-player-elapsed {
  color: var(--ncp-text);
  min-width: 4ch;
  text-align: right;
}

/* `op 19/31` next to the clock; min-width (from nc/player) keeps the scrubber still. */
.nc-player-opcount {
  margin-left: 6px;
  padding-left: 7px;
  border-left: 1px solid var(--ncp-border);
  color: var(--ncp-text);
  text-align: left;
}

.nc-player-opcount[hidden] {
  display: none;
}

.nc-player-bar[data-layout="compact"] .nc-player-time {
  gap: 1px;
}

.nc-player-bar[data-layout="compact"] .nc-player-opcount {
  margin-left: 4px;
  padding-left: 5px;
}

.nc-player-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nc-player-row[hidden] {
  display: none;
}

.nc-player-row-label {
  display: none;
  flex: none;
  min-width: 2.6em;
  color: var(--ncp-dim);
}

.nc-player-speed {
  flex: none;
  height: 26px;
  padding: 0 4px;
  border: 1px solid var(--ncp-border);
  border-radius: 6px;
  background: var(--ncp-panel-2);
  color: var(--ncp-text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

/* Future-path mode: 전체 / 앞으로 갈 경로 흐리게 / 지난 경로만. */
.nc-player-future {
  display: inline-flex;
  flex: none;
  padding: 1px;
  border: 1px solid var(--ncp-border);
  border-radius: 7px;
  background: var(--ncp-panel-2);
}

.nc-player-future-btn {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ncp-dim);
  cursor: pointer;
}

.nc-player-future-btn svg {
  display: block;
  fill: currentColor;
}

.nc-player-future-btn:hover {
  color: var(--ncp-text);
}

.nc-player-future-btn[aria-checked="true"] {
  background: var(--ncp-panel);
  box-shadow: 0 0 0 1px var(--ncp-border);
  color: var(--ncp-accent);
}

/* ⋯ popover: controls that do not fit inline move here (nc/player applyLayout). */
.nc-player-popover {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 200px;
  padding: 8px 10px;
  border: 1px solid var(--ncp-border);
  border-radius: 10px;
  background: var(--ncp-panel);
  box-shadow: var(--ncp-shadow);
}

.nc-player-popover[hidden] {
  display: none;
}

.nc-player-popover .nc-player-row-label {
  display: inline;
}

.nc-player-pop-steps {
  gap: 2px;
  flex-wrap: wrap;
}

.nc-player-bar[data-popover] .nc-player-more {
  background: var(--ncp-panel-2);
  color: var(--ncp-accent);
}

@media (prefers-reduced-motion: no-preference) {
  .nc-player-bar {
    transition: background-color 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
  }

  .nc-player-btn,
  .nc-player-future-btn,
  .nc-dro-toggle svg {
    transition: background-color 0.12s ease, color 0.12s ease, transform 0.15s ease;
  }
}

/* ------------------------------------------------------------------ DRO */

#nc-dro.nc-dro-root {
  display: block;
  /* The field grid adapts to the left panel width (NU-03). */
  container: nc-dro / inline-size;
  border-top: 1px solid var(--ncp-border);
  background: var(--ncp-panel);
  color: var(--ncp-text);
  font: var(--ncp-fs-sm)/1.35 var(--ncp-font);
}

#nc-dro.nc-dro-root[data-empty] {
  display: none;
}

.nc-dro-header {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 2px 8px 2px 2px;
  background: var(--ncp-panel-2);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

#nc-dro.nc-dro-root:not([data-collapsed]) .nc-dro-header {
  border-bottom: 1px solid var(--ncp-border);
}

.nc-dro-toggle {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ncp-dim);
  cursor: pointer;
}

.nc-dro-toggle:hover {
  background: color-mix(in srgb, var(--ncp-dim) 14%, transparent);
  color: var(--ncp-text);
}

.nc-dro-toggle:focus-visible {
  outline: 2px solid var(--ncp-accent);
  outline-offset: -2px;
}

.nc-dro-toggle svg {
  display: block;
}

#nc-dro.nc-dro-root[data-collapsed] .nc-dro-toggle svg {
  transform: rotate(-90deg);
}

.nc-dro-title {
  flex: none;
  font-weight: var(--ncp-fw-semibold);
}

#nc-dro.nc-dro-root[data-collapsed] .nc-dro-title,
#nc-dro.nc-dro-root[data-collapsed] .nc-dro-unit {
  display: none;
}

/* Collapsed one-line summary: fixed-width numbers so nothing shifts while playing. */
.nc-dro-summary {
  display: none;
  flex: 1 1 auto;
  align-items: baseline;
  column-gap: 5px;
  min-width: 0;
  overflow: hidden;
  font-family: var(--ncp-mono);
  font-size: var(--ncp-fs-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Fit by priority (nc/player fitSummary): X Y Z always, then F, then the tool; digits are never cut.
   `…` marks dropped items (they stay in its tooltip and in the expanded DRO). */
.nc-dro-summary[data-fit="no-tool"] .nc-dro-sum-tool,
.nc-dro-summary[data-fit="axes"] .nc-dro-sum-tool,
.nc-dro-summary[data-fit="axes"] .nc-dro-sum-feed,
.nc-dro-summary[data-fit="axes-tight"] .nc-dro-sum-tool,
.nc-dro-summary[data-fit="axes-tight"] .nc-dro-sum-feed,
.nc-dro-summary[data-fit="axes-tight"] .nc-dro-sum-unit,
.nc-dro-summary[data-fit="aux-tight"] .nc-dro-sum-tool,
.nc-dro-summary[data-fit="aux-tight"] .nc-dro-sum-unit,
.nc-dro-summary[data-fit="aux-bare"] .nc-dro-sum-tool,
.nc-dro-summary[data-fit="aux-bare"] .nc-dro-sum-unit,
.nc-dro-summary[data-fit="wrap"] .nc-dro-sum-tool,
.nc-dro-summary[data-fit="wrap"] .nc-dro-sum-feed {
  display: none;
}

/* Panels keep the depth when the summary wraps (RU-13: it never hides behind `+N`). */
#nc-dro.nc-dro-root[data-group="panel"] .nc-dro-summary[data-fit="wrap"] .nc-dro-sum-feed {
  display: block;
}

.nc-dro-summary[data-fit="wrap"] {
  flex-wrap: wrap;
  row-gap: 1px;
  padding: 2px 0;
}

/* `+N` chip: items the summary dropped (latin/numbers only, so the micro size is allowed). */
.nc-dro-sum-more {
  flex: none;
  align-self: center;
  padding: 0 4px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--ncp-dim) 16%, transparent);
  color: var(--ncp-text);
  font-size: var(--ncp-fs-micro);
  font-weight: var(--ncp-fw-semibold);
  line-height: 16px;
  cursor: help;
}

.nc-dro-sum-more[hidden] {
  display: none;
}

#nc-dro.nc-dro-root[data-collapsed] .nc-dro-summary {
  display: flex;
}

.nc-dro-sum-axis {
  display: inline-flex;
  flex: none;
  gap: 2px;
}

.nc-dro-sum-label {
  font-weight: var(--ncp-fw-bold);
}

/* The unit follows Z, so it reads as the coordinates' unit and never as the feed's. */
.nc-dro-sum-unit {
  margin-left: 3px;
  color: var(--ncp-dim);
}

.nc-dro-sum-x .nc-dro-sum-label {
  color: var(--ncp-x);
}

.nc-dro-sum-y .nc-dro-sum-label {
  color: var(--ncp-y);
}

.nc-dro-sum-z .nc-dro-sum-label {
  color: var(--ncp-z);
}

/* min-width per program comes from nc/player (the widest value it can show). */
.nc-dro-sum-value {
  min-width: 7ch;
  text-align: right;
}

.nc-dro-sum-feed,
.nc-dro-sum-tool {
  flex: none;
  color: var(--ncp-dim);
}

.nc-dro-unit {
  flex: 1 1 auto;
  font-weight: var(--ncp-fw-medium);
  color: var(--ncp-dim);
}

.nc-dro-body[hidden] {
  display: none;
}

/* Axis letter and value side by side (RU-12): values right-aligned in a per-program min-width
   (nc/player) so the decimal points line up, instead of at the far edge of the panel. */
.nc-dro-axes {
  display: grid;
  grid-template-columns: 16px max-content;
  justify-content: start;
  align-items: baseline;
  column-gap: 10px;
  padding: 6px 12px 4px;
  font-family: var(--ncp-mono);
}

.nc-dro-axis-label {
  font-size: var(--ncp-fs-lg);
  font-weight: var(--ncp-fw-bold);
}

.nc-dro-axis-x {
  color: var(--ncp-x);
}

.nc-dro-axis-y {
  color: var(--ncp-y);
}

.nc-dro-axis-z {
  color: var(--ncp-z);
}

.nc-dro-axis-value {
  min-width: 9ch;
  overflow: hidden;
  font-size: var(--ncp-fs-xl);
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.nc-dro-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px 14px;
  margin: 0;
  padding: 5px 12px 8px;
  border-top: 1px dashed var(--ncp-border);
}

.nc-dro-field {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.nc-dro-field.is-wide {
  grid-column: 1 / -1;
}

/* Every label is at most three Hangul (회전수), so one width lines the values up in each column. */
.nc-dro-field-label {
  flex: none;
  min-width: 3.2em;
  color: var(--ncp-dim);
}

.nc-dro-field-value {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-family: var(--ncp-mono);
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A narrow left panel (1024 px window): the tool gets its own row so `T600 Ø6 mm` is not cut. */
@container nc-dro (max-width: 279px) {
  .nc-dro-field[data-key="tool"] {
    grid-column: 1 / -1;
  }
}

/* Names (motion, op) are text, not numbers. */
.nc-dro-field.is-text .nc-dro-field-value {
  font-family: inherit;
}
