/* 모챙이 - AI 이모티콘 메이커 (다크 테마, 0챙이 시리즈 톤 계승) */
:root {
  --bg: #0b1020;
  --bg-surface: #131a2e;
  --bg-elevated: #1b2440;
  --border: #2a3556;
  --text-primary: #e7ecf6;
  --text-secondary: #b6c0d8;
  --text-muted: #8090ad;
  --accent: #8b5cf6;
  --accent2: #3b82f6;
  --green: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --pink: #ec4899;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, rgba(139,92,246,0.15), transparent), var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--accent2); }
code { background: var(--bg-elevated); padding: 1px 6px; border-radius: 5px; font-size: 12px; }
img { max-width: 100%; }
/* 긴 단어/URL이 좁은 화면에서 가로로 넘치지 않게 */
.concept-tagline, .concept-grid .v, .gal-title, .gal-sub, .hint, .help-body p { overflow-wrap: anywhere; }

/* 시작 화면 */
#login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 40px 36px; max-width: 420px; width: 100%; text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
}
.login-card .logo { font-size: 52px; }
.login-card h1 { margin: 12px 0 4px; font-size: 24px; }
.login-card p { color: var(--text-muted); font-size: 14px; line-height: 1.6; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 10px; padding: 11px 18px; font-weight: 700; font-size: 14px;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-ghost { background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-secondary); }
.btn-block { width: 100%; }
.btn-danger { background: linear-gradient(135deg, var(--red), #b91c1c); }

/* 앱 레이아웃 */
#app { min-height: 100vh; }
.layout { display: flex; min-height: 100vh; align-items: stretch; }
.sidebar {
  width: 260px; flex: none; background: var(--bg-surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh;
}
.mobile-topbar { display: none; }
.sidebar-overlay { display: none; }
.sidebar-close { display: none; }
.icon-btn { background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-primary); width: 38px; height: 38px; border-radius: 9px; font-size: 18px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--border); }
.side-logo { font-size: 18px; font-weight: 800; display: flex; align-items: center; gap: 8px; padding: 6px 8px 14px; }
.badge { font-size: 11px; font-weight: 700; color: var(--accent); border: 1px solid var(--accent); border-radius: 8px; padding: 2px 8px; }
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-item { text-align: left; background: transparent; border: none; color: var(--text-secondary); padding: 10px 12px; border-radius: 9px; font-size: 14px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.side-item:hover { background: var(--bg-elevated); color: var(--text-primary); }
.side-item.active { background: var(--bg-elevated); color: var(--text-primary); box-shadow: inset 3px 0 0 var(--accent); }
.side-badge { background: var(--amber); color: #1b1300; font-size: 11px; font-weight: 800; border-radius: 10px; padding: 1px 7px; min-width: 18px; text-align: center; }
.side-sec { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--text-muted); padding: 16px 10px 6px; font-weight: 700; }
.month-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.proj-item { text-align: left; background: transparent; border: none; color: var(--text-secondary); padding: 9px 12px; border-radius: 8px; font-size: 13px; display: flex; justify-content: space-between; gap: 8px; cursor: pointer; align-items: center; }
.proj-item:hover { background: var(--bg-elevated); color: var(--text-primary); }
.proj-item.active { background: var(--bg-elevated); color: var(--text-primary); box-shadow: inset 2px 0 0 var(--accent); }
.proj-item .cnt { color: var(--text-muted); font-size: 11px; }
.side-sync { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 8px 0; border-top: 1px solid var(--border); margin-top: 10px; }
.sync-status { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 8px 0; margin-top: 8px; }
.user-chip { font-size: 12px; color: var(--text-muted); margin-right: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { flex: 1; padding: 24px 22px 60px; max-width: 980px; }
.view.hidden { display: none; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .title { font-size: 20px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; margin-bottom: 18px; }
.card-title { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--text-muted); }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-primary);
  border-radius: 9px; padding: 9px 12px; font-size: 14px; font-family: inherit; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); background-color: rgba(139,92,246,0.08); }
/* 네이티브 드롭다운 옵션 — Windows/Linux 브라우저에서 흰 배경+흰 글씨로 안 보이던 문제 방지 */
select option, select optgroup { background-color: var(--bg-elevated); color: var(--text-primary); }
/* 일부 브라우저(Firefox 등)가 placeholder를 과하게 흐리게 처리하는 것 방지 */
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: 1; }
textarea { width: 100%; resize: vertical; line-height: 1.6; }
.hint { font-size: 12px; color: var(--text-muted); line-height: 1.5; margin-top: 4px; }

/* 진행 표시 */
.proc { margin-top: 12px; font-size: 13px; color: var(--text-secondary); }
.step { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.err-line { color: var(--red); }
.ok-line { color: var(--green); }

/* 컨셉안 카드 */
.concept-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; margin-bottom: 16px; }
.concept-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.concept-name { font-size: 18px; font-weight: 800; }
.concept-tag { color: var(--accent); font-weight: 600; }
.concept-tagline { color: var(--text-secondary); font-size: 14px; margin-bottom: 10px; }
.concept-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; margin: 10px 0; }
.concept-grid .k { font-size: 11px; color: var(--text-muted); font-weight: 700; }
.concept-grid .v { font-size: 13px; color: var(--text-primary); line-height: 1.5; }
.palette { display: flex; gap: 6px; margin-top: 4px; }
.swatch { width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--border); }
.title-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.title-chip { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 7px; padding: 3px 9px; font-size: 12px; color: var(--text-secondary); }
.set-preview { margin-top: 10px; }
.set-preview summary { cursor: pointer; color: var(--text-muted); font-size: 12px; font-weight: 700; }
.set-preview ol { margin: 8px 0 0; padding-left: 20px; columns: 2; font-size: 12.5px; color: var(--text-secondary); line-height: 1.7; }
/* 모바일/소형 태블릿 폼 — 필드를 세로로 쌓고 입력칸이 가로폭을 채우게 */
@media (max-width: 640px) {
  .concept-grid { grid-template-columns: 1fr; }
  .set-preview ol { columns: 1; }
  .row { gap: 10px; }
  .row > .field { flex-grow: 1; flex-basis: 100%; min-width: 0; }
  .field > select,
  .field > input[type="text"],
  .field > input[type="password"],
  .field > textarea { width: 100%; }
  .topbar .title { font-size: 18px; }
  .topbar { margin-bottom: 14px; }
}
.concept-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* 레퍼런스 업로드 */
.dropzone { border: 2px dashed var(--border); border-radius: 14px; padding: 26px; text-align: center; color: var(--text-secondary); cursor: pointer; transition: all 0.15s; margin-top: 12px; }
.dropzone:hover, .dropzone:focus { border-color: var(--accent); background: rgba(139,92,246,0.06); outline: none; }
.dropzone.drag { border-color: var(--accent); background: rgba(139,92,246,0.12); }
.dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone-inner { display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.ref-thumbs { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.ref-thumb { position: relative; width: 92px; height: 92px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--bg-elevated); }
.ref-thumb img { width: 100%; height: 100%; object-fit: contain; }
.ref-thumb .x { position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,0.6); color: #fff; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 13px; line-height: 1; cursor: pointer; }

/* 분석 결과 */
.analysis-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; margin-bottom: 16px; }
.tag-list { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.tag { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 7px; padding: 3px 9px; font-size: 12px; color: var(--text-secondary); }
.warn-box { border: 1px solid var(--amber); background: rgba(245,158,11,0.08); border-radius: 10px; padding: 12px 14px; margin-top: 12px; }
.warn-box .k { color: var(--amber); font-weight: 800; font-size: 12px; }
.warn-box ul { margin: 6px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--text-secondary); line-height: 1.6; }

/* 작업실 세트 그리드 */
.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-top: 14px; }
.emo-cell { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.emo-cell.base-char { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.emo-stage {
  position: relative; aspect-ratio: 1/1; border-radius: 10px; overflow: hidden;
  background:
    linear-gradient(45deg, #20283f 25%, transparent 25%), linear-gradient(-45deg, #20283f 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #20283f 75%), linear-gradient(-45deg, transparent 75%, #20283f 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #2a3146;
  display: flex; align-items: center; justify-content: center;
}
.emo-stage img { width: 100%; height: 100%; object-fit: contain; }
.emo-stage .placeholder { color: var(--text-muted); font-size: 30px; }
.emo-stage .cell-no { position: absolute; top: 6px; left: 8px; font-size: 11px; font-weight: 800; color: var(--text-muted); background: rgba(11,16,32,0.7); border-radius: 6px; padding: 1px 6px; }
.emo-stage .base-flag { position: absolute; top: 6px; right: 8px; font-size: 10px; font-weight: 800; color: #fff; background: var(--accent); border-radius: 6px; padding: 1px 6px; }
.emo-stage.busy::after { content: ''; position: absolute; inset: 0; background: rgba(11,16,32,0.55); }
.emo-stage .stage-spin { position: absolute; z-index: 2; }
.emo-meta { display: flex; flex-direction: column; gap: 5px; }
.emo-meta input { font-size: 12.5px; padding: 6px 9px; }
.emo-label { font-weight: 700; font-size: 12px; color: var(--text-secondary); }
.emo-actions { display: flex; gap: 5px; flex-wrap: wrap; }
/* 🎨 그리기는 한 줄 전체 차지(줄바꿈 방지), 미니 버튼 4개는 아랫줄에 나란히 */
.emo-actions .btn { padding: 7px 9px; font-size: 12px; border-radius: 8px; flex: 1 1 100%; min-width: 0; white-space: nowrap; }
.emo-actions .mini { background: var(--bg-surface); border: 1px solid var(--border); color: var(--text-secondary); flex: 1 1 0; width: auto; padding: 6px 0; min-width: 0; }

/* 보관함 */
.gal-project { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; margin-bottom: 16px; }
.gal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.gal-title { font-weight: 800; font-size: 16px; }
.gal-sub { color: var(--text-muted); font-size: 12px; }
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.gal-thumb { aspect-ratio: 1/1; border-radius: 10px; overflow: hidden; border: 1px solid var(--border);
  background:
    linear-gradient(45deg, #20283f 25%, transparent 25%), linear-gradient(-45deg, #20283f 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #20283f 75%), linear-gradient(-45deg, transparent 75%, #20283f 75%);
  background-size: 14px 14px; background-position: 0 0, 0 7px, 7px -7px, -7px 0; background-color: #2a3146;
}
.gal-thumb img { width: 100%; height: 100%; object-fit: contain; }
.empty-state { text-align: center; color: var(--text-muted); padding: 40px 20px; }
.empty-state .big { font-size: 40px; }

/* 다듬기 모달 */
.edit-preview { aspect-ratio: 1/1; max-width: 240px; margin: 0 auto 14px; border-radius: 12px; overflow: hidden; border: 1px solid var(--border);
  background:
    linear-gradient(45deg, #20283f 25%, transparent 25%), linear-gradient(-45deg, #20283f 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #20283f 75%), linear-gradient(-45deg, transparent 75%, #20283f 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0; background-color: #2a3146;
}
.edit-preview img { width: 100%; height: 100%; object-fit: contain; }
.edit-chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.chip { background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-secondary); border-radius: 20px; padding: 6px 12px; font-size: 12px; font-weight: 600; }
.chip:hover { border-color: var(--accent); color: var(--text-primary); }
.edit-history { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.edit-history img { width: 54px; height: 54px; object-fit: contain; border-radius: 8px; border: 1px solid var(--border); cursor: pointer; background: var(--bg-elevated); }
.edit-history img.cur { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* 토스트 / 모달 공통 */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-primary);
  padding: 12px 18px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: all 0.25s ease; z-index: 9999; box-shadow: 0 10px 40px rgba(0,0,0,0.5); max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--red); }
#toast.success { border-color: var(--green); }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 500; }
.modal { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 22px; }
.modal h3 { margin: 0 0 16px; }
.modal .field { margin-bottom: 12px; }
.modal .field input, .modal .field textarea, .modal .field select { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.help-body p { font-size: 13.5px; line-height: 1.6; color: var(--text-secondary); margin: 8px 0; }

/* 모바일 */
@media (max-width: 860px) {
  body { overflow-x: hidden; }
  .layout { display: block; }
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 40;
    background: var(--bg-surface); border-bottom: 1px solid var(--border);
    padding: 10px 14px;
  }
  .mobile-title { font-weight: 800; font-size: 16px; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; height: 100vh;
    width: 290px; max-width: 86vw;
    transform: translateX(-100%); transition: transform 0.28s ease;
    z-index: 1000; box-shadow: 6px 0 30px rgba(0,0,0,0.55);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-flex; margin-left: auto; }
  .sidebar-overlay {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.55);
    opacity: 0; pointer-events: none; transition: opacity 0.28s ease; z-index: 900;
  }
  .sidebar-overlay.show { opacity: 1; pointer-events: auto; }
  .main { max-width: 100%; width: 100%; padding: 16px 14px 50px; overflow-x: hidden; }
  .card { padding: 14px; }
  .set-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .modal { padding: 18px; }
}

/* 초소형 폰 */
@media (max-width: 480px) {
  .main { padding: 14px 12px 46px; }
  .login-card { padding: 30px 22px; }
  .login-card .logo { font-size: 44px; }
  .login-card h1 { font-size: 21px; }
  .card { padding: 13px; border-radius: 12px; }
  .topbar .title { font-size: 17px; }
  .concept-name { font-size: 16px; }
  .gal-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .emo-actions .btn { font-size: 11px; padding: 6px 6px; }
  .emo-actions .mini { padding: 6px 0; }
  .chip { padding: 5px 10px; }
  .modal { padding: 16px; border-radius: 14px; }
  .modal-actions { flex-wrap: wrap; }
}
