/* PatternDigitizerMini — 편집 화면 스타일 (밝은 디자인 툴 스타일)
   원칙
   1) #viewport 안쪽에는 border·padding·transform을 주지 않는다. (pdm-app.js가 viewport의
      getBoundingClientRect 기준으로 포인터 → 사진 좌표를 계산하므로, 테두리가 생기면 클릭 위치가 어긋난다.)
      테두리처럼 보이는 표시는 pointer-events:none인 #viewport::after로만 그린다.
   2) #world / #photo / #overlay의 위치·크기 규칙은 원본과 동일하게 둔다. (#world에는 레이아웃에 영향 없는 그림자만 추가)
   3) JS가 class를 통째로 바꾸는 요소(#status, #scaleBadge, #exportReason)는 그 class만으로 스타일링하고,
      화면 전체의 진행 상태는 CSS :has()로 기존 DOM 상태(aria-pressed, disabled, hidden)를 읽어 표시한다.
   4) 색 의미: 보라 = 주요 동작·현재 도구, 주황 = 축척·주의, 초록 = 저장 가능, 빨강 = 오류.
      색만으로 구분하지 않도록 글자·기호·굵기·막대 표시를 함께 쓴다. */

:root {
  --header-h: 60px;
  --rail-w: 84px;
  --side-w: 300px;

  /* 바탕: 흰 패널 + 연회색 작업대 */
  --canvas: #eceef3;
  --canvas-dot: #d6dae3;
  --surface: #ffffff;
  --surface-2: #f6f7fa;
  --surface-3: #eef0f5;
  --panel-bg: #f7f8fb;
  --line: #e8eaf0;
  --line-strong: #d4d8e1;
  --text: #1d2129;
  --text-2: #4b5260;
  --muted: #8b92a0;

  /* 포인트 */
  --primary: #6a4cff;
  --primary-hover: #5a3cf0;
  --primary-soft: #f0ecff;
  --primary-line: #c9bdff;
  --ruler: #f08c00;
  --ruler-soft: #fff4e2;
  --ok: #10b47c;
  --ok-soft: #e7f8f1;
  --err: #f03e3e;
  --err-soft: #fff0f0;
  --warn: #f59f00;
  --warn-soft: #fff6e0;

  /* 사진 위 오버레이 색 — 기본: 초록 커팅매트·어두운 배경 + 흰 종이 경계에서 모두 보이는 채도 높은 색 */
  --ov-outline: #ff2e88;
  --ov-select: #2b95ff;
  --ov-ruler: #ffd21a;
  --ov-ruler-new: #6ff1ff;
  --ov-handle: #ff9900;
  --ov-label: #ffffff;
  --ov-halo: rgba(0, 0, 0, .86);

  --radius: 10px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(25, 30, 50, .06);
  --shadow-md: 0 6px 20px rgba(25, 30, 50, .08), 0 1px 3px rgba(25, 30, 50, .06);
  --shadow-photo: 0 10px 34px rgba(25, 30, 55, .20), 0 2px 6px rgba(25, 30, 55, .10);
  --font: "Pretendard Variable", Pretendard, "SUIT Variable", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "D2Coding", monospace;
}

/* 밝은 사진(흰 종이·밝은 바닥)용 진한 오버레이 색. 상태바의 "선 색" 링크가 #tone-light를 :target으로 만든다. */
body:has(#tone-light:target) {
  --ov-outline: #d4006e;
  --ov-select: #0047d1;
  --ov-ruler: #9a5c00;
  --ov-ruler-new: #006d8c;
  --ov-handle: #c24400;
}

/* ───────── 기본 ───────── */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--header-h) minmax(0, 1fr);
  background: var(--canvas);
  color: var(--text);
  font: 13.5px/1.5 var(--font);
  letter-spacing: -.01em;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; letter-spacing: inherit; }
h1, h2, p { margin: 0; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  color: var(--text-2);
  font: 600 10.5px/1 var(--mono);
  letter-spacing: 0;
  white-space: nowrap;
  vertical-align: 1px;
}

button, .download-link, .empty-open, .tone-opt {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background-color .12s, border-color .12s, color .12s, box-shadow .12s;
}
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 13px;
  font-weight: 600;
}
button:hover:not(:disabled), .download-link:hover, .tone-opt:hover { background: var(--surface-2); border-color: #bfc5d0; }
button:active:not(:disabled) { transform: translateY(1px); }
/* 비활성: 흐림 + 점선 테두리(색 이외의 단서) */
button:disabled { opacity: .45; cursor: not-allowed; border-style: dashed; }
:is(button, a, summary, input, label.empty-open):focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ───────── 머리글 ───────── */
.app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 2;
}
.brand-block { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 160px; }
.brand-mark { flex: none; display: block; width: 34px; height: 34px; border-radius: 9px; box-shadow: 0 3px 10px rgba(106, 76, 255, .3); }
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 14px; font-weight: 800; line-height: 1.25; letter-spacing: -.02em; }
#fileLabel { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
body:has(#emptyState[hidden]) #fileLabel { color: var(--text-2); }

.history-actions { display: flex; gap: 2px; padding-left: 12px; border-left: 1px solid var(--line); flex: none; }
.ghost-btn { border-color: transparent; background: transparent; padding: 0 10px; color: var(--text-2); }
.ghost-btn:hover:not(:disabled) { background: var(--surface-3); border-color: transparent; color: var(--text); }
.ghost-btn:disabled { border-color: transparent; }
.ghost-btn kbd { margin-left: 2px; }

/* 작업 순서 (상태는 DOM에서 읽음, 클릭 동작 없음) */
.flow { display: flex; align-items: center; gap: 2px; margin: 0 auto; padding: 4px; list-style: none; flex: 0 1 auto; min-width: 0; background: var(--surface-2); border-radius: 999px; }
.flow-step {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px 0 5px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.flow-step kbd { height: 16px; min-width: 16px; padding: 0 3px; font-size: 10px; margin-left: -2px; }
.flow-num {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--muted);
  font: 800 11px/1 var(--font);
}
/* 완료: 숫자 대신 ✓ */
body:has(#emptyState[hidden]) .step-photo .flow-num,
body:has(#scaleBadge:not(.muted)) .step-scale .flow-num,
body:has(#exportDxfBtn:not(:disabled)) .step-outline .flow-num { font-size: 0; background: var(--ok); }
body:has(#emptyState[hidden]) .step-photo .flow-num::after,
body:has(#scaleBadge:not(.muted)) .step-scale .flow-num::after,
body:has(#exportDxfBtn:not(:disabled)) .step-outline .flow-num::after { content: "✓"; font-size: 12px; color: #fff; }
body:has(#emptyState[hidden]) .step-photo,
body:has(#scaleBadge:not(.muted)) .step-scale,
body:has(#exportDxfBtn:not(:disabled)) .step-outline { color: var(--text-2); }
/* 지금 할 단계: 가장 앞의 미완료 단계 */
body:not(:has(#emptyState[hidden])) .step-photo,
body:has(#emptyState[hidden]):has(#scaleBadge.muted) .step-scale,
body:has(#scaleBadge:not(.muted)):has(#exportDxfBtn:disabled) .step-outline,
body:has(#exportDxfBtn:not(:disabled)) .step-export {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--primary-line);
}
body:not(:has(#emptyState[hidden])) .step-photo .flow-num,
body:has(#emptyState[hidden]):has(#scaleBadge.muted) .step-scale .flow-num,
body:has(#scaleBadge:not(.muted)):has(#exportDxfBtn:disabled) .step-outline .flow-num,
body:has(#exportDxfBtn:not(:disabled)) .step-export .flow-num { background: var(--primary); color: #fff; }

.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex: 0 0 auto; }
#openImageBtn { border-color: var(--primary-line); color: var(--primary); }
#openImageBtn:hover { background: var(--primary-soft); border-color: var(--primary); }
/* 다음에 눌러야 할 버튼만 채운 보라색 */
body:not(:has(#emptyState[hidden])) #openImageBtn,
#exportDxfBtn:not(:disabled) { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(106, 76, 255, .28); }
body:not(:has(#emptyState[hidden])) #openImageBtn:hover,
#exportDxfBtn:not(:disabled):hover { background: var(--primary-hover); border-color: var(--primary-hover); }
#exportDxfBtn:disabled { background: var(--surface-2); }

/* ───────── 본문 3열 ───────── */
.app-main { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--side-w); min-height: 0; min-width: 0; }

/* 도구 레일: 아이콘 타일 */
.tool-rail {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  padding: 10px 8px 12px;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.rail-group { display: flex; flex-direction: column; gap: 4px; }
.rail-group + .rail-group { padding-top: 8px; border-top: 1px solid var(--line); }
.rail-label { color: var(--muted); font-size: 10.5px; font-weight: 700; text-align: center; letter-spacing: -.02em; }
.tile {
  position: relative;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  min-height: 56px;
  padding: 7px 3px 6px;
  border-color: transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  word-break: keep-all;
}
.tile .icon { width: 21px; height: 21px; }
.tile:hover:not(:disabled) { background: var(--surface-3); border-color: transparent; color: var(--text); }
.tile:disabled { border-color: transparent; }
.tile kbd { height: 15px; min-width: 15px; padding: 0 3px; font-size: 9.5px; border-bottom-width: 1px; }
.mode-btn { min-height: 62px; font-size: 12px; }
.mode-btn .icon { width: 23px; height: 23px; }
.mode-btn kbd { position: absolute; top: 5px; right: 5px; }
/* 현재 도구: 보라 배경 + 왼쪽 막대 + 채운 단축키 */
.mode-btn[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); font-weight: 800; }
.mode-btn[aria-pressed="true"]:hover:not(:disabled) { background: #e7e0ff; color: var(--primary); }
.mode-btn[aria-pressed="true"] kbd { background: var(--primary); border-color: var(--primary); color: #fff; }

/* 작업 영역 */
.stage { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-width: 0; min-height: 0; }
#viewport {
  position: relative;
  overflow: hidden;
  min-height: 0;
  background-color: var(--canvas);
  background-image: radial-gradient(var(--canvas-dot) 1px, transparent 1.2px);
  background-size: 20px 20px;
  touch-action: none;
  cursor: crosshair;
  outline: none;
}
#viewport::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 0 transparent; }
#viewport:focus-visible::after { box-shadow: inset 0 0 0 1px rgba(106, 76, 255, .3); }
body:has(#emptyState[hidden]):has(#rulerMode[aria-pressed="true"]) #viewport::after { box-shadow: inset 0 0 0 3px var(--ruler); }
#viewport.dragover::after { box-shadow: inset 0 0 0 3px var(--primary); }
body:has(#editMode[aria-pressed="true"]) #viewport { cursor: default; }
#viewport.panning { cursor: grabbing; }

/* ↓ 좌표 정합 관련 규칙: 원본과 동일하게 유지 */
#world { position: absolute; left: 0; top: 0; display: none; transform-origin: 0 0; }
#photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; image-orientation: from-image; pointer-events: none; user-select: none; }
#overlay { position: absolute; inset: 0; overflow: visible; }
/* ↑ */
#world { box-shadow: var(--shadow-photo); } /* 그림자는 레이아웃·좌표에 영향 없음 */

/* 오버레이 (선 두께는 확대와 무관하게 화면 기준) */
.trace { fill: none; stroke: var(--ov-outline); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linecap: round; stroke-linejoin: round; }
.trace.selected { stroke: var(--ov-select); stroke-width: 3.2; }
.trace.preview { stroke: var(--ov-outline); stroke-width: 1.6; stroke-dasharray: 6 5; opacity: .92; }
.hit { fill: none; stroke: transparent; stroke-width: 15; vector-effect: non-scaling-stroke; pointer-events: stroke; cursor: pointer; }
.marker-ring, .marker-cross { fill: none; stroke: var(--ov-outline); vector-effect: non-scaling-stroke; }
.curve-handle { fill: none; stroke: var(--ov-handle); vector-effect: non-scaling-stroke; }
.curve-handle + .marker-cross { stroke: var(--ov-handle); }
.marker-ring.selected, .marker-cross.selected, .curve-handle.selected, .curve-handle.selected + .marker-cross { stroke: var(--ov-select); }
.handle-guide { stroke: var(--ov-handle); stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; opacity: .8; }
.point-hit, .handle-hit, .ruler-hit { fill: transparent; stroke: transparent; pointer-events: all; cursor: move; }
.point-label, .ruler-label { fill: var(--ov-label); stroke: var(--ov-halo); paint-order: stroke; pointer-events: none; font-weight: 700; font-family: var(--font); }
.pending-end { fill: none; stroke: var(--ov-outline); vector-effect: non-scaling-stroke; }
.ruler-line { fill: none; stroke: var(--ov-ruler); stroke-width: 2; stroke-dasharray: 10 5; vector-effect: non-scaling-stroke; }
.ruler-line.candidate { stroke: var(--ov-ruler-new); stroke-dasharray: 4 4; }
.ruler-ring { fill: none; stroke: var(--ov-ruler); vector-effect: non-scaling-stroke; }
.ruler-ring.candidate { stroke: var(--ov-ruler-new); }
.ruler-cross { fill: none; stroke: var(--ov-ruler); vector-effect: non-scaling-stroke; }
.ruler-cross.candidate { stroke: var(--ov-ruler-new); }

/* 빈 화면 */
#emptyState { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; pointer-events: none; }
.empty-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 430px;
  padding: 32px 32px 24px;
  border: 2px dashed var(--line-strong);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  color: var(--text-2);
  text-align: center;
}
.empty-icon { display: grid; place-items: center; width: 54px; height: 54px; margin-bottom: 4px; border-radius: 16px; background: var(--primary-soft); color: var(--primary); }
.empty-icon .icon { width: 28px; height: 28px; }
.empty-card strong { color: var(--text); font-size: 19px; font-weight: 800; letter-spacing: -.03em; }
.empty-open {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  margin: 6px 0 8px;
  padding: 0 26px;
  border-color: var(--primary);
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(106, 76, 255, .3);
}
.empty-open:hover { background: var(--primary-hover); }
.empty-tip, .empty-privacy { font-size: 12px; color: var(--muted); }
.empty-privacy { padding-top: 10px; border-top: 1px solid var(--line); }
#viewport.dragover .empty-card { border-color: var(--primary); background: var(--primary-soft); }

/* 상태 표시줄 */
.statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 44px;
  padding: 5px 10px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.mode-pill {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px 0 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.mode-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--mode-dot, var(--primary)); }
.mode-pill::after { content: "직선 · L"; }
body:not(:has(#emptyState[hidden])) .mode-pill { display: none; }
body:has(#rulerMode[aria-pressed="true"]) .mode-pill { background: var(--ruler-soft); color: #b06200; --mode-dot: var(--ruler); }
body:has(#rulerMode[aria-pressed="true"]) .mode-pill::after { content: "축척 지정 · R"; }
body:has(#curveMode[aria-pressed="true"]) .mode-pill::after { content: "곡선 · C"; }
body:has(#editMode[aria-pressed="true"]) .mode-pill::after { content: "편집 · E"; }
body:has(#measureMode[aria-pressed="true"]) .mode-pill::after { content: "거리 재기 · M"; }
body:has(#viewport[data-mode="fold"]) .mode-pill { background: #e6fbf3; color: #08714e; --mode-dot: #10b47c; }
body:has(#viewport[data-mode="fold"]) .mode-pill::after { content: "접힘선 찍기 · Enter 완료"; }

#status { flex: 1 1 auto; min-width: 0; padding: 4px 10px; border-radius: 8px; color: var(--text-2); font-size: 13px; }
#status.pending { background: var(--warn-soft); color: #8a5800; }
#status.error { background: var(--err-soft); color: #c42b2b; }
#status.pending::before, #status.error::before {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-right: 7px;
  border-radius: 50%;
  font: 800 11px/1 var(--mono);
  vertical-align: -2px;
  color: #fff;
}
#status.pending::before { content: "…"; background: var(--warn); }
#status.error::before { content: "!"; background: var(--err); }

.download-link {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 260px;
  height: 30px;
  padding: 0 11px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  line-height: 28px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}
.download-link::before { content: "↓ "; color: var(--ok); font-weight: 800; }

.tone-switch, .zoom-tools { flex: none; display: flex; align-items: center; gap: 2px; }
.tone-switch { padding: 3px; border-radius: 10px; background: var(--surface-2); }
.tone-label { margin: 0 4px 0 6px; color: var(--muted); font-size: 11.5px; font-weight: 600; }
.tone-opt { height: 26px; padding: 0 9px; line-height: 24px; font-size: 12px; font-weight: 600; color: var(--muted); border-color: transparent; background: transparent; }
body:not(:has(#tone-light:target)) .tone-opt-std,
body:has(#tone-light:target) .tone-opt-light { background: var(--surface); border-color: var(--line); color: var(--text); box-shadow: var(--shadow-sm); }
body:not(:has(#tone-light:target)) .tone-opt-std::before,
body:has(#tone-light:target) .tone-opt-light::before { content: "✓ "; color: var(--primary); }
.zoom-tools { padding: 3px; border-radius: 10px; background: var(--surface-2); }
.zoom-tools button { min-height: 28px; height: 28px; padding: 0 10px; border-color: transparent; background: transparent; font-size: 12.5px; }
.zoom-tools button:hover:not(:disabled) { background: var(--surface); border-color: var(--line); }
#zoomOutBtn, #zoomInBtn { width: 30px; padding: 0; font-size: 16px; }
#zoomLabel { width: 46px; text-align: center; color: var(--text); font: 700 12px/1 var(--mono); font-variant-numeric: tabular-nums; }

/* ───────── 정보 패널: 흰 카드 ───────── */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding: 12px;
  overflow-y: auto;
  background: var(--panel-bg);
  border-left: 1px solid var(--line);
}
.card { padding: 13px 14px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-sm); }
.card h2 { display: flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 800; letter-spacing: -.02em; }
.card h2 small { color: var(--muted); font-size: 11px; font-weight: 600; }
.card h2 .icon { color: var(--primary); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.card-selection h2 { margin-bottom: 4px; }
.step-tag { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 7px; background: var(--surface-3); color: var(--muted); font: 800 11px/1 var(--font); }
.section-copy, .card-note { color: var(--muted); font-size: 12px; }
.card-note { margin-top: 8px; font-size: 11.5px; }
.unit-label { color: var(--muted); font-size: 11.5px; font-weight: 600; }
.help-steps kbd, .shortcut kbd, .section-copy kbd, .card-note kbd { height: 16px; min-width: 16px; padding: 0 4px; font-size: 10px; }
body:has(#scaleBadge:not(.muted)):not(:has(#rulerMode[aria-pressed="true"])) .card-scale .section-copy { display: none; }

/* 축척 배지: JS가 class를 "badge" / "badge muted"로 교체 */
/* JS가 class를 "badge" / "badge muted"로 교체 — 축척 배지(#scaleBadge)와 질감 개수 배지(#textureQueueBadge)가 같은 class를 쓰므로 ID로 나눈다 */
.badge { flex: none; padding: 3px 9px; border-radius: 999px; background: var(--surface-3); color: var(--muted); font-size: 11.5px; font-weight: 700; white-space: nowrap; }
#scaleBadge { background: var(--ok-soft); color: #08875c; }
#scaleBadge::before { content: "✓ "; }
#scaleBadge.muted { background: var(--surface-3); color: var(--muted); }
#scaleBadge.muted::before { content: "○ "; }
body:has(#emptyState[hidden]) #scaleBadge.muted { background: var(--ruler-soft); color: #b06200; }
#textureQueueBadge:not(.muted) { background: var(--primary-soft); color: var(--primary); }

body:has(#emptyState[hidden]):has(#scaleBadge.muted) .card-scale { border-color: #ffd8a1; box-shadow: inset 3px 0 0 var(--ruler), var(--shadow-sm); }
body:has(#rulerMode[aria-pressed="true"]) .card-scale { border-color: #ffc978; background: #fffcf6; box-shadow: inset 3px 0 0 var(--ruler), var(--shadow-md); }
body:has(#emptyState[hidden]):has(#scaleBadge.muted) .card-scale .step-tag,
body:has(#rulerMode[aria-pressed="true"]) .card-scale .step-tag { background: var(--ruler); color: #fff; }

.ruler-editor { margin: 10px 0 2px; padding: 11px; border-radius: 12px; background: var(--ruler-soft); }
.ruler-steps { margin: 0 0 10px; padding-left: 18px; color: var(--text-2); font-size: 12px; }
.ruler-steps li { margin: 1px 0; }
.ruler-steps li::marker { color: var(--ruler); font-weight: 800; }
.ruler-editor label, .field-grid label { display: block; color: var(--text); font-size: 12px; font-weight: 700; }
.ruler-editor label { margin-bottom: 5px; }
.input-row { display: flex; align-items: center; gap: 8px; }
.input-row input, .field-grid input {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: border-color .12s, box-shadow .12s;
}
.input-row input { font: 700 17px/1 var(--mono); }
.input-row input:focus, .field-grid input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(106, 76, 255, .18); }
/* :invalid 표시는 쓰지 않음 — 원본 속성(min 0.001 · step 0.1) 때문에 100·150 같은 정상값도 브라우저가 invalid로 보기 때문. 검사는 앱 메시지로. */
.input-row span { color: var(--text-2); font: 700 13px/1 var(--mono); }
.input-hint { margin-top: 5px; color: #9a6b2a; font-size: 11.5px; }
.button-row { display: flex; gap: 6px; margin-top: 9px; }
.button-row button { flex: 1; min-height: 36px; }
#applyScaleBtn:not(:disabled) { background: var(--primary); border-color: var(--primary); color: #fff; }
#applyScaleBtn:not(:disabled):hover { background: var(--primary-hover); }

.info-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 8px 0 0; font-size: 12.5px; }
.info-grid dt { color: var(--muted); }
.info-grid dd { margin: 0; text-align: right; word-break: break-word; font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; color: var(--text); }

/* 치수 */
.metric-grid { display: flex; flex-direction: column; gap: 4px; margin: 4px 0 10px; }
.metric-grid div { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 7px 11px; border-radius: 10px; background: var(--surface-2); }
.metric-grid dt { color: var(--muted); font-size: 12px; font-weight: 600; }
.metric-grid dd { margin: 0; color: var(--muted); font: 800 17px/1.2 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; white-space: nowrap; }
body:has(#exportDxfBtn:not(:disabled)) .metric-grid div { background: var(--primary-soft); }
body:has(#exportDxfBtn:not(:disabled)) .metric-grid dd { color: var(--text); }

/* DXF 저장 가능 여부: JS가 class를 "inline-message" / "inline-message ready"로 교체 */
.inline-message { display: flex; gap: 7px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); font-size: 12px; }
.inline-message::before {
  content: "!";
  flex: none;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  border-radius: 50%;
  background: var(--muted);
  color: #fff;
  font: 800 11px/1 var(--mono);
}
body:has(#emptyState[hidden]) #exportReason:not(.ready) { background: var(--warn-soft); color: #8a5800; }
body:has(#emptyState[hidden]) #exportReason:not(.ready)::before { background: var(--warn); }
#textureQueueNote:not(.ready)::before { content: "i"; background: var(--primary); }
.inline-message.ready { background: var(--ok-soft); color: #08714e; }
.inline-message.ready::before { content: "✓"; background: var(--ok); }

/* 뒷판 펼침 · 구간 길이 */
.card-unfold > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; font-size: 13.5px; font-weight: 800; letter-spacing: -.02em; }
.card-unfold > summary::-webkit-details-marker { display: none; }
.card-unfold > summary::after { content: "펼치기 ▾"; color: var(--muted); font-size: 11px; font-weight: 600; }
.card-unfold[open] > summary::after { content: "접기 ▴"; }
.card-unfold[open] > summary { margin-bottom: 7px; }
.summary-title { display: inline-flex; align-items: center; gap: 7px; }
.summary-title .icon { color: var(--primary); }
.pair { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 6px; }
.pair span { color: var(--muted); font-size: 12px; }
.pair input, .unfold-table input { width: 100%; min-width: 0; height: 34px; padding: 0 9px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); font: 700 13px/1 var(--mono); font-variant-numeric: tabular-nums; }
.pair input:focus, .unfold-table input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(106, 76, 255, .18); }
.unfold-table { display: grid; grid-template-columns: 1fr; gap: 4px; margin-top: 8px; max-height: 220px; overflow-y: auto; }
.unfold-table:empty { display: none; }
.unfold-table label { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 8px; padding: 3px 4px 3px 9px; border-radius: 8px; background: var(--surface-2); font-size: 12px; font-weight: 700; color: var(--text-2); }
.unfold-table label > span:last-child { color: var(--muted); font: 600 11.5px/1 var(--mono); padding-right: 6px; }
.unfold-table input { height: 30px; }
#unfoldPreviewBtn[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
#unfoldApplyBtn:not(:disabled) { background: var(--primary); border-color: var(--primary); color: #fff; }
#unfoldApplyBtn:not(:disabled):hover { background: var(--primary-hover); }
.unfold-note { margin-top: 8px; padding: 7px 10px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); font-size: 12px; }
.unfold-note.ready { background: var(--ok-soft); color: #08714e; }
.unfold-note.ready::before { content: "✓ "; font-weight: 800; }
.unfold-note.error { background: var(--err-soft); color: #c42b2b; }
.unfold-note.error::before { content: "! "; font-weight: 800; }
.sub-heading.first { margin-top: 10px; }
.field-grid select { width: 100%; min-width: 0; height: 34px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); font: 600 12.5px/1 var(--font); color: var(--text); }
.field-grid select:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(106, 76, 255, .18); }
.field-label { color: var(--text); font-size: 12px; font-weight: 700; }
.check-row { display: flex; align-items: center; gap: 7px; white-space: nowrap; font-size: 12px; font-weight: 600; color: var(--text-2); cursor: pointer; }
.check-row input { width: 16px; height: 16px; accent-color: var(--primary); }
.pair input:disabled { background: var(--surface-2); color: var(--muted); border-style: dashed; }
.profile-list { margin-top: 8px; max-height: 180px; }
#profileDrawBtn:not(:disabled) { border-color: #9ee6c9; background: #e6fbf3; color: #08714e; }
#profileFinishBtn:not(:disabled) { background: #10b47c; border-color: #10b47c; color: #fff; }
.fold-line { fill: none; stroke: #10e08a; stroke-width: 2.4; stroke-dasharray: 8 4; vector-effect: non-scaling-stroke; pointer-events: none; }
.fold-ring { fill: none; stroke: #10e08a; vector-effect: non-scaling-stroke; pointer-events: none; }
.fold-seam { fill: none; stroke: #10e08a; stroke-width: 9; stroke-opacity: .5; stroke-linecap: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.sub-heading { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12.5px; font-weight: 800; letter-spacing: -.02em; }
.measure-row { padding-top: 6px; border-top: 1px dashed var(--line); }
.unfold-tip { margin-top: 10px; padding: 8px 10px; border-radius: 10px; background: var(--warn-soft); color: #7a5414; font-size: 11.5px; line-height: 1.55; }
.unfold-tip summary { cursor: pointer; font-weight: 800; }
.unfold-tip ol { margin: 6px 0 0; padding-left: 17px; }
.unfold-tip li { margin: 3px 0; }
.unfold-tip kbd { height: 16px; min-width: 16px; padding: 0 4px; font-size: 10px; }
/* 사진 위: 펼침 미리보기(보라 점선)·이동 화살·거리 재기 */
.unfold-preview { fill: none; stroke: #8b5cff; stroke-width: 2.2; stroke-dasharray: 7 5; vector-effect: non-scaling-stroke; pointer-events: none; }
.unfold-shift { stroke: #8b5cff; stroke-width: 1.2; vector-effect: non-scaling-stroke; pointer-events: none; opacity: .9; }
.measure-line { stroke: #00d1ff; stroke-width: 2; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; pointer-events: none; }
.measure-ring { fill: none; stroke: #00d1ff; vector-effect: non-scaling-stroke; pointer-events: none; }
.measure-label { fill: #fff; stroke: rgba(0, 0, 0, .86); paint-order: stroke; font-weight: 700; font-family: var(--font); pointer-events: none; }

/* 조각별 질감 사진 (ID·동작은 pdm-app.js / pdm-texture.js 그대로) */
.field-grid { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 7px 10px; margin: 10px 0; }
.field-grid input { height: 36px; font-size: 13px; }
.input-row.compact input { height: 36px; font: 700 14px/1 var(--mono); }
.wide-button { width: 100%; min-height: 40px; }
#addTexturePieceBtn:not(:disabled) { border-color: var(--primary-line); background: var(--primary-soft); color: var(--primary); }
#addTexturePieceBtn:not(:disabled):hover { background: #e7e0ff; border-color: var(--primary); }
.texture-queue { margin: 8px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 5px; max-height: 232px; overflow-y: auto; }
.texture-queue li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 8px 8px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.texture-queue li.empty-row { justify-content: center; padding: 12px; border-style: dashed; background: transparent; color: var(--muted); font-size: 12px; }
.texture-queue li > div { min-width: 0; display: flex; flex-direction: column; }
.texture-queue strong, .texture-queue small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.texture-queue strong { font-size: 12.5px; font-weight: 700; }
.texture-queue small { color: var(--muted); font: 600 11px/1.4 var(--mono); }
.texture-queue button { flex: none; min-height: 28px; padding: 0 9px; font-size: 12px; color: var(--text-2); }
.texture-actions { margin-top: 8px; }
.texture-actions button { min-height: 40px; }
#clearTextureQueueBtn { flex: 0 0 auto; }
#exportTextureZipBtn:not(:disabled) { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(106, 76, 255, .25); }
#exportTextureZipBtn:not(:disabled):hover { background: var(--primary-hover); }
#textureQueueNote { margin-top: 8px; }
.texture-notes { margin: 8px 0 0; padding-left: 16px; color: var(--muted); font-size: 11.5px; line-height: 1.5; }
.texture-notes li { margin: 2px 0; }
.texture-notes code { font: 600 11px/1 var(--mono); color: var(--text-2); }

.warning { margin: 0; padding: 9px 11px; border-radius: 10px; background: var(--warn-soft); color: #7a5414; font-size: 11.5px; line-height: 1.55; }
.card-accuracy { padding: 6px; }

/* 도움말 */
.help summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; font-size: 13.5px; font-weight: 800; }
.help summary::-webkit-details-marker { display: none; }
.help summary::after { content: "펼치기 ▾"; color: var(--muted); font-size: 11px; font-weight: 600; }
.help[open] summary::after { content: "접기 ▴"; }
.help-steps { margin: 9px 0 10px; padding-left: 18px; color: var(--text-2); font-size: 12px; }
.help-steps li { margin: 0 0 5px; }
.shortcut-list { margin: 0; }
.shortcut { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 12px; }
.shortcut dt { color: var(--muted); }
.shortcut dd { margin: 0; text-align: right; color: var(--text-2); }

/* ───────── 화면 크기별 ───────── */
@media (min-width: 1680px) { :root { --side-w: 324px; } }
@media (max-width: 1440px) { .flow-step kbd { display: none; } }
/* 노트북 폭: 순서 표시줄은 지금 단계만 글자로 */
@media (max-width: 1366px) {
  :root { --side-w: 284px; }
  .flow-step .flow-text { display: none; }
  .flow-step { padding: 0 5px; }
  body:not(:has(#emptyState[hidden])) .step-photo .flow-text,
  body:has(#emptyState[hidden]):has(#scaleBadge.muted) .step-scale .flow-text,
  body:has(#scaleBadge:not(.muted)):has(#exportDxfBtn:disabled) .step-outline .flow-text,
  body:has(#exportDxfBtn:not(:disabled)) .step-export .flow-text { display: inline; }
  body:not(:has(#emptyState[hidden])) .step-photo,
  body:has(#emptyState[hidden]):has(#scaleBadge.muted) .step-scale,
  body:has(#scaleBadge:not(.muted)):has(#exportDxfBtn:disabled) .step-outline,
  body:has(#exportDxfBtn:not(:disabled)) .step-export { padding-right: 11px; }
  .tone-label { display: none; }
}
@media (max-width: 1200px) {
  .history-actions .btn-text { display: none; }
  .download-link { max-width: 170px; }
}
@media (max-width: 1080px) {
  .header-actions .ghost-btn .btn-text { display: none; }
  :root { --side-w: 268px; }
}
/* 화면 높이가 낮은 노트북 (1366×768, 1280×720 등) */
@media (max-height: 760px) and (min-width: 901px) {
  :root { --header-h: 54px; }
  .tool-rail { gap: 4px; padding-top: 8px; }
  .tile { min-height: 46px; padding: 4px 3px; }
  .mode-btn { min-height: 50px; }
  .rail-group + .rail-group { padding-top: 6px; }
  .side-panel { gap: 8px; padding: 10px; }
  .metric-grid div { padding: 5px 10px; }
  .metric-grid dd { font-size: 15px; }
  .card { padding: 11px 12px 12px; }
  .statusbar { min-height: 40px; padding: 4px 10px; }
}
@media (max-height: 700px) and (min-width: 901px) {
  .tile:not(.mode-btn) .icon { display: none; }
  .tile:not(.mode-btn) { min-height: 40px; }
  .rail-label { display: none; }
}
/* 태블릿·휴대폰: 세로로 쌓고 페이지 스크롤 (정밀 편집은 데스크톱 기준) */
@media (max-width: 900px) {
  body { display: block; height: auto; min-height: 100%; overflow: auto; }
  .app-header { flex-wrap: wrap; gap: 8px 10px; padding: 10px 12px; }
  .brand-block { flex: 1 1 auto; }
  .flow { order: 3; flex: 1 1 100%; margin: 0; overflow-x: auto; }
  .flow-step .flow-text { display: none; }
  .header-actions { flex: 1 1 100%; justify-content: flex-start; flex-wrap: wrap; }
  .app-main { display: flex; flex-direction: column; }
  .tool-rail { flex-direction: row; gap: 6px; padding: 8px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .rail-group { flex-direction: row; flex: none; }
  .rail-group + .rail-group { padding: 0 0 0 6px; border-top: 0; border-left: 1px solid var(--line); }
  .rail-label { display: none; }
  .tile { width: 70px; flex: none; }
  .stage { height: 68vh; min-height: 340px; }
  .statusbar { flex-wrap: wrap; }
  #status { flex-basis: 100%; order: -1; }
  .side-panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
}
@media (max-width: 520px) {
  .tone-switch, .history-actions .btn-text { display: none; }
  .header-actions button { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
