:root {
  --bg: #f7f6fb; --card: #ffffff; --ink: #1d1b26; --mute: #6b6880; --line: #e3e0ee;
  --accent: #6d4aff; --accent-ink: #ffffff; --alt: #0f9d7a; --warn: #c2410c; --chip: #efecf8;
  --shadow: 0 1px 2px rgba(20,10,60,.06), 0 6px 24px rgba(20,10,60,.06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121119; --card: #1c1a26; --ink: #ecebf5; --mute: #a19db8; --line: #2e2b3d;
    --accent: #8f73ff; --alt: #2cc79f; --warn: #fb923c; --chip: #272436; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.55 system-ui, -apple-system, "Segoe UI",
  "Apple SD Gothic Neo", "Malgun Gothic", sans-serif; }
a { color: var(--accent); }
button, input, textarea { font: inherit; color: inherit; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; max-width: 1180px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-size: 17px; }
.topright { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.server { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--mute);
  background: var(--card); border: 1px solid var(--line); padding: 5px 11px; border-radius: 99px; }
.server i { width: 8px; height: 8px; border-radius: 50%; background: #aaa; }
.server.ok i { background: #22c55e; } .server.busy i { background: #f59e0b; } .server.off i { background: #ef4444; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 0 16px 10px; max-width: 1180px; margin: 0 auto;
  scrollbar-width: none; }
@media (min-width: 701px) { .tabs { flex-wrap: wrap; overflow-x: visible; } }   /* 14 tabs: wrap instead of hiding some off-screen */
.tabs button { flex: none; border: 1px solid var(--line); background: var(--card); padding: 9px 14px;
  border-radius: 12px; cursor: pointer; white-space: nowrap; }
.tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

main { max-width: 1180px; margin: 0 auto; padding: 0 16px 24px; }
.panel { display: none; gap: 18px; grid-template-columns: minmax(300px, 400px) 1fr; align-items: start; }
.panel.on { display: grid; }
@media (max-width: 820px) { .panel.on { grid-template-columns: 1fr; } }

.controls { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.lbl { font-weight: 600; font-size: 14px; }
textarea, input[type=text], input:not([type]) { width: 100%; border: 1px solid var(--line); background: var(--bg);
  border-radius: 12px; padding: 10px 12px; resize: vertical; }
textarea:focus, input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button, .aspects button { border: 1px solid transparent; background: var(--chip); padding: 6px 10px;
  border-radius: 99px; cursor: pointer; font-size: 13px; }
.chips button.on, .aspects button.on { border-color: var(--accent); color: var(--accent); background: transparent; }
.chips input[type=color] { width: 34px; height: 30px; border: none; padding: 0; background: none; cursor: pointer; }
.aspects { display: flex; flex-wrap: wrap; gap: 6px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.more summary { cursor: pointer; color: var(--mute); font-size: 13px; }
.more label { display: block; font-size: 13px; margin-top: 8px; color: var(--mute); }
.hint { margin: 0; color: var(--mute); font-size: 13px; }
.go { border: none; background: var(--accent); color: var(--accent-ink); padding: 13px 16px;
  border-radius: 14px; font-weight: 700; cursor: pointer; font-size: 16px; }
.go.alt { background: var(--alt); }
.go small { display: block; font-weight: 400; font-size: 12px; opacity: .85; }
.go:disabled { opacity: .5; cursor: progress; }
.ghost { border: 1px solid var(--line); background: transparent; padding: 6px 10px; border-radius: 10px; cursor: pointer; }
.brush label { display: flex; align-items: center; gap: 8px; font-size: 13px; }

.drops { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.drop { position: relative; aspect-ratio: 1; border: 2px dashed var(--line); border-radius: 14px;
  display: grid; place-items: center; cursor: pointer; color: var(--mute); font-size: 12px; text-align: center;
  overflow: hidden; background: var(--bg); }
.drop.big { grid-column: 1 / -1; aspect-ratio: auto; min-height: 110px; }
.drop.over { border-color: var(--accent); }
.drop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.drop .x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: none;
  background: rgba(0,0,0,.6); color: #fff; cursor: pointer; line-height: 1; z-index: 2; }
.drop .n { position: absolute; left: 4px; top: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px;
  padding: 1px 6px; border-radius: 6px; z-index: 2; }

.stage { min-height: 320px; display: flex; flex-direction: column; gap: 14px; }
.empty { border: 2px dashed var(--line); border-radius: 18px; min-height: 320px; display: grid; place-items: center;
  color: var(--mute); }
.status { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.status .bar { height: 6px; background: var(--chip); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.status .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.status.err { border-color: var(--warn); color: var(--warn); }
.result { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 18px; overflow: hidden;
  box-shadow: var(--shadow); }
.imgbox { background: repeating-conic-gradient(#8881 0 25%, transparent 0 50%) 0 0 / 20px 20px; display: grid; place-items: center; }
.result img { display: block; max-width: 100%; max-height: 75vh; }
.result figcaption { padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.meta { color: var(--mute); font-size: 12px; word-break: break-word; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.btn { border: 1px solid var(--line); background: var(--bg); padding: 6px 10px; border-radius: 10px; cursor: pointer;
  font-size: 13px; text-decoration: none; color: var(--ink); }
.btn.dl { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.canvas-wrap { position: relative; border-radius: 18px; overflow: hidden; touch-action: none; background: var(--card);
  border: 1px solid var(--line); }
.canvas-wrap canvas { display: block; width: 100%; height: auto; }
.canvas-wrap canvas.mask { position: absolute; inset: 0; opacity: .5; cursor: crosshair; }
.ts:empty { display: none; }
.lang { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 99px;
  padding: 5px 8px; font-size: 13px; cursor: pointer; max-width: 150px; }
.navlinks .lang { margin-right: 2px; }

/* 관리 탭 */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stats div { background: var(--bg); border-radius: 12px; padding: 8px 10px; font-size: 12px; color: var(--mute); }
.stats b { display: block; font-size: 20px; color: var(--ink); }
.limits { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.limits label { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.limits input { width: 90px; text-align: right; }
.log { background: var(--bg); border-radius: 10px; padding: 8px; font-size: 11px; max-height: 220px; overflow: auto; white-space: pre-wrap; }
.adgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.adgrid figure { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.adgrid img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.adgrid figcaption { padding: 6px 8px; font-size: 12px; display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.howto { margin: 8px 0; padding: 10px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.howto summary { cursor: pointer; font-weight: 600; }
.howto ol { margin: 8px 0 2px; padding-left: 20px; display: grid; gap: 6px; }
.recent { width: 100%; border-collapse: collapse; font-size: 12px; background: var(--card); }
.recent th, .recent td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.recent td.no { color: var(--warn); }

footer { max-width: 1180px; margin: 20px auto 40px; padding: 0 16px; color: var(--mute); font-size: 13px; }
footer .small { font-size: 12px; }

/* 3D */
.r3d model-viewer { display: block; width: 100%; height: min(70vh, 560px); background: radial-gradient(circle at 50% 40%, var(--card), var(--bg)); --poster-color: transparent; }

/* 한글 디자인 */
.dz-controls { gap: 10px; }
.dz-sec { border-top: 1px solid var(--line); padding-top: 8px; }
.dz-sec summary { cursor: pointer; font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.dz-sec > * + * { margin-top: 8px; }
.dz-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.dz-inline input[type=color] { width: 32px; height: 26px; border: none; padding: 0; background: none; }
.dz-props[hidden] { display: none; }
.dz-props { display: flex; flex-direction: column; gap: 8px; background: var(--bg); padding: 10px; border-radius: 12px; }
.dz-props select { border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; background: var(--card); color: var(--ink); max-width: 100%; }
.dz-copies { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.dz-copy { text-align: left; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 10px; cursor: pointer; }
.dz-copy b { display: block; font-size: 14px; } .dz-copy span { color: var(--mute); font-size: 12px; }
.dz-wrap { width: 100%; margin: 0 auto; }
.dz-canvas { position: relative; width: 100%; overflow: hidden; border-radius: 12px; box-shadow: var(--shadow);
  touch-action: none; user-select: none; container-type: inline-size; }
.dz-layer { position: absolute; transform: translate(-50%, -50%); white-space: pre; cursor: move; line-height: 1.2; }
.dz-layer img { display: block; pointer-events: none; }
.dz-layer.sel { outline: 2px dashed #6d4aff; outline-offset: 6px; }
.dz-handle { display: none; position: absolute; right: -14px; bottom: -14px; width: 16px; height: 16px; border-radius: 50%;
  background: #6d4aff; border: 2px solid #fff; cursor: nwse-resize; }
.dz-layer.sel .dz-handle { display: block; }

/* 캐릭터 */
.ch-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.ch-card { position: relative; border: 2px solid var(--line); background: var(--bg); border-radius: 12px; padding: 4px; cursor: pointer; text-align: center; }
.ch-card.on { border-color: var(--accent); }
.ch-card img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; }
.ch-card span { font-size: 12px; display: block; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-card i { position: absolute; top: 2px; right: 4px; font-style: normal; color: var(--mute); font-size: 16px; }
.ch-mode { display: flex; flex-direction: column; gap: 8px; }
.ch-mode[hidden] { display: none; }
.ch-panels { display: flex; flex-direction: column; gap: 8px; }
.ch-panel { display: grid; grid-template-columns: 34px 1fr; gap: 4px 6px; align-items: start; }
.ch-panel b { grid-row: span 2; font-size: 13px; padding-top: 8px; }
.ch-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 8px; background: #fff; }
.ch-grid a { text-decoration: none; color: #333; text-align: center; font-size: 12px; }
.ch-grid img { width: 100%; display: block; border-radius: 8px; }

/* 사진 도구 */
.ph-tool { display: flex; flex-direction: column; gap: 8px; }
.ph-tool[hidden] { display: none; }

/* 작업 흐름 (flow.js) */
.fl-cmp { position: relative; display: inline-block; line-height: 0; max-width: 100%; }
.fl-cmp .fl-before, .fl-cmp i, .fl-cmp input, .fl-cmp .fl-tag { display: none; }
.fl-cmp.on .fl-before { display: block; position: absolute; inset: 0; width: 100%; height: 100%; max-height: none; }
.fl-cmp.on i { display: block; position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.35); pointer-events: none; }
.fl-cmp.on input { display: block; position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize; }
.fl-cmp.on .fl-tag { display: block; position: absolute; top: 8px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px;
  line-height: 1.5; padding: 1px 8px; border-radius: 99px; pointer-events: none; }
.fl-tag.l { left: 8px; } .fl-tag.r { right: 8px; }
.btn.on { border-color: var(--accent); color: var(--accent); }
.fl-next { display: flex; gap: 6px; }
.fl-next input { flex: 1; min-width: 0; padding: 7px 10px; }
.fl-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 6px; }
.fl-cell { position: relative; aspect-ratio: 1; border: 3px solid transparent; border-radius: 12px; background: var(--bg);
  overflow: hidden; padding: 0; cursor: pointer; display: grid; place-items: center; color: var(--mute); font-size: 20px; }
.fl-cell:disabled { cursor: default; }
.fl-cell:not(:disabled):hover, .fl-cell.on { border-color: var(--accent); }
.result .fl-cell img { position: absolute; inset: 0; width: 100%; height: 100%; max-height: none; object-fit: cover; }
.fl-cell.busy { animation: fl-pulse 1.2s ease-in-out infinite; }
@keyframes fl-pulse { 50% { opacity: .45; } }
.fl-tree, #hist-stage { min-width: 0; }
.fl-tree { display: flex; flex-direction: column; gap: 6px; }
.fl-node { display: flex; align-items: center; gap: 10px; text-align: left; border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 6px; cursor: pointer; min-width: 0; overflow: hidden; }
.fl-node.on { border-color: var(--accent); }
.fl-node img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex: none;
  background: repeating-conic-gradient(#8882 0 25%, transparent 0 50%) 0 0 / 12px 12px; }
.fl-node span { min-width: 0; display: flex; flex-direction: column; font-size: 13px; }
.fl-node small { color: var(--mute); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 3D 파일 보기 */
.v3-drop { border: 2px dashed var(--line); border-radius: 14px; min-height: 96px; display: grid; place-items: center;
  text-align: center; padding: 12px; cursor: pointer; color: var(--mute); font-size: 13px; background: var(--bg); }
.v3-drop.over { border-color: var(--accent); color: var(--accent); }
.v3-host { position: relative; width: 100%; height: min(72vh, 680px); min-height: 360px; border-radius: 18px; overflow: hidden;
  border: 1px solid var(--line); background: #15151c; touch-action: none; }
.v3-host canvas { display: block; width: 100%; height: 100%; }
.v3-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #9aa; pointer-events: none; text-align: center; padding: 16px; }
.v3-host.over { outline: 3px solid var(--accent); outline-offset: -3px; }
.v3-checks { display: grid; gap: 6px; font-size: 13px; }
.v3-checks label { display: flex; align-items: center; gap: 8px; }
.v3-info { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 12px; color: var(--mute); }
.v3-info b { color: var(--ink); font-weight: 600; text-align: right; }
.v3-tree { max-height: 220px; overflow: auto; font-size: 12px; margin-top: 6px; }
.v3-tree div { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.v3-tree input { margin: 0; }
.v3-empty[hidden] { display: none; }
.v3-clip video { display: block; width: 100%; max-height: 60vh; background: #000; }
.v3-clip[hidden] { display: none; }
.v3-linkbox { display: flex; flex-direction: column; gap: 6px; }
.v3-linkbox code { font-size: 12px; word-break: break-all; flex: 1 1 220px; }
#v3-rec.rec { background: #d33; animation: v3pulse 1s infinite; }
@keyframes v3pulse { 50% { opacity: .65; } }
