/*
 * 기억다방 — 디자인 시스템
 * 고령층 친화형 따뜻한 감성 UI
 */

/* ─── CSS 변수 (컬러 팔레트) ─── */
:root {
  /* 배경색 */
  --color-bg-primary: #FFF8F0;
  --color-bg-secondary: #F5E6D3;
  --color-bg-card: #FFFFFF;
  --color-bg-warm: #FDF2E9;

  /* 포인트 컬러 */
  --color-primary: #A0522D;
  --color-primary-light: #C1705B;
  --color-primary-dark: #7A3B1E;
  --color-primary-hover: #8B4726;

  /* 텍스트 */
  --color-text-primary: #3E2723;
  --color-text-secondary: #5D4037;
  --color-text-muted: #8D6E63;
  --color-text-light: #A1887F;

  /* 상태색 */
  --color-success: #81A969;
  --color-warning: #E8A87C;
  --color-error: #D4796A;
  --color-info: #7FB3D8;

  /* 그림자 */
  --shadow-sm: 0 1px 3px rgba(62, 39, 35, 0.08);
  --shadow-md: 0 4px 12px rgba(62, 39, 35, 0.1);
  --shadow-lg: 0 8px 24px rgba(62, 39, 35, 0.12);

  /* 전환 */
  --transition-default: 0.4s ease-in-out;
  --transition-fast: 0.2s ease;

  /* 둥근 모서리 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;
}

/* ─── 기본 리셋 및 타이포그래피 ─── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 18px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Noto Sans KR', sans-serif;
  background-color: var(--color-bg-primary);
  color: var(--color-text-primary);
  line-height: 1.7;
  min-height: 100vh;
  padding-bottom: 80px; /* 하단 네비 여백 */
  -webkit-font-smoothing: antialiased;
}

/* ─── 고령층 접근성 유틸리티 ─── */
.text-elder {
  font-size: 1.125rem; /* 20px at 18px base */
  line-height: 1.8;
}

.text-elder-lg {
  font-size: 1.333rem; /* 24px */
  font-weight: 700;
}

.text-elder-xl {
  font-size: 1.556rem; /* 28px */
  font-weight: 700;
}

/* ─── 큰 터치 버튼 ─── */
.btn-elder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 56px;
  padding: 0.75rem 1.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-default);
  text-decoration: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn-elder:active {
  transform: scale(0.97);
}

.btn-primary {
  background-color: var(--color-primary);
  color: #FFFFFF;
}

.btn-primary:hover {
  background-color: var(--color-primary-hover);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background-color: var(--color-bg-secondary);
  color: var(--color-text-primary);
}

.btn-secondary:hover {
  background-color: #EAD5BF;
}

.btn-outline {
  background-color: transparent;
  color: var(--color-primary);
  border: 2px solid var(--color-primary);
}

.btn-outline:hover {
  background-color: var(--color-primary);
  color: #FFFFFF;
}

.btn-full {
  width: 100%;
}

/* ─── 기능 카드 ─── */
.card {
  background: var(--color-bg-card);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-default);
  border: 1px solid rgba(160, 82, 45, 0.08);
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card-feature {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2rem 1rem;
  gap: 0.75rem;
  min-height: 160px;
  cursor: pointer;
  text-decoration: none;
  color: var(--color-text-primary);
}

.card-feature .icon {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: var(--color-bg-warm);
  color: var(--color-primary);
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.card-feature .label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

/* ─── 입력 필드 ─── */
.input-elder {
  width: 100%;
  min-height: 56px;
  padding: 0.875rem 1rem;
  font-size: 1.125rem;
  font-family: inherit;
  color: var(--color-text-primary);
  background: var(--color-bg-card);
  border: 2px solid var(--color-bg-secondary);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast);
  outline: none;
}

.input-elder:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(160, 82, 45, 0.15);
}

.input-elder::placeholder {
  color: var(--color-text-light);
}

/* ─── 하단 탭 네비게이션 ─── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-bg-card);
  border-top: 1px solid rgba(160, 82, 45, 0.1);
  display: flex;
  justify-content: space-around;
  padding: 0.5rem 0;
  z-index: 100;
  box-shadow: 0 -2px 12px rgba(62, 39, 35, 0.06);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem;
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  min-width: 64px;
  min-height: 56px;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  touch-action: manipulation;
}

.nav-item:hover,
.nav-item.active {
  color: var(--color-primary);
  background: var(--color-bg-warm);
}

.nav-item .nav-icon {
  font-size: 1.5rem;
  line-height: 1;
}

/* ─── 환영 배너 ─── */
.welcome-banner {
  background: linear-gradient(135deg, var(--color-primary-light) 0%, var(--color-primary) 100%);
  color: #FFFFFF;
  border-radius: var(--radius-xl);
  padding: 2rem 1.5rem;
  margin-bottom: 1.5rem;
  position: relative;
  overflow: hidden;
}

.welcome-banner::after {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 200px;
  height: 200px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
}

.welcome-banner h1 {
  font-size: 1.556rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  position: relative;
  z-index: 1;
}

.welcome-banner p {
  font-size: 1rem;
  opacity: 0.9;
  position: relative;
  z-index: 1;
}

/* ─── 채팅 말풍선 ─── */
.chat-bubble {
  max-width: 80%;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  margin-bottom: 0.75rem;
  font-size: 1rem;
  line-height: 1.6;
  animation: fadeInUp 0.4s ease;
}

.chat-bubble-ai {
  background: var(--color-bg-warm);
  color: var(--color-text-primary);
  border-bottom-left-radius: 4px;
  margin-right: auto;
}

.chat-bubble-user {
  background: var(--color-primary);
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
  margin-left: auto;
}

/* ─── 로딩 스피너 ─── */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--color-bg-secondary);
  border-top: 4px solid var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-text {
  color: var(--color-text-muted);
  font-size: 1rem;
}

/* ─── 에러 메시지 ─── */
.error-message {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: #FFF0ED;
  color: var(--color-error);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  border-left: 4px solid var(--color-error);
}

.success-message {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: #F0F7EC;
  color: var(--color-success);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  border-left: 4px solid var(--color-success);
}

/* ─── 녹음 버튼 ─── */
.record-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--color-error);
  color: #FFFFFF;
  border: none;
  font-size: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-default);
  box-shadow: 0 4px 16px rgba(212, 121, 106, 0.3);
  touch-action: manipulation;
}

.record-btn.recording {
  animation: pulse 1.5s ease-in-out infinite;
  background: #C0392B;
}

/* ─── 페이지 컨테이너 ─── */
.page-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

/* ─── 폼 ─── */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 0.5rem;
}

/* ─── 그리드 ─── */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

/* ─── 구분선 ─── */
.divider {
  border: none;
  border-top: 1px solid rgba(160, 82, 45, 0.1);
  margin: 1.5rem 0;
}

/* ─── 애니메이션 ─── */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 4px 16px rgba(212, 121, 106, 0.3);
  }
  50% {
    transform: scale(1.08);
    box-shadow: 0 4px 24px rgba(212, 121, 106, 0.5);
  }
}

/* ─── TTS 음성 안내 버튼 ─── */
.tts-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--color-bg-secondary);
  color: var(--color-primary);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 1.25rem;
}

.tts-btn:hover {
  background: var(--color-primary);
  color: #FFFFFF;
}

/* ─── 반응형 ─── */
@media (max-width: 375px) {
  html {
    font-size: 16px;
  }
}

@media (min-width: 768px) {
  .page-container {
    max-width: 600px;
    padding: 2rem;
  }
}

/* ─── 완료 화면 (노인 친화형) ─── */
#completion-screen {
  animation: fadeIn 0.6s ease-out;
}

#completion-screen.hidden {
  display: none !important;
}

/* 내용 슬라이드업 애니메이션 */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

@keyframes bounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* 완료 화면 버튼 스타일 */
#completion-home-btn,
#completion-restart-btn {
  font-family: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 12px rgba(160, 82, 45, 0.2);
  cursor: pointer;
}

#completion-home-btn:active,
#completion-restart-btn:active {
  transform: scale(0.98) !important;
  box-shadow: 0 2px 6px rgba(160, 82, 45, 0.2);
}

/* 채팅 영역 페이드아웃 */
#chat-area.opacity-50 {
  opacity: 0.5;
  pointer-events: none;
  transition: opacity 0.4s ease-out;
}
