/* ===== 로컬 번들 폰트 (오프라인) — DS tokens/fonts.css와 동일 구성 =====
   UI: Inter(가변, 라틴 — 450/700 포함 전 웨이트), 한글은 Pretendard 폴백.
   Mono: JetBrains Mono(가변, 라틴). */
@font-face { font-family: 'Inter'; font-weight: 100 900; font-style: normal; font-display: swap; src: url('fonts/inter-var.woff2') format('woff2'); }
@font-face { font-family: 'Pretendard'; font-weight: 400; font-style: normal; font-display: swap; src: url('fonts/pretendard-400.woff2') format('woff2'); }
@font-face { font-family: 'Pretendard'; font-weight: 500; font-style: normal; font-display: swap; src: url('fonts/pretendard-500.woff2') format('woff2'); }
@font-face { font-family: 'Pretendard'; font-weight: 600; font-style: normal; font-display: swap; src: url('fonts/pretendard-600.woff2') format('woff2'); }
/* DS 지정 모노 폰트 — 수치·단축키·헥스 전용 (가변 웨이트, 라틴 서브셋) */
@font-face { font-family: 'JetBrains Mono'; font-weight: 100 800; font-style: normal; font-display: swap; src: url('fonts/jetbrains-mono-var.woff2') format('woff2'); }

/* ===== Pixel Edit — Design System 토큰 =====
   Pixel Edit Design System의 ui_kits/pixel-canvas 화면을 그대로 재현.
   웜뉴트럴 그레이 램프 + 스틸블루 액센트, 다크 아트보드, 플로팅 줌 필.
   모노 폰트는 수치·단축키 전용 — DS 지정 JetBrains Mono(로컬 번들). */
:root {
  /* ---- 뉴트럴 그레이 램프 ---- */
  --gray-1000: #171717;
  --gray-950:  #1c1c1c;
  --gray-900:  #202020;
  --gray-800:  #292929;
  --gray-750:  #303030;
  --gray-700:  #353535;
  --gray-650:  #3d3d3d;
  --gray-600:  #404040;
  --gray-550:  #4b4b4b;
  --gray-500:  #5c5c5c;
  --gray-450:  #6e6e6e;
  --gray-400:  #808080;
  --gray-300:  #a8a8a8;
  --gray-100:  #e9e9e9;

  /* ---- 액센트: 스틸블루 ---- */
  --blue-600: #2b6fd6;
  --blue-500: #4a86e0;
  --blue-tint: #273647;

  /* ---- 시맨틱 별칭 ---- */
  --bg: var(--gray-1000);            /* 캔버스 백드롭 */
  --surface: var(--gray-800);        /* 도킹 패널·상단바 */
  --surface-raised: var(--gray-700); /* 팝오버·메뉴·hover */
  --surface-inset: var(--gray-900);  /* 입력 필드 웰 */
  --surface-control: var(--gray-600);
  --surface-control-hover: var(--gray-550);
  --surface-control-active: var(--gray-500);
  --surface-selected: var(--blue-tint);
  --border-subtle: var(--gray-1000); /* 패널 사이 다크 헤어라인 */
  --border: var(--gray-650);
  --border-strong: var(--gray-500);
  --text: var(--gray-100);
  --text-dim: var(--gray-300);
  --text-faint: var(--gray-400);
  --text-disabled: var(--gray-450);
  --accent: var(--blue-600);
  --accent-hi: var(--blue-500);
  --on-accent: #ffffff;
  --danger: #e5484d;

  --font-ui: 'Inter', 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* 라운딩 — 절제. 칩 3 / 인풋 4 / 버튼 6 / 플로팅 8 / 필 full */
  --radius-xs: 3px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-full: 999px;

  /* 엘리베이션 */
  --shadow-popover: 0 8px 28px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.4);
  --shadow-menu: 0 6px 20px rgba(0, 0, 0, 0.5);
  --shadow-inset: inset 0 1px 0 rgba(0, 0, 0, 0.35);
  --shadow-stage: 0 12px 40px rgba(0, 0, 0, 0.5);
  --ring-focus: 0 0 0 1px var(--surface), 0 0 0 3px rgba(43, 111, 214, 0.55);

  /* 모션 — 즉각적이고 기능적. 바운스 없음 */
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --dur-fast: 120ms;

  /* 다크 아트보드 체커 — 킷(#242424/#1d1d1d)보다 한 단계 밝게:
     "투명"이 Ink(#1d1d1d)나 맨 배경과 구분되어 항상 체커로 읽히도록 */
  --board: #1d1d1d;
  --checker: repeating-conic-gradient(#3a3a3a 0% 25%, #2a2a2a 0% 50%) 50% / 16px 16px;
  --checker-sm: repeating-conic-gradient(#3a3a3a 0% 25%, #2a2a2a 0% 50%) 50% / 8px 8px;

  --badge-bg: rgba(168, 168, 168, 0.16);
  --scroll-thumb: var(--gray-550);
  --scroll-thumb-hover: var(--gray-500);
  --tracking-caps: 0.06em;
}

/* ===== 라이트 테마 — 킷(PixelCanvasShell)의 TOKENS.light + ART.light 오버라이드 ===== */
:root[data-theme="light"] {
  --bg: #e7e8ea;
  --surface: #ffffff;
  --surface-raised: #f1f2f3;
  --surface-inset: #f5f6f7;
  --surface-control: #e9eaec;
  --surface-control-hover: #dee0e3;
  --surface-control-active: #d2d5d9;
  --surface-selected: #e6effc;
  --border-subtle: #e4e6e9;
  --border: #d9dce0;
  --border-strong: #c2c6cc;
  --text: #1c1e21;
  --text-dim: #565a60;
  --text-faint: #868b92;
  --text-disabled: #b3b7bd;
  --shadow-popover: 0 8px 28px rgba(20, 24, 31, 0.14), 0 2px 6px rgba(20, 24, 31, 0.08);
  --shadow-menu: 0 6px 20px rgba(20, 24, 31, 0.14);
  --shadow-inset: inset 0 1px 0 rgba(0, 0, 0, 0.04);
  --shadow-stage: 0 10px 34px rgba(20, 24, 31, 0.16);
  --ring-focus: 0 0 0 1px #ffffff, 0 0 0 3px rgba(43, 111, 214, 0.45);
  --board: #ffffff;
  --checker: repeating-conic-gradient(#ffffff 0% 25%, #d8dade 0% 50%) 50% / 16px 16px;
  --checker-sm: repeating-conic-gradient(#ffffff 0% 25%, #d8dade 0% 50%) 50% / 8px 8px;
  --badge-bg: rgba(20, 24, 31, 0.08);
  --scroll-thumb: #c2c6cc;
  --scroll-thumb-hover: #aab0b8;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 12px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-variant-numeric: tabular-nums;
}
::selection { background: var(--accent); color: var(--on-accent); }

#app { display: flex; flex-direction: column; height: 100vh; background: var(--bg); }
.spacer { flex: 1; }

/* ===== 상단바 (48px) ===== */
#topbar {
  height: 48px; flex: none;
  display: flex; align-items: center; gap: 4px;
  padding: 0 12px;
  background: var(--surface); border-bottom: 1px solid var(--border-subtle);
}
.brand { display: flex; align-items: center; gap: 8px; padding-right: 12px; }
.brand-tile {
  width: 22px; height: 22px; border-radius: var(--radius-sm);
  background: var(--accent); display: inline-grid; place-items: center;
}
.brand-name {
  font: 700 12px/1.3 var(--font-ui); color: var(--text-dim);
  text-transform: uppercase; letter-spacing: var(--tracking-caps); white-space: nowrap;
}
.brand-name b { color: var(--text); }

/* 상단바 현재 프로젝트 이름 (읽기 전용 라벨) */
.project-name {
  font: 600 12px/1.3 var(--font-ui);
  color: var(--text-dim);
  max-width: 180px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* 사이즈 배지 — 대문자 뉴트럴 필 */
.badge {
  height: 20px; padding: 0 9px; border-radius: var(--radius-full);
  background: var(--badge-bg); color: var(--text-dim);
  font: 600 10px/20px var(--font-ui); letter-spacing: var(--tracking-caps);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}

/* 상단바 버튼 — DS Button (ghost / primary, sm) */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 12px; margin-left: 4px;
  border: none; border-radius: var(--radius-md); cursor: pointer;
  font-family: var(--font-ui); font-size: 12px; font-weight: 500; line-height: 1;
  transition: background var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.btn .icon { width: 14px; height: 14px; }
.btn.ghost { background: transparent; color: var(--text-dim); }
.btn.ghost:hover:not([disabled]) { background: var(--surface-raised); color: var(--text); }
.btn.icon-only { width: 28px; padding: 0; justify-content: center; }
.btn.icon-only .icon { width: 15px; height: 15px; }
.btn.primary { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover:not([disabled]) { background: var(--accent-hi); }
.btn:focus-visible { outline: none; box-shadow: var(--ring-focus); }
button[disabled] { opacity: 0.35; cursor: not-allowed; }

/* 테마 스위치 — 킷 사양: sm(24px) 아이콘 버튼 2개, gap 2, 활성만 --text, 비활성 --text-faint */
#theme-switch { display: flex; align-items: center; gap: 2px; margin-left: 4px; }
#theme-switch .btn { margin-left: 0; width: 24px; height: 24px; color: var(--text-faint); }
#theme-switch .btn .icon { width: 14px; height: 14px; }
#theme-switch .btn.current { color: var(--text); }
/* 라이트 모드의 비활성 아이콘(달)은 한 단계 더 밝은 회색으로 */
:root[data-theme="light"] #theme-switch .btn:not(.current) { color: var(--text-disabled); }

/* ===== 상단바 Load/Save 드롭다운 — 킷(PixelCanvasShell) Export 드롭다운과 동일 =====
   트리거: 고스트 sm 버튼 + 우측 13px 셰브론.
   팝오버: 240px, 패널 서피스, radius-md, popover 그림자, padding 4.
   항목(ExportItem): 30px 아이콘 타일 + 제목/설명 2줄, hover는 raised 서피스. */
.btn .icon.chev { width: 13px; height: 13px; margin: 0 -2px; }
.menu { position: relative; display: flex; }
.menu.open > .btn.ghost { background: var(--surface-raised); color: var(--text); }
.menu-dropdown {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 100;
  width: 240px; padding: 4px;
  flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-popover);
}
.menu.open .menu-dropdown { display: flex; }
.menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: none; border: none; border-radius: var(--radius-sm);
  padding: 8px 10px; cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard);
}
.menu-item:hover:not([disabled]) { background: var(--surface-raised); }
.menu-item[disabled] { opacity: 0.35; cursor: not-allowed; }
.mi-icon {
  width: 30px; height: 30px; flex: none;
  border-radius: var(--radius-sm); background: var(--surface-inset);
  border: 1px solid var(--border);
  display: grid; place-items: center; color: var(--text-dim);
}
.mi-icon .icon { width: 16px; height: 16px; }
.mi-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.mi-title { font: 600 12px/1.3 var(--font-ui); color: var(--text); }
.mi-desc { font: 500 11px/1.3 var(--font-ui); color: var(--text-faint); }

/* Load 드롭다운 프로젝트 목록 */
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; flex-shrink: 0; }
#project-list { display: flex; flex-direction: column; max-height: 40vh; overflow-y: auto; }
#project-list:empty { display: none; }
.project-row { cursor: pointer; }
.project-row.current .mi-title { color: var(--accent-hi); }
.proj-del {
  margin-left: auto; flex-shrink: 0;
  background: none; border: none; cursor: pointer; padding: 2px;
  color: var(--text-faint); display: none;
}
.project-row:hover .proj-del { display: inline-flex; }
.proj-del:hover { color: var(--text); }
.proj-del .icon { width: 14px; height: 14px; }

/* ===== 작업 공간 ===== */
#workspace { flex: 1; display: flex; min-height: 0; }

/* 좌측 툴레일 (48px) — 아이콘 전용, 활성 도구는 한 단계 밝은 채움 */
#tool-rail {
  width: 48px; flex: none;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 0;
  background: var(--surface); border-right: 1px solid var(--border-subtle);
}
.rail-btn {
  width: 32px; height: 32px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--radius-md);
  background: transparent; color: var(--text-dim); cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.rail-btn:hover:not([disabled]):not(.active) { background: var(--surface-raised); color: var(--text); }
.rail-btn.active { background: var(--surface-control-active); color: var(--text); }
/* 그리드 토글은 도구와 달리 채움 없이 아이콘만 액센트 색 (킷 사양) */
#rail-grid.active { background: transparent; color: var(--accent); }
#rail-grid.active:hover:not([disabled]) { background: var(--surface-raised); }
.rail-btn:focus-visible { outline: none; box-shadow: var(--ring-focus); }
.rail-btn .icon { width: 18px; height: 18px; }
.rail-sep { width: 24px; height: 1px; margin: 4px 0; background: var(--border); }

/* ===== 도킹 패널 공통 ===== */
#frame-list {
  width: 176px; flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-right: 1px solid var(--border-subtle);
}
#right-panel {
  width: 244px; flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-left: 1px solid var(--border-subtle);
}
#layer-list { display: flex; flex-direction: column; min-height: 0; max-height: 42%; }
/* 레이어 아래 섹션들(Background/Palette/Shades)을 담는 스크롤 영역 */
#right-sections { flex: 1; min-height: 0; overflow-y: auto; }

/* 섹션 헤더 — 패널 헤더(FRAMES/LAYERS)와 동일한 40px, 위아래 헤어라인, 볼드 대문자 라벨 */
.section-header {
  height: 40px; flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  border-top: 1px solid var(--border-subtle); border-bottom: 1px solid var(--border-subtle);
  font: 700 11px/1.3 var(--font-ui); color: var(--text-dim);
  text-transform: uppercase; letter-spacing: var(--tracking-caps);
}
.section-body { padding: 12px 12px 14px; }

/* 패널 헤더 — 40px, 대문자 라벨 + "+" 버튼 */
.panel-header {
  height: 40px; flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 0 12px;
  border-bottom: 1px solid var(--border-subtle);
}
.panel-title {
  font: 700 11px/1 var(--font-ui); color: var(--text-dim);
  letter-spacing: var(--tracking-caps); text-transform: uppercase;
}
.panel-add {
  width: 22px; height: 22px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--radius-xs);
  background: none; color: var(--text-dim); cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.panel-add:hover:not([disabled]), .panel-add:focus-visible:not([disabled]) {
  background: var(--surface-control); color: var(--text); outline: none;
}
.panel-add .icon { width: 15px; height: 15px; }
.panel-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
#frame-list .panel-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; }
#layer-list .panel-body { padding: 6px; display: flex; flex-direction: column; gap: 2px; }
/* 빈 상태 문구 — 패널 본문 패딩과 합쳐 좌측 12px, 헤더 타이틀과 정렬 */
.empty-note { color: var(--text-faint); font-size: 12px; padding: 8px 0; }
#frame-list .empty-note { padding-left: 4px; }
#layer-list .empty-note { padding-left: 6px; }

/* ===== 프레임 카드 ===== */
.frame-box {
  position: relative; flex: none;
  padding: 6px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
  transition: background var(--dur-fast) var(--ease-standard);
}
.frame-box:hover:not(.selected) { background: var(--surface-raised); }
.frame-box.selected { background: var(--surface-selected); border-color: var(--accent); }
.frame-art {
  /* Background 섹션 선택을 따름 (ui.js가 --frame-art-bg 설정; 투명 = 체커) */
  background: var(--frame-art-bg, var(--board)); border-radius: 3px; overflow: hidden;
  display: grid; place-items: center; padding: 4px;
}
.frame-thumb { display: block; max-width: 100%; height: auto; image-rendering: pixelated; }
.frame-meta { display: flex; align-items: center; justify-content: space-between; min-height: 18px; }
.frame-index { font: 500 12px var(--font-mono); color: var(--text-faint); }
.frame-box.selected .frame-index { color: var(--text); }
.frame-remove {
  width: 18px; height: 18px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--radius-xs);
  background: none; color: var(--text-faint); cursor: pointer;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.frame-box:hover .frame-remove, .frame-remove:focus-visible { opacity: 1; }
.frame-remove:hover, .frame-remove:focus-visible { color: var(--danger); outline: none; }
.frame-remove .icon { width: 13px; height: 13px; }

/* ===== 캔버스 스테이지 ===== */
#editor-area { flex: 1; min-width: 0; position: relative; background: var(--bg); }
#editor-area.drag-over { outline: 2px dashed var(--accent); outline-offset: -10px; }
/* 빌드 버전 표기 — 편집 영역 좌하단 구석, 배포(dist) 빌드에서만 채워진다 */
#version-tag {
  position: absolute; left: 8px; bottom: 6px;
  font: 500 10px/1.2 var(--font-ui);
  color: var(--text-faint);
  pointer-events: none; user-select: none;
}
#version-tag:empty { display: none; }
#stage-scroll { position: absolute; inset: 0; overflow: auto; display: flex; }
/* 배경(체커/단색)은 캔버스가 아니라 스테이지 div에 깐다 — Chromium이 가속 캔버스
   레이어에서 단색→그라디언트 배경 전환을 다시 그리지 않는 버그가 있어(직전 단색이
   화면에 남음), 배경 전환은 일반 div에서 처리하고 캔버스는 투명하게 둔다. */
#stage {
  margin: auto; line-height: 0; flex: none;
  background: var(--checker); border: 1px solid var(--border);
  box-shadow: var(--shadow-stage);
}
#editor-canvas { image-rendering: pixelated; display: block; }

/* 플로팅 줌/상태 필 (하단 중앙) */
#zoom-pill {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 6px 0 12px;
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--radius-full); box-shadow: var(--shadow-popover);
}
.pill-value { font: 500 12px var(--font-mono); color: var(--text-dim); }
.pill-percent { font: 500 12px var(--font-mono); color: var(--text); min-width: 44px; text-align: center; }
.pill-sep { width: 1px; height: 16px; background: var(--border); }
.pill-btn {
  width: 24px; height: 24px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--radius-full);
  background: transparent; color: var(--text-dim); cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.pill-btn:hover:not([disabled]) { background: var(--surface-control); color: var(--text); }
.pill-btn:focus-visible { outline: none; box-shadow: var(--ring-focus); }
.pill-btn .icon { width: 14px; height: 14px; }

/* ===== 레이어 행 (40px, 라운드, 선택=블루 워시+액센트 보더) ===== */
.layer-row {
  position: relative; flex: none;
  display: flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 8px 0 10px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard);
}
.layer-row:hover:not(.selected) { background: var(--surface-raised); }
.layer-row.selected { background: var(--surface-selected); border-color: var(--accent); }
.layer-row.dragging { opacity: 0.4; }
.layer-row.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.layer-row.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.layer-row.hidden-layer .layer-name, .layer-row.hidden-layer .layer-thumb { opacity: 0.5; }
.layer-row .vis {
  width: 18px; height: 18px; padding: 0; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; user-select: none; background: none; border: none;
  color: var(--text-dim);
  transition: color var(--dur-fast) var(--ease-standard);
}
.layer-row.hidden-layer .vis { color: var(--text-disabled); }
.layer-row .vis:hover { color: var(--text); }
.layer-row .vis .icon { width: 15px; height: 15px; }
.layer-row .layer-thumb {
  width: 26px; height: 26px; flex: none; object-fit: contain; image-rendering: pixelated;
  background: var(--checker-sm);
  border: 1px solid var(--border); border-radius: 3px;
}
.layer-row .layer-name {
  flex: 1; min-width: 0; font-size: 12px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.layer-row.selected .layer-name { color: var(--text); }
.layer-row .layer-name input {
  width: 100%; font-size: 12px; font-family: var(--font-ui);
  background: var(--surface-inset); color: var(--text);
  border: 1px solid var(--accent); border-radius: var(--radius-xs); padding: 1px 3px;
}
.layer-row .layer-btn {
  width: 18px; height: 18px; padding: 0; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: var(--radius-xs);
  color: var(--text-faint); cursor: pointer; opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.layer-row:hover .layer-btn:not([disabled]), .layer-row .layer-btn:focus-visible:not([disabled]) { opacity: 1; }
.layer-row .layer-btn:hover:not([disabled]), .layer-row .layer-btn:focus-visible:not([disabled]) {
  color: var(--danger); outline: none;
}
.layer-row .layer-btn .icon { width: 13px; height: 13px; }
.layer-row .layer-btn[disabled] { opacity: 0; cursor: default; }

/* ===== BACKGROUND 섹션 — 킷 채택 사양 (투명/흰/회/검 + 커스텀 추가 칩) ===== */
/* 팔레트와 동일한 5열 그리드 — 커스텀 색이 늘면 +칩과 함께 다음 행으로 흐른다 */
#bg-swatches, #quant-swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 8px; }
.bg-swatch {
  width: 100%; height: 24px; padding: 0; position: relative;
  border: 1px solid var(--border); border-radius: var(--radius-xs); cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-standard);
}
.bg-swatch:hover:not(.current) { border-color: var(--border-strong); }
.bg-swatch.current { border: 2px solid var(--accent); box-shadow: var(--ring-focus); }
/* 투명 = 보더 색으로 그린 10px conic 체커 (테마 자동 대응) */
.bg-swatch.transparent {
  background-image: conic-gradient(var(--border) 0 25%, transparent 0 50%, var(--border) 0 75%, transparent 0);
  background-size: 10px 10px;
}
/* 커스텀 추가 칩: 점선 + 플러스. 고른 색은 새 스와치로 목록에 추가된다 */
.bg-swatch.custom {
  display: grid; place-items: center; background: transparent;
  border-style: dashed; border-color: var(--border-strong); color: var(--text-faint);
}
.bg-swatch.custom .icon { width: 15px; height: 15px; }
.bg-swatch.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.bg-caption { font: 500 11px/1.4 var(--font-ui); color: var(--text-faint); }
/* Quantize 섹션 실행 버튼 — 섹션 폭에 맞춤 */
.quant-run { width: 100%; justify-content: center; margin: 0 0 6px; }

/* ===== 팔레트 섹션 ===== */
.active-color { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
#color-input {
  width: 44px; height: 44px; padding: 0; flex: none;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-inset); background: none; cursor: pointer;
}
#color-input::-webkit-color-swatch-wrapper { padding: 0; }
#color-input::-webkit-color-swatch { border: none; border-radius: 3px; }
#color-input::-moz-color-swatch { border: none; border-radius: 3px; }
.active-color-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#color-hex { font: 500 12px var(--font-mono); color: var(--text); text-transform: uppercase; }
.active-color-caption { font: 500 11px var(--font-ui); color: var(--text-faint); }

/* 가변 색 · 5열 그리드 · 24px 칩 — 10개 초과 시 행 추가, 0-9만 단축키 */
#palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.pal-slot {
  position: relative; height: 24px; width: 100%; padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius-xs); cursor: pointer;
}
.pal-slot.current { border: 2px solid var(--accent); box-shadow: var(--ring-focus); }
.pal-slot .pal-n {
  position: absolute; top: 3px; left: 3px;
  font-family: var(--font-ui); font-weight: 700; font-size: 9px; line-height: 1;
}

#shade-ramp { display: flex; gap: 4px; }
.shade {
  flex: 1; height: 24px; display: inline-block; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-xs);
}
.shade.current { cursor: default; border: 2px solid var(--accent); }
.shade:hover:not(.current) { border-color: var(--border-strong); }

/* ===== 상태바 (26px) ===== */
#status-bar {
  height: 26px; flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  background: var(--surface); border-top: 1px solid var(--border-subtle);
  font: 500 11px var(--font-ui); color: var(--text-faint);
}
.status-icon { width: 12px; height: 12px; flex: none; }
#status-msg { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-value { font: 500 11px var(--font-mono); color: var(--text-faint); white-space: nowrap; }
.status-sep { width: 1px; height: 12px; background: var(--border); }

/* ===== 내장 모달 (window.prompt/confirm 대체) — 플로팅 팝오버 문법 ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.5);
}
.modal-overlay[hidden] { display: none; }
.modal {
  min-width: 320px; max-width: 90vw; padding: 16px;
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-popover);
  font-family: var(--font-ui); color: var(--text);
}
.modal-msg { font-size: 12px; line-height: 1.5; white-space: pre-line; margin-bottom: 12px; }
.modal-input {
  width: 100%; box-sizing: border-box; margin-bottom: 14px; padding: 0 9px; height: 28px;
  background: var(--surface-inset); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-inset);
  font-family: var(--font-mono); font-size: 12px;
}
.modal-input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring-focus); }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; }
.modal-btns button {
  height: 28px; padding: 0 14px; border-radius: var(--radius-md); cursor: pointer;
  font-family: var(--font-ui); font-size: 12px; font-weight: 500;
  border: 1px solid var(--border); background: var(--surface-control); color: var(--text);
  transition: background var(--dur-fast) var(--ease-standard);
}
.modal-cancel:hover { background: var(--surface-control-hover); }
.modal-ok { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.modal-ok:hover { background: var(--accent-hi); border-color: var(--accent-hi); }
.modal-btns button:focus-visible { outline: none; box-shadow: var(--ring-focus); }

/* ===== Import 다이얼로그 — 킷 ImportDialog 사양 ===== */
.import-dialog {
  width: 440px; max-width: 92vw;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-popover); overflow: hidden;
}
.imp-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border-subtle);
}
.imp-badge {
  width: 26px; height: 26px; flex: none; border-radius: var(--radius-md);
  background: var(--surface-selected); color: var(--accent);
  display: grid; place-items: center;
}
.imp-titles { flex: 1; min-width: 0; }
.imp-title { font: 700 12px/1.3 var(--font-ui); color: var(--text); }
.imp-sub { font: 500 11px/1.3 var(--font-ui); color: var(--text-faint); }
.imp-sub b { font: 500 12px var(--font-mono); color: var(--text-dim); }
.imp-body { padding: 16px; }
.imp-preview {
  background: repeating-conic-gradient(var(--surface-inset) 0% 25%, var(--surface-control) 0% 50%) 0 0 / 14px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px; margin-bottom: 16px; display: grid; place-items: center;
}
.imp-preview canvas { display: block; image-rendering: pixelated; max-width: 100%; }
.imp-label {
  display: block; margin-bottom: 8px;
  font: 700 11px/1.3 var(--font-ui); color: var(--text-faint);
  text-transform: uppercase; letter-spacing: var(--tracking-caps);
}
.imp-note { font: 400 12px/1.4 var(--font-ui); color: var(--text-dim); }
.imp-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-top: 1px solid var(--border-subtle);
  background: var(--surface-raised);
}
.imp-count { flex: 1; font: 500 11px var(--font-ui); color: var(--text-faint); }
.imp-count b { font: 500 12px var(--font-mono); color: var(--text-dim); }
.imp-footer .btn { margin-left: 0; }
.btn.secondary { background: var(--surface-control); border: 1px solid var(--border); color: var(--text); }
.btn.secondary:hover:not([disabled]) { background: var(--surface-control-hover); }

/* ===== Preview 다이얼로그 — 스프라이트 100%/200% 미리보기 (Import 다이얼로그 구조 재사용) ===== */
.preview-dialog { width: auto; min-width: 320px; max-width: 92vw; }
.pv-stage { min-height: 96px; }
.pv-seg { margin-bottom: 0; }

/* 세그먼트 컨트롤 — DS forms/SegmentedControl (인셋 트랙 + 밝게 뜬 활성 세그먼트) */
.seg {
  display: flex; padding: 2px; gap: 2px; height: 28px; margin-bottom: 16px;
  background: var(--surface-inset); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}
.seg button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center;
  padding: 0 12px; border: none; border-radius: var(--radius-sm);
  font: 500 12px var(--font-ui); color: var(--text-faint);
  background: transparent; cursor: pointer; white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-standard), background var(--dur-fast) var(--ease-standard);
}
.seg button.active { font-weight: 600; color: var(--text); background: var(--surface-control-active); }

/* 숫자 입력 — DS forms/NumberInput (인셋 필드 + 라벨 + 단위 칩) */
.imp-fields { display: flex; gap: 8px; }
.ninput {
  flex: 1; display: inline-flex; align-items: center; height: 28px;
  background: var(--surface-inset); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden;
}
.ninput .nlabel {
  padding: 0 8px; align-self: stretch; display: flex; align-items: center;
  font: 500 11px var(--font-ui); color: var(--text-faint);
  border-right: 1px solid var(--border-subtle);
}
.ninput input {
  flex: 1; width: 100%; min-width: 36px; height: 100%; padding: 0 8px;
  background: transparent; border: none; outline: none;
  color: var(--text); font: 500 12px var(--font-mono);
}
.ninput .nunit {
  padding: 0 8px; font: 500 10px var(--font-ui); color: var(--text-faint);
  text-transform: uppercase; letter-spacing: var(--tracking-caps);
}
.ninput:focus-within { border-color: var(--accent); }

/* 아이콘 공통 (ui.js icon() + 정적 SVG) */
.icon { width: 15px; height: 15px; display: block; flex-shrink: 0; }

/* ===== 다크 스크롤바 ===== */
.panel-body::-webkit-scrollbar, #stage-scroll::-webkit-scrollbar, #right-sections::-webkit-scrollbar { width: 10px; height: 10px; }
.panel-body::-webkit-scrollbar-thumb, #stage-scroll::-webkit-scrollbar-thumb, #right-sections::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box;
}
.panel-body::-webkit-scrollbar-thumb:hover, #stage-scroll::-webkit-scrollbar-thumb:hover, #right-sections::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); }
::-webkit-scrollbar-track { background: transparent; }

/* 팔레트 추출 다이얼로그 — 임계 슬라이더 + 추출 칩 */
.quant-range { width: 100%; accent-color: var(--accent); }
.quant-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.quant-chip {
  width: 18px; height: 18px; border-radius: var(--radius-xs);
  border: 1px solid var(--border);
}

/* 양자화 다이얼로그 — 전/후 비교 미리보기 */
.quant-compare { display: flex; gap: 8px; }
.quant-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.quant-pane .imp-preview { width: 100%; }
