/* ============ Reset & Base ============ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary: #667eea;
  --primary-light: #8b9cf7;
  --primary-dark: #4c63d2;
  --accent: #f093fb;
  --accent-light: #f5b5fc;
  --girl-primary: #ff6b9d;
  --girl-secondary: #ffa3c4;
  --girl-bg: linear-gradient(135deg, #ffecd2, #fcb69f);
  --boy-primary: #4facfe;
  --boy-secondary: #6fc3ff;
  --boy-bg: linear-gradient(135deg, #a1c4fd, #c2e9fb);
  --bg-primary: #f8f9fe;
  --bg-secondary: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-light: #9ca3af;
  --border: #e5e7eb;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ============ Pages ============ */
.page {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
  transform: translateX(30px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.page.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

/* ============ Welcome Page ============ */
.welcome-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px 24px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
}

.welcome-bg-circles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.circle {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
}

.circle-1 {
  width: 300px;
  height: 300px;
  top: -80px;
  right: -60px;
  animation: float 8s ease-in-out infinite;
}

.circle-2 {
  width: 200px;
  height: 200px;
  bottom: 60px;
  left: -50px;
  animation: float 6s ease-in-out infinite reverse;
}

.circle-3 {
  width: 150px;
  height: 150px;
  top: 40%;
  right: -30px;
  animation: float 7s ease-in-out infinite 1s;
}

@keyframes float {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-20px) scale(1.05); }
}

.welcome-content {
  position: relative;
  z-index: 1;
  text-align: center;
  width: 100%;
}

.logo-container {
  margin-bottom: 48px;
}

.logo-icon {
  width: 100px;
  height: 100px;
  margin: 0 auto 16px;
  animation: pulse-soft 3s ease-in-out infinite;
}

.logo-icon svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.2));
}

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

.app-title {
  font-size: 40px;
  font-weight: 800;
  color: white;
  letter-spacing: 2px;
  margin-bottom: 8px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.app-subtitle {
  font-size: 16px;
  color: rgba(255,255,255,0.85);
  font-weight: 400;
}

.welcome-features {
  margin-bottom: 48px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.feature-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: rgba(255,255,255,0.9);
  font-size: 15px;
  padding: 10px 20px;
  background: rgba(255,255,255,0.12);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(10px);
}

.feature-icon {
  font-size: 20px;
}

.welcome-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius-xl);
  transition: all 0.25s ease;
  padding: 12px 24px;
  font-family: inherit;
}

.btn-primary {
  background: white;
  color: var(--primary);
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.btn-primary:active {
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.btn-lg {
  padding: 16px 32px;
  font-size: 17px;
  border-radius: var(--radius-xl);
}

.btn-block {
  width: 100%;
}

.btn-text {
  background: none;
  color: rgba(255,255,255,0.8);
  font-weight: 500;
}

.btn-text:active {
  color: white;
}

/* ============ Auth Pages ============ */
.auth-container {
  height: 100%;
  padding: 60px 24px 40px;
  background: var(--bg-secondary);
  overflow-y: auto;
}

.back-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-primary);
  margin-bottom: 24px;
  transition: all 0.2s;
}

.back-btn:active {
  transform: scale(0.92);
  background: var(--border);
}

.auth-header {
  margin-bottom: 36px;
}

.auth-header h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.auth-header p {
  font-size: 15px;
  color: var(--text-secondary);
}

.form-group {
  margin-bottom: 24px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.form-group input[type="text"],
.form-group input[type="number"] {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 16px;
  color: var(--text-primary);
  background: var(--bg-primary);
  transition: border-color 0.25s;
  outline: none;
  font-family: inherit;
}

.form-group input:focus {
  border-color: var(--primary);
}

.gender-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.gender-option {
  cursor: pointer;
}

.gender-option input {
  display: none;
}

.gender-card {
  padding: 20px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  text-align: center;
  transition: all 0.25s;
  background: var(--bg-primary);
}

.gender-card:active {
  transform: scale(0.97);
}

.gender-option input:checked + .gender-card {
  border-color: var(--primary);
  background: linear-gradient(135deg, rgba(102,126,234,0.08), rgba(240,147,251,0.08));
  box-shadow: 0 0 0 1px var(--primary);
}

.gender-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.gender-card span {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.auth-container .btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  margin-top: 12px;
}

.auth-container .btn-text {
  color: var(--primary);
  margin-top: 16px;
  width: 100%;
}

/* ============ Bot Selection Page ============ */
.select-container {
  height: 100%;
  padding: 60px 20px 40px;
  background: var(--bg-primary);
  overflow-y: auto;
}

.select-header {
  text-align: center;
  margin-bottom: 32px;
}

.select-header h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.select-header p {
  font-size: 14px;
  color: var(--text-secondary);
}

.bot-cards {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---- Profile Card Layout ---- */
.bot-profile-card {
  position: relative;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: all 0.3s;
  overflow: hidden;
}

.bot-profile-card:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-sm);
}

.bot-profile-img-wrapper {
  position: relative;
  width: 100%;
  height: 320px;
  overflow: hidden;
}

.bot-card-girl .bot-profile-img-wrapper {
  background: linear-gradient(135deg, #ffecd2, #fcb69f, #ff9a9e);
}

.bot-card-boy .bot-profile-img-wrapper {
  background: linear-gradient(135deg, #a1c4fd, #c2e9fb, #d4efff);
}

.bot-profile-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 20%;
  display: block;
}

.bot-profile-info {
  padding: 16px 20px 20px;
  text-align: center;
}

.bot-profile-info h3 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}

.bot-age {
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 6px;
}

.bot-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.bot-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 14px;
}

.tag {
  font-size: 12px;
  padding: 3px 10px;
  background: var(--bg-primary);
  border-radius: 20px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.btn-chat-girl,
.btn-chat-boy {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: var(--radius-xl);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.2s;
}

.btn-chat-girl {
  background: linear-gradient(135deg, #ff6b9d, #ff8fb1);
}

.btn-chat-boy {
  background: linear-gradient(135deg, #4facfe, #6fc3ff);
}

.btn-chat-girl:active,
.btn-chat-boy:active {
  opacity: 0.85;
}

.recommend-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(102,126,234,0.4);
  animation: badge-glow 2s ease-in-out infinite;
  z-index: 2;
}

@keyframes badge-glow {
  0%, 100% { box-shadow: 0 2px 8px rgba(102,126,234,0.4); }
  50% { box-shadow: 0 2px 16px rgba(102,126,234,0.7); }
}

/* Avatar classes for chat header and messages */
.girl-avatar {
  background: url('/assets/girl.png') center/cover, linear-gradient(135deg, #ff9a9e 0%, #fecfef 50%, #fdfcfb 100%);
}

.boy-avatar {
  background: url('/assets/boy.png') center/cover, linear-gradient(135deg, #a1c4fd 0%, #c2e9fb 50%, #fdfcfb 100%);
}

/* ============ Chat Page ============ */
.chat-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #f5f5f7;
}

.chat-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top, 12px));
  background: var(--bg-secondary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  z-index: 10;
  gap: 12px;
}

.chat-header .back-btn {
  margin-bottom: 0;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chat-header-info h3 {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
}

.online-status {
  font-size: 12px;
  color: #34d399;
  display: flex;
  align-items: center;
  gap: 4px;
}

.online-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #34d399;
  display: inline-block;
}

.menu-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.menu-btn:active {
  background: var(--bg-primary);
}

/* ============ Skills Menu ============ */
.skills-menu {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.skills-menu.active {
  pointer-events: auto;
  opacity: 1;
}

.skills-menu-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.3);
}

.skills-menu-content {
  position: absolute;
  top: 70px;
  right: 16px;
  background: white;
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-lg);
  transform: translateY(-10px);
  transition: transform 0.3s;
  min-width: 200px;
}

.skills-menu.active .skills-menu-content {
  transform: translateY(0);
}

.skills-menu-content h4 {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 12px;
  font-weight: 600;
}

.skill-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skill-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: none;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 15px;
  color: var(--text-primary);
  font-family: inherit;
  transition: all 0.2s;
}

.skill-item:active {
  background: var(--border);
  transform: scale(0.97);
}

.skill-icon {
  font-size: 20px;
}

/* ============ Chat Messages ============ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.chat-date {
  text-align: center;
  font-size: 12px;
  color: var(--text-light);
  padding: 4px 12px;
  background: rgba(0,0,0,0.04);
  border-radius: 20px;
  align-self: center;
  margin: 4px 0;
}

.message {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: msg-in 0.3s ease;
}

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

.message-bot {
  align-self: flex-start;
}

.message-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  overflow: hidden;
}

.message-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.message-bot .message-avatar {
  background: linear-gradient(135deg, var(--primary-light), var(--accent-light));
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.message-user .message-avatar {
  background: linear-gradient(135deg, #e2e8f0, #cbd5e1);
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
}

.message-bot .message-bubble {
  background: white;
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.message-user .message-bubble {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border-bottom-right-radius: 4px;
}

/* Special message cards */
.message-card {
  background: white;
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  border-bottom-left-radius: 4px;
}

.message-card .card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.message-card .card-icon {
  font-size: 24px;
}

.message-card .card-title {
  font-size: 15px;
  font-weight: 600;
}

.message-card .card-body {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.message-card .card-progress {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.message-card .card-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 2px;
  animation: progress-anim 3s ease-in-out infinite;
}

@keyframes progress-anim {
  0% { width: 0%; }
  50% { width: 80%; }
  100% { width: 100%; }
}

.message-card .card-status {
  font-size: 12px;
  color: var(--primary);
  margin-top: 8px;
  font-weight: 500;
}

/* Video / Audio Player in chat */
.media-player {
  border-radius: var(--radius-md);
  overflow: hidden;
}

.chat-video {
  width: 100%;
  max-width: 280px;
  border-radius: var(--radius-md);
  display: block;
  background: #000;
}

.chat-audio {
  width: 100%;
  max-width: 280px;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-light);
  border-radius: 50%;
  animation: typing 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

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

/* ============ Chat Input ============ */
.chat-input-area {
  padding: 8px 12px;
  padding-bottom: max(8px, var(--safe-bottom));
  background: var(--bg-secondary);
  border-top: 1px solid rgba(0,0,0,0.06);
}

.input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.voice-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: all 0.2s;
}

.voice-btn:active {
  background: var(--border);
  transform: scale(0.92);
}

.voice-btn.active {
  background: var(--primary);
  color: white;
}

.text-input-container {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--bg-primary);
  border-radius: 24px;
  padding: 4px 4px 4px 16px;
  border: 1px solid var(--border);
  transition: border-color 0.25s;
}

.text-input-container:focus-within {
  border-color: var(--primary);
}

#message-input {
  flex: 1;
  border: none;
  background: none;
  font-size: 15px;
  color: var(--text-primary);
  outline: none;
  font-family: inherit;
  padding: 8px 0;
}

#message-input::placeholder {
  color: var(--text-light);
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
  opacity: 0.5;
}

.send-btn.active {
  opacity: 1;
}

.send-btn:active {
  transform: scale(0.9);
}

.voice-input-container {
  flex: 1;
}

.voice-record-btn {
  width: 100%;
  padding: 14px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  font-size: 15px;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  user-select: none;
  -webkit-user-select: none;
}

.voice-record-btn:active,
.voice-record-btn.recording {
  background: linear-gradient(135deg, rgba(102,126,234,0.1), rgba(240,147,251,0.1));
  border-color: var(--primary);
  color: var(--primary);
}

/* ============ Voice Overlay ============ */
.voice-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}

.voice-overlay.active {
  display: flex;
}

.voice-animation {
  text-align: center;
  color: white;
}

.voice-wave {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 16px;
  height: 60px;
}

.voice-wave span {
  width: 4px;
  height: 20px;
  background: white;
  border-radius: 4px;
  animation: wave 1s ease-in-out infinite;
}

.voice-wave span:nth-child(1) { animation-delay: 0s; }
.voice-wave span:nth-child(2) { animation-delay: 0.1s; }
.voice-wave span:nth-child(3) { animation-delay: 0.2s; }
.voice-wave span:nth-child(4) { animation-delay: 0.3s; }
.voice-wave span:nth-child(5) { animation-delay: 0.4s; }

@keyframes wave {
  0%, 100% { height: 20px; }
  50% { height: 50px; }
}

.voice-animation p {
  font-size: 16px;
  opacity: 0.9;
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 10px 24px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 9999;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  backdrop-filter: blur(10px);
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============ Utilities ============ */
.text-center { text-align: center; }
.mt-16 { margin-top: 16px; }

/* ============ Scrollbar ============ */
.chat-messages::-webkit-scrollbar {
  width: 0;
}

/* ============ Responsive ============ */
@media (min-width: 481px) {
  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    box-shadow: 0 0 40px rgba(0,0,0,0.08);
  }
}
