:root {
  --accent: #185FA5;
  --accent-hover: #0C447C;
  --danger: #E24B4A;
  --warning: #EF9F27;
  --success: #3B6D11;
  --ink: #1A1A18;
  --muted: #78766F;
  --line: #E4E1D8;
  --surface: #FFFFFF;
  --surface-2: #F5F3EC;
  --page: #EFECE3;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  font-family: 'Noto Sans KR', sans-serif;
  background: var(--page);
  color: var(--ink);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 481px) {
  #app { max-width: 560px; border-radius: 20px; height: min(100dvh, 800px); margin-top: 24px; box-shadow: 0 24px 60px rgba(0,0,0,0.12); }
  .char-avatar-img { width: 78px; height: 108px; }
}

/* 워크스페이스 바 */
.workspace {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 20px; background: var(--surface-2);
  border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.workspace-brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: inherit; cursor: pointer; min-width: 0;
}
.bgm-control { display: flex; align-items: center; gap: 6px; flex-shrink: 0; min-width: 0; }
.bgm-btn {
  width: 30px; height: 30px; border-radius: 50%; border: none;
  background: var(--surface); color: var(--ink); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.bgm-btn:hover { background: rgba(0,0,0,0.08); }
.bgm-title {
  font-size: 11px; color: var(--muted); max-width: 90px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.logo-img { width: 24px; height: 24px; object-fit: contain; flex-shrink: 0; }
.workspace-name { font-size: 12px; font-weight: 500; margin: 0; }
.workspace-sub { font-size: 10px; color: var(--muted); margin: 0; }

/* DM 헤더 */
.dm-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.dm-left { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--accent); flex-shrink: 0;
  background-size: cover; background-position: center;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 500; font-size: 15px;
}
.name { font-size: 14px; font-weight: 500; margin: 0; }
.status { font-size: 11px; color: var(--success); margin: 2px 0 0; }
.menu-btn {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: transparent; color: var(--ink);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.menu-btn:hover { background: var(--surface-2); }

/* 채팅 피드 */
.chat {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 16px;
}
.empty-state { text-align: center; color: var(--muted); font-size: 13px; margin: auto 0; }

.qa-block { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.bubble { max-width: 78%; padding: 10px 14px; font-size: 13px; line-height: 1.6; }
.bubble.question { background: var(--accent); color: #fff; border-radius: 16px 16px 4px 16px; }
.bubble.answer { background: var(--surface-2); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; }
.answer-row { display: flex; align-items: flex-end; gap: 6px; align-self: flex-start; }
.char-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent); flex-shrink: 0;
  background-size: cover; background-position: center;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 500; font-size: 13px;
}
.char-avatar-img {
  width: 46px; height: 64px; object-fit: contain; object-position: bottom; flex-shrink: 0;
}
.meta { font-size: 10px; color: var(--muted); margin: 0; }
.meta.right { align-self: flex-end; margin-right: 4px; }
.meta.left { align-self: flex-start; margin-left: 4px; }

.answer-cta {
  align-self: flex-start;
  background: none; border: 1px dashed #B4B2A9; color: var(--muted);
  border-radius: 20px; padding: 6px 14px; font-size: 12px; cursor: pointer;
}
.answer-cta:hover { border-color: var(--accent); color: var(--accent); }

.admin-actions { display: flex; align-items: center; gap: 8px; align-self: flex-start; margin-top: 2px; }
.icon-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 4px; display: flex; align-items: center; justify-content: center; border-radius: 50%;
}
.icon-btn:hover { color: var(--danger); background: var(--surface-2); }

/* 입력창 */
.composer-wrap { margin: 12px 20px 16px; flex-shrink: 0; }
.composer {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border-radius: 20px;
  padding: 6px 6px 6px 12px;
}
.attach-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 4px; flex-shrink: 0;
}
.attach-btn:hover { color: var(--accent); }
.composer-image-preview { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; padding-left: 4px; }
.composer-image-preview img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; }
.composer-image-preview button {
  background: var(--surface-2); border: none; border-radius: 50%; width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); padding: 0;
}
.bubble-image { max-width: 200px; border-radius: 12px; display: block; margin-bottom: 6px; }
.composer input { flex: 1; border: none; background: transparent; font-size: 13px; font-family: inherit; outline: none; }
.send-btn {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent);
  color: #fff; border: none; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.send-btn:hover { background: var(--accent-hover); }
.send-icon {
  width: 0; height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 10px solid #fff;
  margin-left: 3px;
}

/* 시트/모달 공통 */
.sheet-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  align-items: flex-end; justify-content: center; z-index: 50;
}
.sheet-backdrop.open { display: flex; }
.sheet {
  background: var(--surface); width: 100%; max-width: 480px;
  border-radius: 20px 20px 0 0; padding: 8px; margin-bottom: 0;
}
.sheet-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: none; border: none; text-align: left; padding: 14px 12px;
  font-size: 14px; color: var(--ink); cursor: pointer; border-radius: 12px;
  text-decoration: none; box-sizing: border-box;
}
.sheet-item:hover { background: var(--surface-2); }

.modal {
  background: var(--surface); width: 100%; max-width: 380px;
  border-radius: 20px; padding: 20px; margin-bottom: 40px;
}
.modal-title { font-size: 15px; font-weight: 500; margin: 0 0 14px; }
.modal-question { font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin: 0 0 12px; }
.modal input, .modal textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; font-size: 14px; font-family: inherit; margin-bottom: 10px; resize: none;
}
.modal-error { color: var(--danger); font-size: 12px; margin: -4px 0 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.btn-ghost, .btn-primary {
  border: none; border-radius: 20px; padding: 8px 16px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.btn-ghost { background: none; color: var(--muted); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.avatar-preview {
  width: 88px; height: 88px; border-radius: 50%; background: var(--surface-2);
  background-size: cover; background-position: center; margin: 0 auto 14px;
}
.preset-row { display: flex; gap: 8px; margin-bottom: 10px; }
.preset-btn {
  flex: 1; border: 1px solid var(--line); background: none; border-radius: 20px;
  padding: 8px 0; font-size: 13px; cursor: pointer; font-family: inherit; color: var(--ink);
}
.preset-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.expression-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.expression-btn {
  width: 38px; height: 38px; border-radius: 50%; background: var(--surface-2);
  border: 1px solid var(--line); cursor: pointer; padding: 0;
  background-size: cover; background-position: center; flex-shrink: 0;
}
.expression-label { font-size: 12px; color: var(--muted); }
.expression-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.expression-picker button {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: none; border-radius: 20px;
  padding: 4px 12px 4px 4px; font-size: 12px; cursor: pointer; font-family: inherit; color: var(--ink);
}
.expression-picker button img {
  width: 22px; height: 22px; border-radius: 50%; object-fit: cover; background: var(--surface-2);
}
.expression-picker button.active { border-color: var(--accent); color: var(--accent); }

.expr-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.expr-chip {
  display: flex; align-items: center; gap: 6px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 20px; padding: 4px 10px 4px 4px; font-size: 12px;
}
.expr-chip img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }
.expr-chip button { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0; display: flex; }
.expr-add-row { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; flex-wrap: wrap; }
.expr-add-row input[type="text"] { flex: 1; min-width: 100px; margin-bottom: 0; }
.expr-add-row input[type="file"] { flex: 1; min-width: 110px; font-size: 12px; }

.profile-modal { max-height: 85vh; display: flex; flex-direction: column; }
.settings-scroll { overflow-y: auto; padding-right: 2px; }
.settings-scroll label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; }
.settings-scroll label:first-child { margin-top: 0; }

.avatar-row { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.avatar-preview {
  width: 56px; height: 56px; border-radius: 50%; background: var(--surface-2);
  background-size: cover; background-position: center; flex-shrink: 0;
}
.bg-preview {
  width: 72px; height: 44px; border-radius: 8px; background: var(--surface-2);
  background-size: cover; background-position: center; flex-shrink: 0;
}

.color-row { display: flex; gap: 10px; }
.color-swatch {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent;
  padding: 0; cursor: pointer;
}
.color-swatch.active { border-color: var(--ink); }

.two-col { display: flex; gap: 8px; }
.two-col input { flex: 1; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; }
.toggle-row span { font-size: 13px; }
.toggle-switch {
  width: 42px; height: 24px; border-radius: 20px; background: var(--line);
  border: none; padding: 2px; cursor: pointer; position: relative; flex-shrink: 0;
}
.toggle-switch[aria-pressed="true"] { background: var(--accent); }
.toggle-knob {
  display: block; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform 0.15s;
}
.toggle-switch[aria-pressed="true"] .toggle-knob { transform: translateX(18px); }

/* 랜딩 페이지 */
#landing {
  max-width: 380px; margin: 40px auto; padding: 28px 24px;
  background: var(--surface); border-radius: 20px;
}
@media (min-width: 481px) {
  #landing { box-shadow: 0 24px 60px rgba(0,0,0,0.12); }
}
.landing-title { font-family: 'Jua', sans-serif; font-size: 24px; font-weight: 400; line-height: 1.5; margin: 0 0 8px; text-align: center; }
.landing-sub { font-size: 13px; color: var(--muted); margin: 0 0 24px; text-align: center; }
.landing-tabs { display: flex; gap: 6px; background: var(--surface-2); border-radius: 20px; padding: 4px; margin-bottom: 20px; }
.tab-btn {
  flex: 1; border: none; background: none; border-radius: 16px; padding: 8px 0;
  font-size: 13px; font-family: inherit; cursor: pointer; color: var(--muted);
}
.tab-btn.active { background: var(--surface); color: var(--ink); font-weight: 500; }
.landing-form label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
.landing-form label:first-of-type { margin-top: 0; }
.landing-form input {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; font-size: 14px; font-family: inherit;
}
.theme-row { display: flex; gap: 8px; }
.theme-btn {
  flex: 1; border: 1px solid var(--line); background: none; border-radius: 12px;
  padding: 12px 10px; cursor: pointer; font-family: inherit; text-align: left;
  display: flex; flex-direction: column; gap: 2px;
}
.theme-btn.active { border-color: var(--accent); border-width: 2px; }
.theme-name { font-size: 12px; font-weight: 500; }
.theme-sub { font-size: 11px; color: var(--muted); }
.btn-primary.wide { width: 100%; margin-top: 18px; padding: 11px 0; font-size: 14px; }
.warning-note {
  font-size: 12px; color: var(--danger); background: var(--surface-2);
  border-radius: 8px; padding: 8px 10px; margin: 4px 0 0; line-height: 1.5;
}

.corner-deco-item {
  display: none;
  position: fixed;
  height: auto;
  z-index: 5;
  pointer-events: none;
}
@media (min-width: 900px) {
  .corner-deco-item { display: block; }
}

.deco-resize-handle {
  display: none; position: fixed; width: 14px; height: 14px;
  background: var(--accent); border: 2px solid #fff; border-radius: 50%;
  cursor: nwse-resize; z-index: 6;
}
.deco-resize-handle.visible { display: block; }

.deco-adjust-done {
  display: none; position: fixed; top: 16px; right: 16px; z-index: 10;
  background: var(--accent); color: #fff; border: none; border-radius: 20px;
  padding: 10px 18px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.deco-adjust-done.visible { display: block; }

.deco-order-toolbar {
  position: fixed; display: flex; gap: 4px; z-index: 20;
  background: var(--ink); border-radius: 20px; padding: 3px;
}
.deco-order-toolbar button {
  border: none; background: none; color: #fff; font-size: 11px;
  border-radius: 16px; padding: 4px 8px; cursor: pointer; font-family: inherit;
}
.deco-order-toolbar button:hover { background: rgba(255,255,255,0.2); }

/* 장식 목록(프로필 설정) */
.deco-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.deco-item { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.deco-item-row { display: flex; align-items: center; gap: 8px; }
.deco-item-row img { width: 32px; height: 32px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.deco-item-label { flex: 1; font-size: 12px; color: var(--muted); }
.deco-item-row button {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 4px; display: flex; align-items: center; justify-content: center;
}
.deco-item-row button:hover { color: var(--ink); }
.deco-settings {
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line);
  display: flex; flex-direction: column; gap: 6px;
}
.deco-settings input[type="text"], .deco-settings textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; font-size: 12px; font-family: inherit; margin: 0;
}
.deco-settings input[type="file"] { font-size: 12px; }
.deco-settings textarea { resize: vertical; min-height: 50px; }
.deco-check-row { display: flex; gap: 14px; font-size: 12px; color: var(--ink); }
.deco-check-row label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.deco-settings-note { font-size: 11px; color: var(--muted); margin: 0; }

/* 장식 클릭 반응 */
@keyframes decoBounce {
  0% { transform: scale(1); }
  30% { transform: scale(1.15) translateY(-6px); }
  60% { transform: scale(0.95) translateY(2px); }
  100% { transform: scale(1); }
}
.deco-bounce-anim { animation: decoBounce 0.4s ease; }

@keyframes decoSparkleFly {
  0% { transform: translate(0, 0) scale(0.6); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; }
}
.deco-sparkle {
  position: fixed; width: 8px; height: 8px; border-radius: 50%;
  background: #FFD84D; pointer-events: none; z-index: 7;
  animation: decoSparkleFly 0.6s ease-out forwards;
}

.deco-speech-bubble {
  position: fixed; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px;
  font-size: 12px; max-width: 180px; z-index: 8;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.deco-speech-bubble.show { opacity: 1; }
