:root {
  --bg: #f5f4fa;
  --card: #ffffff;
  --card-2: #f0eef8;
  --text: #1d1a2e;
  --muted: #6d6884;
  --line: #e4e1ef;
  --accent: #7c5cff;
  --accent-2: #ff6b8a;
  --accent-soft: #efeaff;
  --ok: #18a058;
  --warn: #e8a400;
  --bad: #e5484d;
  --shadow: 0 1px 2px rgba(20, 10, 60, 0.06), 0 6px 24px rgba(20, 10, 60, 0.06);
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Pretendard', 'Malgun Gothic', 'Noto Sans KR', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0e17;
    --card: #1a1926;
    --card-2: #23212f;
    --text: #f1effa;
    --muted: #a19cb8;
    --line: #2e2b3e;
    --accent: #9b82ff;
    --accent-soft: #2a2442;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; }
.col { display: flex; flex-direction: column; gap: 8px; }
.spacer { flex: 1; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 16px; }

/* 상단 */
header.top { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
header .bar { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; letter-spacing: -0.02em; white-space: nowrap; }
.logo .mark { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center; color: #fff; font-size: 16px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; background: var(--card-2); font-size: 12px; font-weight: 600; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.progress { height: 3px; background: var(--line); }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.2s; }

/* 버튼 */
.btn { border: 1px solid var(--line); background: var(--card); padding: 9px 14px; border-radius: 11px; cursor: pointer; font-weight: 600; white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover { background: var(--card-2); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border: none; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.btn.icon { width: 34px; height: 34px; padding: 0; font-size: 17px; border-radius: 9px; }
.seg { display: inline-flex; background: var(--card-2); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button { border: none; background: none; padding: 6px 11px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* 처음 화면 */
.drop { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 56px 20px; border: 2px dashed color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: 22px; background: var(--card); cursor: pointer; margin-top: 24px; }
.drop.over { background: var(--accent-soft); }
.drop-icon { font-size: 44px; }
.drop b { font-size: 19px; }
.notes { max-width: 640px; margin: 24px auto 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.notes li { background: var(--card); border-radius: 12px; padding: 10px 14px; font-size: 14px; box-shadow: var(--shadow); }

/* 작업 화면 */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.thumbs { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; }
.thumb { position: relative; flex: none; width: 76px; height: 76px; border-radius: 12px; overflow: hidden; border: 2px solid transparent; cursor: pointer; background: var(--card-2); }
.thumb.on { border-color: var(--accent); }
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb .st { position: absolute; left: 4px; bottom: 4px; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: rgba(0, 0, 0, 0.6); color: #fff; }
.thumb .x { position: absolute; right: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; border: none; background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 12px; cursor: pointer; display: none; }
.thumb:hover .x { display: block; }
.thumb.add { display: grid; place-items: center; font-size: 26px; color: var(--muted); border: 2px dashed var(--line); }
.layout { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }
.editor { padding: 12px; min-width: 0; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar.bottom { margin-top: 10px; }
.brush { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.brush input { width: 110px; }
.stage-wrap { margin-top: 10px; border-radius: 12px; overflow: hidden; }
.stage { position: relative; height: min(62vh, 640px); overflow: auto; display: grid; place-items: center; touch-action: none; border-radius: 12px; }
.stage canvas { display: block; margin: auto; max-width: none; }
#view { image-rendering: auto; }
.stage.tool-hand { cursor: grab; }
.stage.tool-erase, .stage.tool-restore { cursor: none; }
.checker { background-color: #fff; background-image: linear-gradient(45deg, #e6e6ef 25%, transparent 25%), linear-gradient(-45deg, #e6e6ef 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e6e6ef 75%), linear-gradient(-45deg, transparent 75%, #e6e6ef 75%); background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0; }
.stage.bg-white { background: #fff; }
.stage.bg-black { background: #111; }
.stage.bg-pink { background: #ffd6e7; }
.stage.bg-sky { background: #cfe8ff; }
.cursor { position: fixed; pointer-events: none; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6); transform: translate(-50%, -50%); z-index: 20; }
.cursor.restore { border-color: #7cffb2; }
.busy { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center; background: color-mix(in srgb, var(--card) 70%, transparent); font-weight: 700; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.swatches { display: flex; gap: 6px; }
.sw { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--line); cursor: pointer; padding: 0; }
.sw.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.swatches.small .sw { width: 24px; height: 24px; }
.crop-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; padding: 10px; background: var(--accent-soft); border-radius: 12px; }
input[type='color'] { width: 34px; height: 28px; border: none; background: none; padding: 0; cursor: pointer; }

.side { padding: 16px; }
.side h3 { font-size: 14px; margin: 14px 0 8px; color: var(--muted); }
.side h3:first-child { margin-top: 0; }
.field { margin-bottom: 10px; }
.field label { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.field input[type='range'] { width: 100%; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; margin: 8px 0; cursor: pointer; }
input[type='range'] { accent-color: var(--accent); }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 24px 16px 36px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 600; z-index: 50; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }

/* 좁은 화면 (폰) */
@media (max-width: 640px) {
  header .bar { flex-wrap: wrap; row-gap: 8px; }
  header .bar .spacer { display: none; }
  #model-seg { order: 3; width: 100%; }
  #model-seg button { flex: 1; padding: 7px 4px; }
  .pill { max-width: calc(100vw - 190px); }
  .wrap { padding: 12px; }
  .stage { height: 56vh; }
  .brush input { width: 90px; }
}

/* 박제판 */
.board-stage { height: min(70vh, 760px); }
.board-stage canvas { box-shadow: 0 6px 30px rgba(0, 0, 0, 0.18); border-radius: 6px; touch-action: none; }
.swatches.wrap { flex-wrap: wrap; }
.bd-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px; max-height: 200px; overflow-y: auto; }
.bd-item { border: 2px solid var(--line); border-radius: 10px; padding: 3px; cursor: pointer; height: 60px; }
.bd-item:hover { border-color: var(--accent); }
.bd-item img { width: 100%; height: 100%; object-fit: contain; display: block; }
.select, .side select { width: auto; max-width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 7px 10px; font: inherit; color: inherit; }
.side select { width: 100%; }
.side textarea { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 10px; font: inherit; color: inherit; resize: vertical; }
.btn.danger { color: var(--bad); }

/* 탭·나누기 창 */
.seg.big button { padding: 8px 16px; font-size: 15px; }
.modal { border: none; border-radius: 20px; padding: 0; background: var(--card); color: var(--text); width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(10, 8, 20, 0.55); }
.modal-body { padding: 18px 18px 8px; overflow: auto; max-height: calc(100vh - 140px); }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--line); }
.split-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.split-cell { position: relative; border: 2px solid var(--line); border-radius: 14px; padding: 6px; cursor: pointer; background-color: #fff; }
.split-cell.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.split-cell.off { opacity: 0.45; }
.split-cell img { width: 100%; height: 96px; object-fit: contain; display: block; }
.split-cell .tick { position: absolute; top: 6px; left: 6px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.split-cell.off .tick { background: var(--line); color: var(--muted); }
.split-cell .tag { position: absolute; right: 6px; bottom: 6px; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: rgba(0,0,0,.55); color: #fff; }
