/* ── 푸른장미 아틀리에 테마: 짙은 파랑 + 푸른장미 ───────────── */
:root {
  --bg: #060c1d;
  --bg2: #0b1530;
  --panel: rgba(15, 30, 66, .78);
  --panel-solid: #101f42;
  --line: #223a72;
  --line-soft: #1a2c58;
  --accent: #5b8cff;
  --accent-2: #8fb3ff;
  --accent-deep: #2f5bd4;
  --text: #dbe6ff;
  --muted: #8aa0d0;
  --danger: #ff7a8a;
  --ok: #6fe3b2;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans KR', system-ui, sans-serif;
  min-height: 100vh;
}
body::before {
  content: '';
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(900px 600px at 85% -10%, rgba(47, 91, 212, .28), transparent 60%),
    radial-gradient(700px 500px at -10% 40%, rgba(91, 140, 255, .14), transparent 55%),
    radial-gradient(600px 700px at 60% 110%, rgba(30, 58, 138, .25), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
}

.rose { filter: hue-rotate(215deg) saturate(1.7) brightness(1.05); }

/* 테마 스크롤바 (페이지 전체 + 내부 스크롤 영역 공통) */
* { scrollbar-width: thin; scrollbar-color: #2c4585 rgba(11, 25, 54, .5); }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: rgba(11, 25, 54, .5); border-radius: 8px; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #33508f, #22397a);
  border-radius: 8px;
  border: 2px solid #0b1530;
}
::-webkit-scrollbar-thumb:hover { background: var(--accent-deep); }
::-webkit-scrollbar-corner { background: transparent; }

.brand-name {
  font-family: '7. Minal', 'Noto Sans KR', sans-serif;
  font-weight: 400;
  letter-spacing: 1px;
  color: var(--accent-2);
}
.brand .brand-name { font-size: 24px; }
.login-card h1.brand-name { font-size: 44px; margin: 0 0 6px; }

/* ── 상단바 ── */
#topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 22px;
  background: rgba(8, 16, 38, .85);
  border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 50;
}
.brand { font-weight: 900; font-size: 17px; letter-spacing: .5px; white-space: nowrap; }
#nav { display: flex; gap: 4px; flex: 1; }
#nav a {
  color: var(--muted); text-decoration: none; font-weight: 500;
  padding: 7px 14px; border-radius: 9px; font-size: 14px;
}
#nav a:hover { color: var(--text); background: rgba(91, 140, 255, .1); }
#nav a.on { color: #fff; background: rgba(91, 140, 255, .18); }
#nav a { position: relative; }
.nav-badge {
  display: inline-grid; place-items: center;
  min-width: 17px; height: 17px; padding: 0 5px; margin-left: 6px;
  border-radius: 999px; background: var(--danger); color: #1a0a10;
  font-size: 11px; font-weight: 800; line-height: 1; vertical-align: 1px;
}
.nav-badge[hidden] { display: none; }
.userbox { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
#userName { color: var(--accent-2); font-weight: 700; }

main { padding: 20px 22px 60px; max-width: 1500px; margin: 0 auto; }

/* ── 버튼/입력 ── */
button {
  font-family: inherit; font-size: 14px; font-weight: 700;
  color: var(--text);
  background: linear-gradient(180deg, #1b2f61, #152449);
  border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 16px; cursor: pointer;
  transition: filter .15s, transform .05s;
}
button:hover { filter: brightness(1.2); }
button:active { transform: translateY(1px); }
button.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  border-color: var(--accent-deep); color: #fff;
}
button.ghost { background: transparent; border-color: var(--line-soft); color: var(--muted); }
button.ghost:hover { color: var(--text); }
button.danger { border-color: #5a2740; color: var(--danger); background: rgba(255, 122, 138, .07); }
button.small { padding: 5px 10px; font-size: 12.5px; }
button:disabled { opacity: .45; cursor: not-allowed; }

input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--text);
  background: #0b1936; border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 11px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type="color"] { padding: 2px; width: 44px; height: 34px; cursor: pointer; }
input[type="file"] { padding: 5px 8px; color: var(--muted); font-size: 13px; }
input[type="file"]::file-selector-button {
  font-family: inherit; font-size: 13px; font-weight: 700; color: var(--text);
  background: linear-gradient(180deg, #1b2f61, #152449);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 14px; margin-right: 10px; cursor: pointer;
  transition: filter .15s;
}
input[type="file"]::file-selector-button:hover { filter: brightness(1.2); }
input[type="range"] { padding: 0; }
label { font-size: 12.5px; color: var(--muted); display: block; margin-bottom: 4px; }

.chip {
  display: inline-block; padding: 4px 12px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700;
  background: rgba(91, 140, 255, .13); color: var(--accent-2);
  border: 1px solid rgba(91, 140, 255, .3);
}
.chip.warn { background: rgba(255, 122, 138, .1); color: var(--danger); border-color: rgba(255, 122, 138, .3); }

/* ── 로그인 ── */
.login-wrap { display: grid; place-items: center; min-height: 82vh; }
.login-card {
  width: 360px; padding: 40px 36px; text-align: center;
  background: var(--panel); border: 1px solid var(--line-soft);
  border-radius: 20px; backdrop-filter: blur(10px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}
.login-card .big-rose { font-size: 54px; display: block; margin-bottom: 6px; }
.login-card h1 { font-size: 22px; font-weight: 900; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 26px; }
.login-card input { width: 100%; margin-bottom: 12px; text-align: center; font-size: 15px; padding: 11px; }
.login-card button { width: 100%; padding: 12px; font-size: 15px; margin-top: 4px; }
.login-err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 12px; }

/* ── 에디터 ── */
.editor-top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.editor-top .spacer { flex: 1; }
#designTitle { width: 200px; }
.size-pick { display: flex; align-items: center; gap: 6px; }
.size-pick label { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; }
.size-pick select { padding: 6px 8px; }
.side-toggle { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.side-toggle button { border: 0; border-radius: 0; background: transparent; color: var(--muted); }
.side-toggle button.on { background: var(--accent-deep); color: #fff; }

/* 캔버스 칸(auto)은 캔버스 크기에 딱 맞고, 남는 폭은 중앙 정렬로 흡수 */
.editor-body { display: grid; grid-template-columns: 300px auto 300px; gap: 14px; align-items: start; justify-content: center; }
.panel {
  background: var(--panel); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 14px; backdrop-filter: blur(8px);
}
.panel h3 { margin: 0 0 10px; font-size: 13px; color: var(--accent-2); letter-spacing: .5px; }
.canvas-wrap {
  display: grid; place-items: center; position: relative;
  background: rgba(5, 10, 24, .5); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 12px; min-height: 400px;
}
.canvas-wrap canvas { border-radius: 6px; }
/* 원본 숨김 모드: 투명 배경을 체커보드로 표시 */
.canvas-wrap.tpl-hidden .canvas-container {
  background: repeating-conic-gradient(#16264d 0 25%, #0b1936 0 50%) 0 0 / 22px 22px;
  border-radius: 6px;
}
/* 기준선 가이드 */
.guide-h { position: absolute; height: 0; border-top: 1px dashed rgba(111, 227, 178, .75); pointer-events: none; }
.guide-v { position: absolute; width: 0; border-left: 1px dashed rgba(111, 227, 178, .75); pointer-events: none; }
.guide-label {
  position: absolute; font-size: 10px; color: var(--ok);
  background: rgba(8, 16, 38, .85); padding: 1px 7px; border-radius: 6px;
  pointer-events: none; white-space: nowrap;
}

/* 다중 선택 정렬 */
.align-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.align-grid.two { grid-template-columns: 1fr 1fr; }
.align-grid button { padding: 8px 4px; font-size: 12.5px; }

/* ⋯ 더보기 메뉴 */
.menu-wrap { position: relative; }
.menu[hidden] { display: none; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  display: flex; flex-direction: column; gap: 2px; min-width: 176px;
  background: var(--panel-solid); border: 1px solid var(--line);
  border-radius: 11px; padding: 6px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .5);
}
.menu button {
  background: transparent; border: 0; text-align: left;
  padding: 8px 11px; border-radius: 8px; font-weight: 500; font-size: 13px; width: 100%;
}
.menu button:hover { background: rgba(91, 140, 255, .12); }
.menu .danger-item { color: var(--danger); }

.snap-line {
  position: absolute; width: 0;
  border-left: 1px dashed #ff5b8a;
  pointer-events: none; z-index: 4;
}

/* 캔버스를 가리지 않도록 이미지 아래 줄에 배치 (.canvas-wrap 그리드의 두 번째 행) */
.zoom-ctrl {
  margin-top: 10px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center;
  background: rgba(8, 16, 38, .88); border: 1px solid var(--line-soft);
  border-radius: 10px; padding: 5px 8px; z-index: 5;
}
.zoom-ctrl button { padding: 3px 10px; font-size: 14px; }
.zoom-ctrl span { font-size: 12px; color: var(--muted); min-width: 42px; text-align: center; }

.tpl-hint {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
  font-size: 12px; color: var(--muted); background: rgba(8, 16, 38, .85);
  padding: 5px 14px; border-radius: 999px; border: 1px solid var(--line-soft);
  pointer-events: none; white-space: nowrap;
}

#layers { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; min-height: 40px; }
.layer-item {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 9px; border-radius: 9px; cursor: pointer;
  background: rgba(11, 25, 54, .6); border: 1px solid transparent;
  font-size: 13px;
}
.layer-item:hover { border-color: var(--line); }
.layer-item.on { border-color: var(--accent); background: rgba(91, 140, 255, .12); }
.layer-item { cursor: grab; user-select: none; }
.layer-item.dragging { opacity: .35; cursor: grabbing; }
.layer-item .grip { color: var(--muted); font-size: 11px; cursor: grab; }
.drop-indicator {
  height: 0; margin: 1px 4px;
  border-top: 2px solid var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(91, 140, 255, .8);
}
.layer-item .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-item button { padding: 1px 6px; font-size: 11px; background: transparent; border-color: transparent; color: var(--muted); }
.layer-item button:hover { color: var(--text); border-color: var(--line); }
.add-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hint { font-size: 11.5px; color: var(--muted); line-height: 1.6; margin-top: 12px; }
.shortcuts { border-top: 1px dashed var(--line-soft); padding-top: 10px; }
.key-row { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
.key-row > span:first-child { flex: 0 0 108px; white-space: nowrap; }
kbd {
  display: inline-block; padding: 1px 6px;
  background: #0b1936; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; font-family: inherit; font-size: 10.5px;
  color: var(--accent-2); white-space: nowrap;
}

.props-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.prop-sec {
  margin-top: 8px; padding-top: 10px;
  border-top: 1px dashed var(--line-soft);
  font-size: 11px; font-weight: 700; letter-spacing: 1px;
  color: var(--accent-2); text-transform: uppercase;
}
/* 라벨이 두 줄로 접혀도 입력칸은 아래쪽 기준으로 나란히 정렬 */
.props-grid > div { display: flex; flex-direction: column; justify-content: flex-end; }
.props-grid label { flex: 1; }
.props-grid .full { grid-column: 1 / -1; }
.props-grid input, .props-grid select, .props-grid textarea { width: 100%; }
.prop-row { display: flex; align-items: center; gap: 8px; }
.placeholder-msg { color: var(--muted); font-size: 13px; text-align: center; padding: 30px 10px; line-height: 1.7; }
.checkline { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text); cursor: pointer; }
.checkline input { width: auto; }

/* ── 카드 그리드 (결과물/세트) ── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  /* overflow hidden 금지 — ⋯ 메뉴가 카드보다 커도 잘리지 않아야 함 */
}
.card .thumb {
  width: 100%; aspect-ratio: 3 / 4; object-fit: contain;
  background: #060d20; display: block; cursor: zoom-in;
  border-radius: var(--radius) var(--radius) 0 0;
}
.card .thumb.wide { aspect-ratio: 16 / 10; }
.card .body { padding: 12px 14px; }
.card .title { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.card .meta { font-size: 11.5px; color: var(--muted); margin-bottom: 10px; }
.card .btns { display: flex; flex-wrap: wrap; gap: 6px; }
/* 합성 결과 목록: 3줄 정도만 보이고 나머지는 스크롤 */
.card .jobs { max-height: 216px; overflow-y: auto; margin-top: 4px; padding-right: 4px; }

.job-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 0; border-top: 1px dashed var(--line-soft);
  font-size: 12.5px;
}
.job-row img { width: 44px; height: 56px; object-fit: cover; border-radius: 6px; cursor: zoom-in; background: #060d20; }
.job-row .grow { flex: 1; }
.status-queued { color: var(--muted); }
.status-running { color: var(--accent-2); }
.status-done { color: var(--ok); }
.status-error { color: var(--danger); }
.spin {
  display: inline-block; width: 12px; height: 12px;
  border: 2px solid var(--accent-2); border-top-color: transparent;
  border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h2 { margin: 0; font-size: 20px; font-weight: 900; }
.page-head .spacer { flex: 1; }
.tabs { display: flex; gap: 6px; }
.tabs button { background: transparent; border-color: var(--line-soft); color: var(--muted); }
.tabs button.on { background: rgba(91, 140, 255, .16); color: #fff; border-color: var(--accent-deep); }
.empty { color: var(--muted); text-align: center; padding: 60px 0; font-size: 14px; }

/* ── 세트 페이지 ── */
/* minmax(0,1fr): 내용물 크기와 무관하게 두 칸 너비를 항상 동일하게 고정 */
.set-builder { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; margin-bottom: 24px; }
.pick-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px; padding: 6px 2px;
  max-height: 330px; overflow-y: auto;
}
.pick-item {
  cursor: pointer; text-align: center;
  border: 2px solid transparent; border-radius: 10px; padding: 5px;
  background: rgba(11, 25, 54, .5);
}
.pick-item img { width: 100%; height: 120px; object-fit: contain; border-radius: 6px; background: #060d20; }
.pick-item .lbl { font-size: 11px; color: var(--muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-item.on { border-color: var(--accent); background: rgba(91, 140, 255, .12); }
.pick-item.on .lbl { color: var(--accent-2); }

/* ── 테이블 (관리자) ── */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
th { color: var(--muted); font-size: 12px; font-weight: 500; }
tr:hover td { background: rgba(91, 140, 255, .04); }
.form-row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 18px; }
.form-row > div { display: flex; flex-direction: column; }

.tpl-admin { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tpl-admin img.preview { width: 100%; max-height: 320px; object-fit: contain; background: #060d20; border-radius: 10px; }
.ver-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; border-top: 1px dashed var(--line-soft); }

/* ── 사용법 페이지 ── */
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: 1100px; margin: 0 auto; }
.help-grid .panel h3 { font-size: 15px; color: var(--text); margin-bottom: 8px; }
.help-p { font-size: 13.5px; line-height: 1.8; margin: 6px 0; }
.help-p.hint, p.help-p.hint { color: var(--muted); font-size: 12.5px; }
.help-ul { margin: 6px 0; padding-left: 18px; font-size: 13.5px; line-height: 1.9; }
.help-ul li::marker { color: var(--accent); }
.help-ul.two-col { columns: 2; column-gap: 28px; }
.help-ul.two-col li { break-inside: avoid; }
.help-keys { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 10px 0; font-size: 12px; color: var(--muted); }
.help-keys span { white-space: nowrap; }
@media (max-width: 1000px) {
  .help-grid { grid-template-columns: 1fr; }
  .help-ul.two-col { columns: 1; }
}

/* ── 토스트/라이트박스 ── */
#toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: #14264f; border: 1px solid var(--accent-deep);
  color: var(--text); padding: 12px 22px; border-radius: 12px;
  font-size: 14px; font-weight: 500; z-index: 200;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5); max-width: 80vw;
}
#toast.err { border-color: #5a2740; color: var(--danger); }
.lightbox {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(3, 6, 15, .92); display: grid; place-items: center; cursor: zoom-out;
}
.lightbox img { max-width: 94vw; max-height: 94vh; border-radius: 8px; }

@media (max-width: 1000px) {
  .editor-body { grid-template-columns: 1fr; }
  .set-builder { grid-template-columns: 1fr; }
  .tpl-admin { grid-template-columns: 1fr; }
}
