:root {
  --page-bg: linear-gradient(180deg, #d9c6ef 0%, #f3c9e2 50%, #c2ddf7 100%);
  --border: #ecd3ef;
  --surface: #fffbfd;
  --sunken: #f6ecf9;
  --text: #33265c;
  --text-muted: #7c699f;
  --accent: #5b3aa0;
  --accent-contrast: #ffffff;
  --accent-yellow: #ffedb0;
  --accent-pink: #ffb3d9;
  --accent-mint: #a6e8cf;
  --accent-blue: #a9d3f5;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --shadow-card: 0 1px 3px rgba(51, 38, 92, 0.08);
  /* 계단식(픽셀) 모서리 클립패스. --pixel(스텝 크기)만 요소별로 지정해서 재사용 */
  --pixel-clip: polygon(
    0 calc(var(--pixel) * 2), var(--pixel) calc(var(--pixel) * 2), var(--pixel) var(--pixel), calc(var(--pixel) * 2) var(--pixel), calc(var(--pixel) * 2) 0,
    calc(100% - var(--pixel) * 2) 0, calc(100% - var(--pixel) * 2) var(--pixel), calc(100% - var(--pixel)) var(--pixel), calc(100% - var(--pixel)) calc(var(--pixel) * 2), 100% calc(var(--pixel) * 2),
    100% calc(100% - var(--pixel) * 2), calc(100% - var(--pixel)) calc(100% - var(--pixel) * 2), calc(100% - var(--pixel)) calc(100% - var(--pixel)), calc(100% - var(--pixel) * 2) calc(100% - var(--pixel)), calc(100% - var(--pixel) * 2) 100%,
    calc(var(--pixel) * 2) 100%, calc(var(--pixel) * 2) calc(100% - var(--pixel)), var(--pixel) calc(100% - var(--pixel)), var(--pixel) calc(100% - var(--pixel) * 2), 0 calc(100% - var(--pixel) * 2)
  );
}

* { box-sizing: border-box; }

/* Safari/WebKit는 한 font-family 안에서 font-stretch로 여러 폭(normal/condensed)을
   구분해 매칭하는 걸 안정적으로 못해서 엉뚱한 굵기의 글자를 보여줌 - 아예 콘덴스드
   전용 파일을 별도 이름으로 등록해서 매칭 자체를 없앰 (모든 브라우저 동일하게 렌더링) */
@font-face {
  font-family: "Galmuri11Condensed";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('https://cdn.jsdelivr.net/npm/galmuri@latest/dist/Galmuri11-Condensed.woff2') format('woff2'),
       url('https://cdn.jsdelivr.net/npm/galmuri@latest/dist/Galmuri11-Condensed.ttf') format('truetype');
}

button, input, select, textarea {
  font-family: inherit;
}

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: "Galmuri11Condensed", "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: var(--text);
  background: var(--page-bg);
  background-attachment: fixed;
}

/* 갈무리는 한글/영문만 지원해서 일본어는 전용 픽셀 폰트로 대체 (font-family는 상속되지만
   body에 이미 지정된 값이 있어 :lang()으로 body 자신에 직접 다시 지정해야 적용됨) */
body:lang(ja) {
  font-family: "DotGothic16", "Noto Sans KR", sans-serif;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
}

.topbar {
  grid-row: 1;
  display: flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar .logo { height: 28px; width: 28px; display: block; }
.topbar .title { font-weight: 800; font-size: 17.5px; letter-spacing: -0.01em; }
.topbar-actions { display: flex; gap: 6px; margin-left: 16px; }
.canvas-controls { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.mode-toggle-btn {
  --pixel: 3px;
  padding: 6px 12px; border-radius: 0; clip-path: var(--pixel-clip);
  border: 1.5px solid var(--accent); background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.mode-toggle-btn:hover { background: var(--sunken); }
.mode-toggle-btn.panning { background: var(--accent-yellow); color: var(--text); border-color: var(--accent-yellow); }
.lang-select {
  --pixel: 3px;
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  height: 32px;
  padding: 6px 22px 6px 10px; border-radius: 0; clip-path: var(--pixel-clip);
  border: 1.5px solid var(--accent); color: var(--accent);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%235b3aa0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 8px center;
  background-size: 10px 6px;
  font-family: inherit; font-size: 14px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.lang-select:hover { background-color: var(--sunken); }
.lang-select-mobile { display: none; width: 100%; }
.icon-btn {
  --pixel: 3px;
  width: 30px; height: 30px; padding: 0; border-radius: 0; clip-path: var(--pixel-clip);
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 17.5px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--sunken); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn:disabled:hover { background: var(--surface); }

.sidebar-toggle-btn { display: none; }
.sidebar-toggle-btn.icon-btn {
  background: var(--accent); border-color: var(--accent); color: var(--accent-contrast);
}
.sidebar-toggle-btn.icon-btn:hover { background: #2b2926; }
.sidebar-backdrop { display: none; }

.body {
  grid-row: 2;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 0; /* 없으면 자식 스크롤이 동작하지 않음 */
  position: relative;
}

.sidebar {
  overflow-y: auto;
  padding: 14px;
  border-right: 1px solid var(--border);
  background: transparent;
  display: flex; flex-direction: column; gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar::-webkit-scrollbar { width: 20px; }
.sidebar::-webkit-scrollbar-track { background: var(--surface); border: 2px solid var(--border); }
.sidebar::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 0; border: 4px solid var(--surface); background-clip: padding-box;
}

.panel {
  --pixel: 6px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 0;
  clip-path: var(--pixel-clip);
  padding: 16px;
}

.panel h2 {
  font-size: 14px; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.03em; color: var(--text-muted);
  margin: 0 0 10px;
}

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 14px; font-weight: 600; }
.field-unit { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); }
.field input[type="number"],
.field textarea,
.field select {
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 0;
  font-size: 14.5px; background-color: var(--sunken); font-family: inherit; color: var(--text);
}
.field select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2333265c' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px 6px;
}
.field textarea { resize: vertical; min-height: 44px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.file-picker { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
label.file-picker-btn {
  --pixel: 4px;
  display: inline-block; padding: 7px 14px;
  border: 1.5px solid var(--accent); border-radius: 0; clip-path: var(--pixel-clip);
  background: var(--accent); color: var(--accent-contrast);
  font-weight: 700; font-size: 14.5px; cursor: pointer; white-space: nowrap;
}
label.file-picker-btn:hover { background: var(--surface); color: var(--accent); }
.file-picker-filename {
  font-size: 13px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.field input[type="number"] {
  -moz-appearance: textfield; /* Firefox: 증감 스피너 숨김 */
}
.field input[type="number"]::-webkit-inner-spin-button,
.field input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none; margin: 0; /* Chrome/Safari: 증감 스피너 숨김 */
}
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.field input[type="color"] { width: 100%; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 0; }

.color-row { display: flex; align-items: center; gap: 8px; }
.color-row input[type="color"] {
  flex: 1; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 0;
}

input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 0; }
input[type="color"]::-moz-color-swatch { border: none; border-radius: 0; }
.icon-toggle-btn {
  --pixel: 3px;
  width: 34px; height: 34px; flex-shrink: 0; padding: 0; border-radius: 0; clip-path: var(--pixel-clip);
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 17.5px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-toggle-btn:hover { background: var(--sunken); }
.icon-toggle-btn.active { border-color: var(--accent-yellow); background: var(--accent-yellow); }
#eraserBtn { width: auto; padding: 0 12px; font-size: 14px; font-weight: 700; white-space: nowrap; }

.range-with-number { display: flex; align-items: center; gap: 8px; }
.range-with-number input[type="range"] { flex: 1; }
.dim-number { width: 56px; flex-shrink: 0; text-align: center; }

.field-row { display: flex; gap: 8px; }
.field-row .field { flex: 1; }
.field-row .btn { flex: 1; }

.checkbox-field {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  margin-bottom: 10px;
}
.checkbox-field input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 36px; height: 20px; flex-shrink: 0;
  background: var(--surface); border: 2px solid var(--border); border-radius: 0;
  position: relative; cursor: pointer; margin: 0;
  transition: border-color 0.15s ease;
}
.checkbox-field input[type="checkbox"]::before {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 12px; height: 12px; border-radius: 0;
  background: var(--border);
  transition: transform 0.15s ease, background 0.15s ease;
}
.checkbox-field input[type="checkbox"]:checked { border-color: var(--accent-mint); }
.checkbox-field input[type="checkbox"]:checked::before { transform: translateX(16px); background: var(--accent-mint); }

.used-colors {
  display: flex; flex-direction: column; gap: 4px;
  max-height: 220px; overflow-y: auto;
}
.used-colors .empty-note { font-size: 13px; color: var(--text-muted); }
.used-color-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 7px; border-radius: var(--radius-md); border: 1.5px solid transparent;
  background: var(--sunken); cursor: pointer; width: 100%; text-align: left;
  font-size: 14px;
}
.used-color-row:hover { background: var(--border); }
.used-color-row.selected { border-color: var(--accent); background: var(--surface); }
.used-color-row .swatch {
  width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.15);
}
.used-color-row .hex { flex: 1; }
.used-color-row .pct { color: var(--text-muted); font-variant-numeric: tabular-nums; }

.btn {
  --pixel: 4px;
  padding: 9px 14px; border: 1.5px solid var(--accent); border-radius: 0; clip-path: var(--pixel-clip);
  background: var(--surface); color: var(--text); font-size: 14.5px; font-weight: 700; cursor: pointer;
  width: 100%; margin-top: 6px;
}
.btn:hover { background: var(--sunken); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); }
.btn-primary {
  background: var(--accent); color: var(--accent-contrast); border-color: var(--accent);
}
.btn-primary:hover { background: var(--surface); color: var(--accent); }

.canvas-panel {
  position: relative;
  min-height: 0;
  min-width: 0; /* 없으면 확대된 캔버스 내용만큼 이 칸 자체가 옆으로 늘어나 가로 스크롤이 생기지 않음 */
}

.zoom-btn {
  --pixel: 2px;
  width: 24px; height: 24px; padding: 0; border-radius: 0; clip-path: var(--pixel-clip);
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 16.5px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.zoom-btn:hover { background: var(--sunken); }
#zoomLabel { font-size: 14px; font-weight: 700; min-width: 36px; text-align: center; }

.canvas-area {
  height: 100%;
  overflow: auto;
  scrollbar-width: auto;
  scrollbar-color: var(--accent-mint) transparent;
  padding: 24px;
  display: flex;
  background: transparent;
  /* align-items/justify-content: center 대신 자식에 margin: auto를 써서 중앙 정렬함.
     center 정렬은 내용이 컨테이너보다 커지면 시작 지점이 음수로 계산돼 위/왼쪽이
     스크롤로 닿지 않는 flexbox 버그가 있음 - margin: auto는 넘칠 때 0으로 수렴해 항상 끝까지 스크롤 가능 */
}
.canvas-area::-webkit-scrollbar { width: 20px; height: 20px; }
.canvas-area::-webkit-scrollbar-track { background: var(--surface); border: 2px solid var(--accent-mint); }
.canvas-area::-webkit-scrollbar-thumb {
  background: var(--accent-mint); border-radius: 0; border: 4px solid var(--surface); background-clip: padding-box;
}
.canvas-area::-webkit-scrollbar-corner { background: var(--surface); }

.placeholder {
  color: var(--text-muted); font-size: 15.5px; text-align: center;
  margin: auto;
}

.site-footer {
  grid-row: 3;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px 16px; flex-wrap: wrap;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: transparent;
  font-size: 12px; color: var(--text-muted);
  flex-shrink: 0;
}
.site-footer-brand { display: flex; align-items: center; gap: 6px; font-weight: 700; color: var(--text); }
.site-footer-brand img { display: block; }
.site-footer-links { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.site-footer-links a { color: var(--text-muted); text-decoration: none; }
.site-footer-links a:hover { color: var(--accent); text-decoration: underline; }

.doc-page {
  max-width: 640px; margin: 0 auto; padding: 40px 20px 60px;
  color: var(--text); line-height: 1.7; font-size: 14.5px;
}
.doc-page-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
.doc-page .back-link { color: var(--accent); font-weight: 700; text-decoration: none; }
.doc-page .back-link:hover { text-decoration: underline; }
.doc-page h1 { font-size: 22px; margin: 0 0 6px; }
.doc-page .effective-date { color: var(--text-muted); font-size: 13px; margin: 0 0 28px; }
.doc-page h2 { font-size: 16.5px; margin: 28px 0 8px; }
.doc-page p, .doc-page li { margin: 0 0 10px; }
.doc-page ul { padding-left: 20px; }
.doc-page a { color: var(--accent); }
.doc-page a.btn-primary { display: block; color: var(--accent-contrast); text-align: center; text-decoration: none; }

.canvas-wrap {
  position: relative;
  margin: auto;
  box-shadow: var(--shadow-card);
}
.canvas-wrap canvas {
  position: absolute; top: 0; left: 0;
  image-rendering: pixelated;
}
#baseCanvas { pointer-events: none; }
#overlayCanvas { cursor: crosshair; touch-action: none; }
.ruler { image-rendering: auto; pointer-events: none; }

.modal {
  position: fixed; inset: 0; background: rgba(23, 20, 18, 0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal[hidden] { display: none; }
.modal-box {
  --pixel: 6px;
  background: var(--surface); border: 2px solid var(--border); border-radius: 0; clip-path: var(--pixel-clip);
  padding: 20px 24px;
  min-width: 260px;
  max-width: 90vw;
}
.modal-box p { margin: 0 0 14px; font-size: 15.5px; }

/* ===== 모바일 (좁은 화면): 사이드바를 오버레이 드로어로 전환 ===== */
@media (max-width: 760px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .topbar .title { font-size: 15.5px; }

  .sidebar-toggle-btn { display: flex; }

  /* 좁은 화면에선 헤더가 이미 꽉 차서 언어 토글을 햄버거 메뉴(사이드바) 맨 아래로 이동 */
  .lang-select-desktop { display: none; }
  .lang-select-mobile { display: block; }

  .body { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: 56px; left: 0; bottom: 0;
    width: min(85vw, 320px);
    z-index: 90;
    background: var(--sunken);
    box-shadow: 2px 0 12px rgba(23, 20, 18, 0.15);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    top: 56px; left: 0; right: 0; bottom: 0;
    background: rgba(23, 20, 18, 0.4);
    z-index: 80;
  }

  /* 터치 조작을 위해 버튼 히트 영역 확대 */
  .icon-btn, .zoom-btn { width: 38px; height: 38px; font-size: 20px; }
  .icon-toggle-btn { width: 40px; height: 40px; }
  .used-color-row { padding: 8px 7px; }

  .canvas-area { padding: 12px; }

  /* 좁은 화면에서 탑바가 넘치지 않도록 축약 */
  .topbar .title { display: none; }
  .topbar-actions { margin-left: 0; }
  .mode-toggle-btn { padding: 6px 8px; font-size: 12.5px; }
  #zoomLabel { min-width: 30px; font-size: 12.5px; }
}

/* 바늘+실 커스텀 커서 - #app(실제 도안 툴) 안에서만 네이티브 커서를 숨김.
   privacy.html/terms.html처럼 #app이 없고 cursor.js를 안 불러오는 페이지는
   대체 커서가 없으므로 이 규칙 대상에서 제외해 마우스 포인터가 사라지지 않게 함. */
#app, #app * { cursor: none !important; }
#app input, #app textarea, #app select { cursor: auto !important; }

#needleCursor, #eraserCursor {
  position: fixed; top: 0; left: 0;
  pointer-events: none; z-index: 99999;
  will-change: transform;
}

@media (max-width: 420px) {
  /* 탑바 컨트롤이 많아서 아주 좁은 화면에서는 로고와 여백을 더 줄여야 가로 스크롤이 안 생김 */
  .topbar { padding: 0 8px; gap: 6px; }
  .topbar .logo { display: none; }
  .topbar-actions { gap: 4px; margin-left: 0; }
  .canvas-controls { gap: 4px; }
  .icon-btn, .zoom-btn { width: 32px; height: 32px; font-size: 16.5px; }
  .mode-toggle-btn { padding: 6px 8px; font-size: 12px; }
  #zoomLabel { min-width: 26px; font-size: 12px; }
}
