/* ==========================================================
   월하(月下) 사주 채팅 - 본 사이트 UI(480px 밝은 셸)에 맞춤
   상단: 캐릭터 야경 히어로 카드 / 하단: 밝은 대화 영역
   ========================================================== */

:root {
  --primary: #7C3AED;
  --primary-dark: #6D28D9;
  --primary-soft: #F3EEFF;
  --primary-border: #E4DAFB;
  --gold: #E8C878;
  --text-main: #1F2430;
  --text-sub: #6B7280;
  --page-bg: #E5E7EB;
  --hero-1: #1B1740;
  --hero-2: #2E2358;
  --hero-3: #402C74;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: 'Gowun Batang', 'Noto Serif KR', Georgia, serif;
  background: var(--page-bg);
  color: var(--text-main);
  letter-spacing: -0.01em;
}

/* ---------- 480px 모바일 셸 ---------- */
.chat-container {
  position: relative;
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  background: #FFFFFF;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06);
}

/* ==========================================================
   1) 캐릭터 야경 히어로 카드
   ========================================================== */
.wolha-hero {
  position: relative;
  flex-shrink: 0;
  height: 42dvh;
  min-height: 300px;
  max-height: 420px;
  background: linear-gradient(165deg, var(--hero-1) 0%, var(--hero-2) 55%, var(--hero-3) 100%);
  border-radius: 0 0 26px 26px;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(43, 33, 83, 0.22);
}

/* 상단 바 (뒤로 / 이름·상태 / 새로하기) */
.chat-topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px calc(14px + env(safe-area-inset-top));
}

.topbar-btn {
  width: 38px; height: 38px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s;
}

.topbar-btn:hover { background: rgba(255, 255, 255, 0.28); }
.topbar-btn:active { transform: scale(0.94); }
.topbar-btn svg { width: 19px; height: 19px; fill: #FFFFFF; }

.topbar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: center;
}

.topbar-name {
  font-size: 16px;
  font-weight: 700;
  color: #FFFFFF;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.3);
}

.topbar-name em {
  font-style: normal;
  font-size: 12px;
  color: var(--gold);
  margin-left: 3px;
}

.topbar-status {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #6EE7A0;
  box-shadow: 0 0 6px #6EE7A0;
  animation: dot-pulse 2s ease-in-out infinite;
}

@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* 별밭 */
.stars { position: absolute; inset: 0; pointer-events: none; }

.stars::before {
  content: "";
  position: absolute;
  width: 2px; height: 2px;
  border-radius: 50%;
  box-shadow:
    36px 60px #FFF3C4, 120px 40px #C9C2F0, 210px 90px #FFFFFF,
    300px 54px #C9C2F0, 380px 120px #FFF3C4, 60px 150px #FFFFFF,
    160px 200px #C9C2F0, 260px 150px #FFF3C4, 350px 210px #FFFFFF,
    40px 250px #C9C2F0, 140px 300px #FFF3C4, 240px 260px #FFFFFF,
    420px 180px #C9C2F0, 90px 360px #FFF3C4, 320px 330px #FFFFFF;
  animation: twinkle-stars 4s ease-in-out infinite;
}

.stars-2::before {
  box-shadow:
    80px 100px #FFFFFF, 190px 70px #FFF3C4, 280px 120px #C9C2F0,
    370px 90px #FFFFFF, 24px 200px #FFF3C4, 130px 250px #FFFFFF,
    240px 210px #C9C2F0, 330px 280px #FFF3C4, 100px 320px #FFFFFF,
    200px 350px #C9C2F0, 300px 360px #FFF3C4, 440px 260px #FFFFFF;
  animation-delay: 2s;
}

@keyframes twinkle-stars {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 0.35; }
}

/* 캐릭터 SVG */
.wolha {
  height: 96%;
  width: auto;
  max-width: 96%;
  filter: drop-shadow(0 6px 20px rgba(0, 0, 0, 0.28));
  z-index: 1;
}

.wolha-float { animation: floaty 6s ease-in-out infinite; }

@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.eye { transform-box: fill-box; transform-origin: center; animation: blink 5.2s infinite; }
.eye-r { animation-delay: 0.04s; }

@keyframes blink {
  0%, 91%, 100% { transform: scaleY(1); }
  94% { transform: scaleY(0.06); }
  97% { transform: scaleY(1); }
}

.orb { animation: orb-pulse 3.4s ease-in-out infinite; }
.orb-halo, .moon-halo { transform-box: fill-box; transform-origin: center; }
.orb-halo { animation: halo-pulse 3.4s ease-in-out infinite; }
.moon-halo { animation: halo-pulse 8s ease-in-out infinite; }

@keyframes orb-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.82; } }
@keyframes halo-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.6; }
}

.sparkle { transform-box: fill-box; transform-origin: center; animation: twinkle 3s ease-in-out infinite; }
.s2 { animation-delay: 0.6s; }
.s3 { animation-delay: 1.2s; }
.s4 { animation-delay: 1.8s; }
.s5 { animation-delay: 2.4s; }
.s6 { animation-delay: 0.9s; }

@keyframes twinkle {
  0%, 100% { opacity: 0.15; transform: scale(0.7) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.15) rotate(24deg); }
}

/* ==========================================================
   2) 밝은 대화 영역
   ========================================================== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #FAFAFC;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: #E5E8EB transparent;
}

.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-thumb { background: #E5E8EB; border-radius: 4px; }

.msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: msg-in 0.32s ease both;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-bot { align-self: flex-start; }
.msg-user { align-self: flex-end; flex-direction: row-reverse; }

.msg-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8B5CF6, var(--primary));
  color: #FFF3C4;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  box-shadow: 0 2px 6px rgba(124, 58, 237, 0.28);
}

.bubble {
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.7;
  word-break: keep-all;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.msg-bot .bubble {
  background: #FFFFFF;
  border: 1px solid #EEF0F3;
  color: #333D4B;
  border-top-left-radius: 5px;
  box-shadow: 0 1px 3px rgba(17, 17, 17, 0.04);
}

.msg-user .bubble {
  background: linear-gradient(135deg, #8B5CF6, var(--primary));
  color: #FFFFFF;
  border-top-right-radius: 5px;
  box-shadow: 0 3px 10px rgba(124, 58, 237, 0.28);
}

/* 타이핑 */
.typing-dots { display: inline-flex; gap: 5px; padding: 3px 2px; }
.typing-dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #C4C9D4;
  animation: dot-bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ---------- 사주 결과 카드 (밝은 톤) ---------- */
.saju-card {
  background: linear-gradient(160deg, #F7F5FF 0%, #FCFBFF 100%);
  border: 1px solid var(--primary-border);
  border-radius: 16px;
  padding: 16px 14px;
  margin-top: 2px;
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.06);
}

.saju-card-title {
  text-align: center;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 13px;
  letter-spacing: 0.5px;
}

.pillars {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-bottom: 13px;
}

.pillar {
  text-align: center;
  background: #FFFFFF;
  border: 1px solid #EDEAF7;
  border-radius: 11px;
  padding: 9px 3px;
}

.pillar-label { font-size: 10.5px; color: var(--text-sub); margin-bottom: 5px; }

.pillar-char { font-size: 19px; font-weight: 700; line-height: 1.35; color: #2C2440; }

.pillar-el {
  display: inline-block;
  font-size: 9.5px;
  margin-top: 5px;
  padding: 2px 7px;
  border-radius: 9px;
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.el-wood { color: #2F9E63; }
.el-fire { color: #E0574F; }
.el-earth { color: #C99A2E; }
.el-metal { color: #7A8290; }
.el-water { color: #3A72CE; }

.element-bars { display: flex; flex-direction: column; gap: 5px; }

.el-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.el-row .el-name { width: 44px; flex-shrink: 0; font-weight: 600; }
.el-row .el-dots { letter-spacing: 3px; font-size: 11px; }

/* ---------- 빠른 답장 칩 ---------- */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px;
  flex-shrink: 0;
  background: #FAFAFC;
}

.quick-replies:not(:empty) { padding-top: 4px; padding-bottom: 12px; }

.chip {
  border: 1px solid var(--primary-border);
  background: #FFFFFF;
  color: var(--primary-dark);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 15px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.18s, transform 0.15s, border-color 0.18s;
  animation: msg-in 0.32s ease both;
}

.chip:hover { background: var(--primary-soft); border-color: var(--primary); }
.chip:active { transform: scale(0.96); }

/* 생년월일 선택 버블 */
.birth-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  margin-top: 6px;
}

.birth-picker select {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid #E5E8EB;
  background: #F9FAFB;
  color: var(--text-main);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%238B95A1' d='M5 6L0 0h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.birth-picker .confirm-btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, #8B5CF6, var(--primary));
  color: #FFFFFF;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
}

.birth-picker .confirm-btn:hover { opacity: 0.9; }
.birth-picker .confirm-btn:active { transform: scale(0.96); }

/* ---------- 입력창 ---------- */
.chat-input {
  display: flex;
  gap: 9px;
  padding: 11px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid #EEF0F3;
  flex-shrink: 0;
  background: #FFFFFF;
}

.chat-input input {
  flex: 1;
  font-family: inherit;
  font-size: 15px;
  padding: 12px 16px;
  border-radius: 22px;
  border: 1px solid #E5E8EB;
  background: #F7F8FA;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

.chat-input input:focus { border-color: var(--primary); background: #FFFFFF; }
.chat-input input::placeholder { color: #ADB5BD; }
.chat-input input:disabled { opacity: 0.55; cursor: not-allowed; }

.chat-input button {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #8B5CF6, var(--primary));
  color: #FFFFFF;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.2s;
  box-shadow: 0 3px 10px rgba(124, 58, 237, 0.3);
}

.chat-input button:hover:not(:disabled) { transform: scale(1.06); }
.chat-input button:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

/* ---------- 작은 화면 대응 ---------- */
@media (max-height: 680px) {
  .wolha-hero { height: 36dvh; min-height: 250px; }
}

@media (prefers-reduced-motion: reduce) {
  .wolha-float, .eye, .orb, .orb-halo, .moon-halo, .sparkle,
  .stars::before, .status-dot { animation: none !important; }
}
