:root {
  --pink: #ffb3ba;
  --purple: #ba9ce8;
  --pink-deep: #ff8fa3;
  --purple-deep: #9b7bd1;
  --bg-deep: #f7eefb;
  --surface: #ffffff;
  --text: #3a2b4a;
  --text-muted: #7a6a8a;
  --text-faint: #a698b5;
  --border: #ecdcf5;
  --radius-lg: 20px;
  --radius-md: 14px;
  --shadow-card: 0 2px 10px rgba(155, 96, 189, 0.08);
  --shadow-soft: 0 10px 30px rgba(155, 96, 189, 0.16);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--pink) 0%, var(--purple) 100%);
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  box-shadow: var(--shadow-card);
}
.brand-name {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--purple-deep);
}

.new-chat-btn {
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--pink-deep), var(--purple-deep));
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 18px;
}
.new-chat-btn:hover { filter: brightness(1.05); }

.conv-list {
  flex: 1;
  overflow-y: auto;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
}
.conv-item.active {
  background: var(--bg-deep);
  color: var(--text);
  font-weight: 600;
}

.account-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-md);
  background: var(--bg-deep);
  margin-bottom: 12px;
}
.account-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--pink-deep), var(--purple-deep));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  overflow: hidden;
}
.account-avatar img { width: 100%; height: 100%; object-fit: cover; }
.account-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.account-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-sub {
  font-size: 0.7rem;
  color: var(--text-faint);
}
.auth-btn {
  border: 1px solid var(--purple);
  background: var(--surface);
  color: var(--purple-deep);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.credit-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--bg-deep);
  color: var(--purple-deep);
  font-weight: 700;
  font-size: 0.85rem;
}
.credit-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pink-deep);
}
.settings-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.settings-btn:hover { border-color: var(--purple); color: var(--purple-deep); }

/* ---------- Main ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--bg-deep) 0%, #fff 60%);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(6px);
}
.mood-badge {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-deep);
  color: var(--purple-deep);
}
.topbar-right { display: flex; gap: 10px; }
.model-desc {
  margin: 0;
  padding: 6px 24px;
  font-size: 0.75rem;
  color: var(--text-faint);
  text-align: right;
  background: rgba(255,255,255,0.5);
  border-bottom: 1px solid var(--border);
}
.select {
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
}

.chat-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 무작위로 나타나는 빨드 스티커 (터치하면 크레딧 보너스) */
.sticker {
  position: absolute;
  width: 56px;
  height: 56px;
  border: none;
  background: transparent;
  cursor: pointer;
  z-index: 20;
  animation: sticker-pop 0.4s ease;
  filter: drop-shadow(0 4px 10px rgba(155, 96, 189, 0.35));
}
.sticker img { width: 100%; height: 100%; border-radius: 50%; }
.sticker-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--pink-deep);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 999px;
  box-shadow: var(--shadow-card);
}
@keyframes sticker-pop {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.msg {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 720px;
}
.msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: var(--shadow-card);
}
.user-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--pink-deep), var(--purple-deep));
  color: #fff;
  font-size: 0.55rem;
  font-weight: 800;
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.bubble-image {
  display: block;
  max-width: 260px;
  max-height: 260px;
  border-radius: 10px;
  margin-bottom: 6px;
  object-fit: cover;
}
.bubble {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  line-height: 1.55;
  font-size: 0.95rem;
  box-shadow: var(--shadow-card);
  white-space: pre-wrap;
}
.msg.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.user .bubble {
  background: linear-gradient(90deg, var(--pink-deep), var(--purple-deep));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.snack .bubble {
  background: #fff4e6;
  border: 1px dashed #f0b429;
  color: #8a5a00;
  font-size: 0.85rem;
}
.msg.error .bubble {
  background: #fff0f0;
  border: 1px solid #ffb3b3;
  color: #a33;
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,0.85);
}
.composer-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.attach-preview {
  position: relative;
  width: 72px;
}
.attach-preview img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.attach-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--pink-deep);
  color: #fff;
  font-size: 0.7rem;
  cursor: pointer;
  line-height: 1;
}
.icon-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-md);
  font-size: 1.05rem;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--purple); }
.input {
  flex: 1;
  resize: none;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font-size: 0.95rem;
  font-family: inherit;
  max-height: 140px;
}
.input:focus { outline: none; border-color: var(--purple); }
.send-btn {
  padding: 0 22px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--pink-deep), var(--purple-deep));
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(58, 43, 74, 0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 420px;
  max-width: 92vw;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  font-weight: 800;
  border-bottom: 1px solid var(--border);
}
.modal-close {
  border: none;
  background: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-muted);
}
.modal-body {
  padding: 18px 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  flex: 1;
}
.field input {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  font-size: 0.9rem;
}
.field-row { display: flex; gap: 10px; align-items: flex-end; }
.secondary-btn {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--purple);
  background: var(--bg-deep);
  color: var(--purple-deep);
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.hint {
  font-size: 0.78rem;
  color: var(--text-faint);
  line-height: 1.5;
  margin: 0;
}
.divider {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}

.notices-body {
  max-height: 70vh;
  overflow-y: auto;
}
.notice-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 12px;
  overflow: hidden;
}
.notice-card:last-child { margin-bottom: 0; }
.notice-image {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  float: left;
  margin: 0 12px 8px 0;
  box-shadow: var(--shadow-card);
}
.notice-card h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--text);
}
.notice-card p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ---------- 화면 비율 자동 인식 (모바일 / PC 반응형) ---------- */
.menu-toggle {
  display: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-md);
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(58, 43, 74, 0.35);
  z-index: 39;
}
.sidebar-backdrop.open { display: block; }

/* 메시지/이미지가 화면 폭에 비례해서 줄어들도록(초광폭 PC ~ 좁은 모바일 공통 대응) */
.msg { max-width: min(720px, 88vw); }
.bubble-image { max-width: min(260px, 60vw); max-height: min(260px, 60vw); }

@media (max-width: 720px) {
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 82vw;
    max-width: 300px;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 40;
    box-shadow: var(--shadow-soft);
  }
  .sidebar.open { transform: translateX(0); }

  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px;
  }
  .topbar-left { flex: 1 1 auto; min-width: 0; gap: 8px; }
  .mood-badge {
    font-size: 0.72rem;
    padding: 5px 9px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar-right {
    flex: 1 1 100%;
    flex-wrap: wrap;
  }
  .select { flex: 1 1 45%; min-width: 0; font-size: 0.8rem; }
  .model-desc { padding: 6px 14px; text-align: left; }

  .chat { padding: 14px; }
  .composer { padding: 12px 14px 16px; }
  .icon-btn { width: 36px; height: 36px; font-size: 0.95rem; }
}

@media (max-width: 420px) {
  .select { flex: 1 1 100%; }
  .brand-name { font-size: 1rem; }
}
