:root {
  /* 표면 — 민트 살짝 머금은 레이어드 톤 */
  --bg: #ffffff;
  --dot: oklch(0.91 0.008 158);  /* 배경 도트 그리드 색 (아주 연함) */
  --surface: oklch(0.995 0.003 158);
  --surface-2: oklch(0.98 0.008 158);
  --surface-3: oklch(0.965 0.012 158);
  --border: oklch(0.91 0.012 158);
  --border-soft: oklch(0.945 0.008 158);

  /* 텍스트 */
  --text: oklch(0.26 0.018 220);
  --text-dim: oklch(0.55 0.014 220);

  /* 브랜드 — 파비콘 민트톤 기준 */
  --brand: oklch(0.72 0.12 156);
  --brand-strong: oklch(0.62 0.135 154);
  --brand-deep: oklch(0.52 0.13 152);
  --brand-soft: oklch(0.95 0.038 158);
  --brand-soft-2: oklch(0.91 0.05 158);

  /* 말풍선 */
  --user-grad-a: oklch(0.63 0.135 156);
  --user-grad-b: oklch(0.54 0.14 152);
  --user-text: #ffffff;
  --ai-bubble: oklch(0.992 0.004 158);

  /* 그림자 — 얕고 넓게, 민트 머금음 */
  --shadow-sm: 0 1px 2px oklch(0.45 0.05 156 / 0.05), 0 1px 3px oklch(0.45 0.05 156 / 0.04);
  --shadow-md: 0 6px 22px oklch(0.45 0.06 156 / 0.09);
  --shadow-lg: 0 22px 52px oklch(0.4 0.06 156 / 0.14), 0 4px 14px oklch(0.4 0.05 156 / 0.06);
  --shadow-brand: 0 4px 14px oklch(0.6 0.13 154 / 0.28);

  --radius-bubble: 20px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  text-wrap: pretty;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
  min-height: 100dvh;
}

/* ===== 채팅 컨테이너 ===== */
/* 모바일: 화면 꽉 채움. 태블릿/데스크톱: 가운데 카드형 위젯 */
.chat {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 100%;
  height: 100dvh;
  background: var(--surface);
  overflow: hidden;
}

/* ===== Header ===== */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border-soft);
  background:
    linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  backdrop-filter: saturate(1.2);
  z-index: 10;
}
.avatar {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(120% 120% at 30% 22%, var(--surface) 0%, var(--brand-soft) 100%);
  border: 1px solid var(--brand-soft-2);
  box-shadow: var(--shadow-sm), inset 0 1px 0 oklch(1 0 0 / 0.7);
  overflow: hidden;
}
.avatar img {
  width: 30px;
  height: 30px;
  display: block;
}
.header-text { min-width: 0; }
.reset-btn {
  margin-left: auto;
  flex-shrink: 0;
  padding: 8px 13px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text-dim);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.18s, color 0.18s, background 0.18s, transform 0.08s, box-shadow 0.18s;
}
.reset-btn:hover {
  border-color: var(--brand);
  color: var(--brand-strong);
  background: var(--brand-soft);
  box-shadow: var(--shadow-sm);
}
.reset-btn:active { transform: scale(0.96); }
.chat-header h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.012em;
  text-wrap: balance;
}
.status {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
  animation: pulse 2.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--brand-soft); }
  50% { box-shadow: 0 0 0 6px oklch(0.72 0.12 156 / 0.1); }
}

/* ===== Messages ===== */
.messages {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px 18px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  background:
    radial-gradient(130% 45% at 50% 0%, var(--brand-soft) 0%, transparent 42%),
    radial-gradient(120% 60% at 50% 0%, var(--surface-2) 0%, var(--surface) 60%);
}
/* 은은한 스크롤바 — 화살표 버튼 없이 얇고 둥글게 */
.messages { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.messages::-webkit-scrollbar-thumb:hover { background: var(--brand-soft-2); background-clip: padding-box; }

.bubble {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: var(--radius-bubble);
  font-size: 15px;
  line-height: 1.62;
  white-space: pre-wrap;
  word-break: break-word;
  text-wrap: pretty;
  animation: pop 0.26s cubic-bezier(0.2, 0.7, 0.3, 1);
}
.bubble strong { font-weight: 700; }

@keyframes pop {
  from { opacity: 0; transform: translateY(7px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.bubble.user {
  background: linear-gradient(160deg, var(--user-grad-a) 0%, var(--user-grad-b) 100%);
  color: var(--user-text);
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 14px oklch(0.6 0.13 154 / 0.22);
}

.bubble.ai {
  background: var(--ai-bubble);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 6px;
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-sm);
}

.bubble.typing {
  display: inline-flex;
  gap: 4px;
  padding: 15px 17px;
  align-self: flex-start;
  background: var(--ai-bubble);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-bubble);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-sm);
}
.bubble.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand);
  opacity: 0.4;
  animation: blink 1.3s infinite ease-in-out;
}
.bubble.typing span:nth-child(2) { animation-delay: 0.16s; }
.bubble.typing span:nth-child(3) { animation-delay: 0.32s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

.bubble.error {
  background: oklch(0.96 0.03 25);
  color: oklch(0.45 0.15 25);
  align-self: flex-start;
  border-bottom-left-radius: 6px;
  font-size: 14px;
}

.bubble.notice {
  align-self: center;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 12px;
  max-width: 90%;
  text-align: center;
}

/* ===== 첫 화면 카테고리 버튼 ===== */
.chips {
  display: flex;
  flex-direction: column;
  gap: 9px;
  align-self: stretch;
  margin-top: 6px;
  animation: pop 0.3s cubic-bezier(0.2, 0.7, 0.3, 1);
}
.chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.18s, background 0.18s, transform 0.08s, box-shadow 0.18s, color 0.18s;
}
.chip::after {
  content: "›";
  color: var(--text-dim);
  font-size: 18px;
  font-weight: 400;
  transition: transform 0.18s, color 0.18s;
}
.chip:hover {
  border-color: var(--brand);
  background: linear-gradient(180deg, var(--surface) 0%, var(--brand-soft) 140%);
  color: var(--brand-deep);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.chip:hover::after { color: var(--brand-strong); transform: translateX(3px); }
.chip:active { transform: translateY(0) scale(0.99); }

/* ===== Composer ===== */
.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 9px;
  align-items: end;
  padding: 13px 16px calc(15px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border-soft);
  background: linear-gradient(0deg, var(--surface) 0%, var(--surface-2) 100%);
}

#input {
  resize: none;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 13px 17px;
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  outline: none;
  max-height: 140px;
  overflow-y: hidden; /* JS가 내용 넘칠 때만 auto로 토글 */
  background: var(--surface-3);
  color: var(--text);
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s;
  scrollbar-width: thin;                          /* Firefox */
  scrollbar-color: var(--border) transparent;
}
/* 입력창 스크롤바 — 화살표 버튼 없이 얇고 둥글게 (넘칠 때만 보임) */
#input::-webkit-scrollbar { width: 8px; }
#input::-webkit-scrollbar-track { background: transparent; margin: 6px 0; }
#input::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
#input::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
#input::-webkit-scrollbar-thumb:hover {
  background: var(--brand-soft-2);
  background-clip: padding-box;
}
#input:focus {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--brand-soft);
}
#input::placeholder { color: var(--text-dim); }

#send-btn {
  align-self: end;
  width: 47px;
  height: 47px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(155deg, var(--brand) 0%, var(--brand-strong) 100%);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: filter 0.18s, transform 0.08s, box-shadow 0.18s, opacity 0.18s;
  box-shadow: var(--shadow-brand);
}
#send-btn svg {
  width: 20px;
  height: 20px;
  display: block;
}
#send-btn:hover { filter: brightness(1.06); box-shadow: 0 6px 18px oklch(0.6 0.13 154 / 0.36); }
#send-btn:active { transform: scale(0.93); }
#send-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  box-shadow: none;
  filter: grayscale(0.2);
}

/* ===== 태블릿 / 데스크톱: 가운데 카드형 위젯 ===== */
@media (min-width: 640px) {
  body {
    padding: 28px;
    align-items: center; /* 카드를 세로 중앙에 — 위아래 간격 동일하게 */
    background-color: var(--bg);
    background-image: radial-gradient(var(--dot) 1.1px, transparent 1.1px);
    background-size: 22px 22px;
  }
  .chat {
    width: 100%;
    max-width: 464px;
    height: min(92dvh, 824px);
    border-radius: 26px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-soft);
  }
}

/* 태블릿: 살짝 더 넓게 */
@media (min-width: 900px) {
  .chat { max-width: 504px; height: min(90dvh, 864px); }
  .messages { padding-left: 22px; padding-right: 22px; }
}

/* 모바일: 꽉 채우고 터치 타깃 키움 */
@media (max-width: 639px) {
  .bubble { max-width: 86%; }
}

/* 모션 민감 사용자 배려 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* 다크 모드 대응 (시스템 설정 따라감) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(0.19 0.014 200);
    --dot: oklch(0.33 0.012 220);
    --surface: oklch(0.235 0.014 220);
    --surface-2: oklch(0.265 0.014 220);
    --surface-3: oklch(0.295 0.014 220);
    --border: oklch(0.34 0.014 220);
    --border-soft: oklch(0.31 0.012 220);
    --text: oklch(0.95 0.008 220);
    --text-dim: oklch(0.7 0.015 220);
    --brand: oklch(0.74 0.12 156);
    --brand-strong: oklch(0.66 0.13 154);
    --brand-deep: oklch(0.82 0.1 156);
    --brand-soft: oklch(0.33 0.05 156);
    --brand-soft-2: oklch(0.4 0.06 156);
    --ai-bubble: oklch(0.29 0.014 220);
  }
  .bubble.error { background: oklch(0.32 0.06 25); color: oklch(0.86 0.08 25); }
}
