/* Pretendard 로드 */
@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.css");

/* 라이트 테마 */
:root {
  --bg-color: #e5e5e7;
  --text-color: #1d1d1f;
  --blob-color: #000000;
  --eye-color-bg: #ffffff;
  --pupil-color: #000000;
  --toggle-moon-stroke: #1e1e1e;
  --active-indicator-bg: #ffffff;
  --active-indicator-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --bubble-tail-bg: #f2f2f5;
}

/* 다크 테마 */
html[data-theme="dark"] {
  --bg-color: #1e1e1e;
  --text-color: #f5f5f7;
  --blob-color: #000000;
  --eye-color-bg: #ffb938;
  --pupil-color: #000000;
  --toggle-moon-stroke: #f5f5f7;
  --active-indicator-bg: rgba(255, 255, 255, 0.12);
  --active-indicator-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.05), 0 1px 2px rgba(0, 0, 0, 0.25);
  --bubble-tail-bg: #353537;
}

/* 오션 테마 */
html[data-theme="ocean"] {
  --bg-color: #1e1e1e;
  --text-color: #f5f5f7;
  --blob-color: #000000;
  --eye-color-bg: #48FFD1;
  --pupil-color: #000000;
  --toggle-moon-stroke: #f5f5f7;
  --active-indicator-bg: rgba(255, 255, 255, 0.12);
  --active-indicator-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.05), 0 1px 2px rgba(0, 0, 0, 0.25);
  --bubble-tail-bg: #353537;
}

/* 블랙 테마 */
html[data-theme="black"] {
  --bg-color: #000000;
  --text-color: #f5f5f7;
  --blob-color: #000000;
  --eye-color-bg: #ffb938;
  --pupil-color: #000000;
  --toggle-moon-stroke: #f5f5f7;
  --active-indicator-bg: rgba(255, 255, 255, 0.12);
  --active-indicator-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.05), 0 1px 2px rgba(0, 0, 0, 0.25);
  --bubble-tail-bg: #1f1f1f;
}

/* 시스템 다크 모드 동기화 */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]):not([data-theme="ocean"]):not([data-theme="black"]) {
    --bg-color: #1e1e1e;
    --text-color: #f5f5f7;
    --blob-color: #000000;
    --eye-color-bg: #ffb938;
    --pupil-color: #000000;
    --toggle-moon-stroke: #f5f5f7;
    --active-indicator-bg: rgba(255, 255, 255, 0.12);
    --active-indicator-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.05), 0 1px 2px rgba(0, 0, 0, 0.25);
    --bubble-tail-bg: #353537;
  }
}

/* 전역 레이아웃 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: 'Pretendard', -apple-system, system-ui, Roboto, sans-serif;
  transition: background-color 0.6s cubic-bezier(0.4, 0, 0.2, 1),
    color 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.character-container {
  position: relative;
  /* 자식 absolute 위치 지정을 위해 추가 */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  user-select: none;
}

.blob-svg {
  width: 130px;
  height: auto;
  overflow: visible;
  transform-origin: bottom center;
}

/* flinch 애니메이션 */
.blob-svg.flinch {
  animation: flinch-anim 0.5s cubic-bezier(0.25, 1, 0.5, 1);
}

@keyframes flinch-anim {
  0% {
    transform: scale(1) translateY(0);
  }

  20% {
    transform: scale(0.96, 1.04) translateY(-4px);
  }

  40% {
    transform: scale(1.04, 0.96) translateY(1.5px);
  }

  70% {
    transform: scale(0.99, 1.01) translateY(-0.5px);
  }

  100% {
    transform: scale(1) translateY(0);
  }
}

/* wiggle 애니메이션 */
.ear-group {
  fill: var(--blob-color);
  transform-box: fill-box;
  transition: fill 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

#left-ear {
  transform-origin: bottom right;
}

#right-ear {
  transform-origin: bottom left;
}

.ear-group.wiggle-left {
  animation: wiggle-l 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.ear-group.wiggle-right {
  animation: wiggle-r 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes wiggle-l {

  0%,
  100% {
    transform: rotate(0deg);
  }

  25% {
    transform: rotate(-16deg);
  }

  60% {
    transform: rotate(8deg);
  }

  80% {
    transform: rotate(-3deg);
  }
}

@keyframes wiggle-r {

  0%,
  100% {
    transform: rotate(0deg);
  }

  25% {
    transform: rotate(16deg);
  }

  60% {
    transform: rotate(-8deg);
  }

  80% {
    transform: rotate(3deg);
  }
}

.blob-body {
  fill: var(--blob-color);
  transition: fill 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 눈 스타일 정의 */
.eye-group {
  transform-origin: center;
  transform-box: fill-box;
  transition: transform 0.12s cubic-bezier(0.4, 0, 0.2, 1);
}

.eye-bg {
  fill: var(--eye-color-bg);
  stroke: transparent;
  stroke-width: 0;
  transition: fill 0.5s cubic-bezier(0.4, 0, 0.2, 1),
    stroke 0.5s cubic-bezier(0.4, 0, 0.2, 1),
    stroke-width 0.3s ease;
}

.pupil {
  fill: var(--pupil-color);
  transition: fill 0.5s cubic-bezier(0.4, 0, 0.2, 1),
    rx 0.25s cubic-bezier(0.4, 0, 0.2, 1),
    ry 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 대기 상태 */
.eye-group.eyes-filled .pupil {
  rx: 13.5px;
  ry: 13.5px;
}

/* blinking 상태 */
.eye-group.blinking {
  transform: scaleY(0);
}

/* 하단 텍스트 */
.status-text {
  font-family: 'Pretendard', sans-serif;
  font-size: 1.3rem;
  font-weight: 500;
  opacity: 0.9;
  transition: color 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  min-height: 1.6em;
  /* 레이아웃 흔들림 방지 */
}

/* 개별 글자 공통 스타일 */
.status-text .char {
  display: inline-block;
  transform-origin: center;
  transition: transform 0.5s cubic-bezier(0.25, 1, 0.5, 1),
    opacity 0.5s cubic-bezier(0.25, 1, 0.5, 1),
    filter 0.5s cubic-bezier(0.25, 1, 0.5, 1);
  transition-delay: var(--delay);
  white-space: pre;
}

/* 1. 사라지는 애니메이션 (흩어짐 + 잔상 효과) */
.status-text.scattering-out .char {
  transform: translate(var(--rx), var(--ry)) rotate(var(--rot)) scale(0.3);
  opacity: 0;
  filter: blur(8px);
  color: var(--text-color);
  text-shadow: 0 0 8px var(--text-color),
    0 0 16px var(--text-color);
}

/* 2. 나타나는 애니메이션 (바깥에서 모여들기) */
.status-text.scattering-in .char {
  animation: scatter-in-anim 0.6s cubic-bezier(0.25, 1, 0.5, 1) forwards;
  animation-delay: var(--delay);
  opacity: 0;
  filter: blur(8px);
}

@keyframes scatter-in-anim {
  0% {
    transform: translate(calc(var(--rx) * 0.5), calc(var(--ry) * 0.5)) rotate(calc(var(--rot) * -0.5)) scale(1.5);
    opacity: 0;
    filter: blur(8px);
    text-shadow: 0 0 8px var(--text-color);
  }

  100% {
    transform: translate(0, 0) rotate(0deg) scale(1);
    opacity: 1;
    filter: blur(0);
    text-shadow: none;
  }
}

/* 플로팅 컨트롤 공통 컨테이너 */
.floating-control-container {
  position: absolute;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 44px;
  z-index: 1000;
}

.theme-selector-container {
  bottom: 24px;
}

.lang-selector-container {
  bottom: 80px;
}

/* 슬라이딩 옵션 패널 공통 */
.sliding-panel {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 22px;
  padding: 6px 14px;
  opacity: 0;
  transform: translateX(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html[data-theme="light"] .sliding-panel {
  background: rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.floating-control-container:hover .sliding-panel,
.floating-control-container.active .sliding-panel {
  opacity: 1;
  transform: translateX(0) scale(1);
  pointer-events: auto;
}

/* 슬라이딩 탭 액티브 인디케이터 */
.active-indicator {
  position: absolute;
  background: var(--active-indicator-bg);
  box-shadow: var(--active-indicator-shadow);
  border-radius: 50%;
  transition: all 0.35s cubic-bezier(0.25, 1, 0.5, 1);
  z-index: 1;
  pointer-events: none;
}

/* 개별 옵션 선택 버튼 */
.control-opt-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, color 0.2s;
  padding: 0;
  font-family: 'Outfit', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-color);
  user-select: none;
  position: relative;
  z-index: 2;
}

.control-opt-btn:hover {
  transform: scale(1.15);
}

/* 테마 표시용 컬러 도트 */
.theme-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.light-dot {
  background: linear-gradient(135deg, #ffffff 50%, #e5e5e7 50%);
}

.dark-dot {
  background: linear-gradient(135deg, #ffb938 50%, #1e1e1e 50%);
}

.ocean-dot {
  background: linear-gradient(135deg, #48FFD1 50%, #1e1e1e 50%);
}

.black-dot {
  background: linear-gradient(135deg, #ffb938 50%, #000000 50%);
}

/* 메인 플로팅 토글 버튼 공통 */
.control-toggle-btn {
  width: 44px;
  height: 44px;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  outline: none;
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  color: var(--text-color);
}

.control-toggle-btn:hover {
  transform: scale(1.1);
}

.control-toggle-btn svg {
  width: 32px;
  height: 32px;
  pointer-events: none;
}

/* 테마 선택기의 sun/moon 전환용 포지셔닝 */
.theme-toggle-btn svg {
  position: absolute;
  fill: none;
}

/* 테마 아이콘 전환 모션 */
.theme-toggle-btn .moon-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
  transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-toggle-btn .sun-icon {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
  transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

html[data-theme="dark"] .theme-toggle-btn .moon-icon,
html[data-theme="ocean"] .theme-toggle-btn .moon-icon,
html[data-theme="black"] .theme-toggle-btn .moon-icon {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

html[data-theme="dark"] .theme-toggle-btn .sun-icon,
html[data-theme="ocean"] .theme-toggle-btn .sun-icon,
html[data-theme="black"] .theme-toggle-btn .sun-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]):not([data-theme="ocean"]):not([data-theme="black"]) .theme-toggle-btn .moon-icon {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
  }

  html:not([data-theme="light"]):not([data-theme="ocean"]):not([data-theme="black"]) .theme-toggle-btn .sun-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
  }
}

/* 말풍선 */
.speech-bubble {
  position: absolute;
  bottom: 165px;
  left: 50%;
  transform: translateX(-50%) scale(0.8) translateY(10px);
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 18px;
  padding: 10px 18px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-color);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
    transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 100;
  text-align: center;
  white-space: nowrap;
}

/* 테마별 라이트 모드 스타일 */
html[data-theme="light"] .speech-bubble {
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.08);
}

.speech-bubble.show {
  opacity: 1;
  transform: translateX(-50%) scale(1) translateY(0);
  pointer-events: auto;
}

/* 말풍선 꼬리 */
.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 12px;
  height: 12px;
  background: var(--bubble-tail-bg);
  border-right: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  z-index: 101;
  clip-path: polygon(100% -10%, 100% 100%, -10% 100%);
}

html[data-theme="light"] .speech-bubble::after {
  border-right: 1px solid rgba(0, 0, 0, 0.08);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

/* 말풍선 내 링크 스타일 */
.speech-bubble a {
  color: var(--text-color);
  font-weight: 700;
  text-decoration: none;
  position: relative;
  display: inline-block;
  padding: 0 2px;
}

.speech-bubble a::after {
  content: '';
  position: absolute;
  width: 100%;
  transform: scaleX(0);
  height: 2px;
  bottom: 0;
  left: 0;
  background-color: var(--text-color);
  transform-origin: bottom right;
  transition: transform 0.25s ease-out;
}

.speech-bubble a:hover::after {
  transform: scaleX(1);
  transform-origin: bottom left;
}