/**
 * AI宠物 MiniApp - 主样式 - v14.9
 */

/* ==================== 基础 ==================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #f5f5f5;
  --card-bg: #ffffff;
  --text: #333333;
  --text-secondary: #666666;
  --border: #e5e5e5;
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ==================== 布局 ==================== */

.app {
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page {
  flex: 1;
  padding-bottom: 60px;
  overflow-y: auto;
}

.page-content {
  padding: 16px;
}

.page-header {
  padding: 16px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.page-header h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

/* ==================== 首页 ==================== */

.pet-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.pet-avatar {
  width: 200px;
  height: 200px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 80px;
  box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
}

.pet-animation {
  font-size: 100px;
}

.pet-animation.happy {
  animation: bounce 0.5s ease infinite alternate;
}

.pet-animation.sleepy {
  animation: sleepy 2s ease-in-out infinite;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-10px); }
}

@keyframes sleepy {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.pet-name {
  font-size: 24px;
  font-weight: bold;
  margin-top: 8px;
}

.pet-level {
  font-size: 14px;
  opacity: 0.8;
}

/* ==================== 属性条 ==================== */

.attributes {
  width: 100%;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.attr-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.attr-bar.warning .attr-progress-fill {
  background: var(--warning) !important;
}

.attr-bar.danger {
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.attr-info {
  width: 70px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
}

.attr-icon {
  font-size: 16px;
}

.attr-progress {
  flex: 1;
  height: 8px;
  background: #eee;
  border-radius: 4px;
  overflow: hidden;
}

.attr-progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.attr-value {
  width: 35px;
  text-align: right;
  font-size: 14px;
  font-weight: 500;
}

/* ==================== 状态提示 ==================== */

.status-tip {
  width: 100%;
  text-align: center;
  padding: 12px;
  background: var(--card-bg);
  border-radius: 12px;
  font-size: 16px;
  color: var(--text-secondary);
}

/* ==================== 操作按钮 ==================== */

.actions {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px 8px;
  background: var(--card-bg);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-btn:active {
  transform: scale(0.95);
  background: #f0f0f0;
}

.action-btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.action-icon {
  font-size: 28px;
}

.action-label {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ==================== 商店 ==================== */

.shop-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.tab {
  padding: 8px 16px;
  background: #f0f0f0;
  border: none;
  border-radius: 20px;
  white-space: nowrap;
  cursor: pointer;
}

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

.shop-items {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.shop-item {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.shop-item:active {
  transform: scale(0.98);
}

.item-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.item-name {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.item-price {
  font-size: 14px;
  color: var(--primary);
  font-weight: bold;
}

.item-effect {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ==================== 拍照 ==================== */

.photos-remaining {
  font-size: 14px;
  color: var(--text-secondary);
}

.camera-modes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.camera-mode {
  padding: 12px;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
}

.camera-mode.active {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}

.camera-mode.vip-only {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
}

.camera-input {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.camera-input textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  resize: none;
  margin-bottom: 12px;
  font-family: inherit;
}

.scene-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.scene-btn {
  padding: 12px 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

/* ==================== AI对话 ==================== */

.chat-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 120px;
}

.chat-welcome {
  text-align: center;
  padding: 40px 0;
  color: var(--text-secondary);
}

.welcome-pet {
  font-size: 60px;
  margin-bottom: 12px;
}

.chat-message {
  display: flex;
  margin-bottom: 8px;
}

.chat-message.user {
  justify-content: flex-end;
}

.chat-message .message-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--card-bg);
}

.chat-message.user .message-bubble {
  background: var(--primary);
  color: white;
}

.chat-message .pet-name {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.chat-input-area {
  position: fixed;
  bottom: 60px;
  left: 0;
  right: 0;
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
}

.chat-input-area input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  outline: none;
}

.send-btn {
  width: 48px;
  height: 48px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
}

.quick-phrases {
  position: fixed;
  bottom: 120px;
  left: 0;
  right: 0;
  display: flex;
  gap: 8px;
  padding: 0 16px;
  overflow-x: auto;
}

.quick-phrases button {
  padding: 6px 12px;
  background: #f0f0f0;
  border: none;
  border-radius: 16px;
  white-space: nowrap;
  font-size: 14px;
}

/* ==================== 我的 ==================== */

.profile-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  margin-bottom: 16px;
}

.profile-avatar {
  width: 80px;
  height: 80px;
  background: white;
  color: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin: 0 auto 12px;
}

.profile-name {
  font-size: 20px;
  font-weight: bold;
}

.profile-level {
  font-size: 14px;
  opacity: 0.8;
}

.vip-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  font-size: 12px;
}

.balance-card {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.balance-item {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}

.balance-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.balance-value {
  font-size: 24px;
  font-weight: bold;
}

.balance-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.profile-menu {
  background: var(--card-bg);
  border-radius: 12px;
  overflow: hidden;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.menu-item:last-child {
  border-bottom: none;
}

.menu-icon {
  font-size: 24px;
}

.menu-text {
  flex: 1;
}

.menu-arrow {
  color: var(--text-secondary);
}

/* ==================== 底部导航 ==================== */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  padding-bottom: calc(8px + var(--safe-bottom));
  background: var(--card-bg);
  border-top: 1px solid var(--border);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 12px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.nav-item.active {
  opacity: 1;
}

.nav-icon {
  font-size: 24px;
}

.nav-label {
  font-size: 10px;
}

/* ==================== 弹窗 ==================== */

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 24px;
  max-width: 90%;
  max-height: 80%;
  overflow-y: auto;
}

.result-header {
  text-align: center;
  margin-bottom: 16px;
}

.result-emoji {
  font-size: 60px;
  margin-bottom: 8px;
}

.result-title {
  font-size: 20px;
  font-weight: bold;
}

.result-pet-animation {
  text-align: center;
  font-size: 40px;
  margin-bottom: 16px;
  animation: bounce 0.5s ease infinite alternate;
}

.result-changes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 16px;
}

.change-item {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 14px;
}

.change-item.positive {
  background: rgba(34, 197, 94, 0.1);
  color: var(--success);
}

.change-item.negative {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

.result-reward {
  text-align: center;
  padding: 8px;
  background: rgba(99, 102, 241, 0.1);
  border-radius: 8px;
  color: var(--primary);
  margin-bottom: 16px;
}

.result-image {
  width: 100%;
  border-radius: 12px;
  margin-bottom: 16px;
}

.result-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* ==================== 按钮 ==================== */

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  cursor: pointer;
}

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

.btn-secondary {
  padding: 12px 16px;
  background: #f0f0f0;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.btn-small {
  padding: 4px 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 12px;
  cursor: pointer;
}

/* ==================== Loading/Toast ==================== */

.loading {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.loading-icon {
  font-size: 60px;
  animation: bounce 0.5s ease infinite alternate;
}

.loading-text {
  margin-top: 12px;
  color: var(--text-secondary);
}

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  padding: 12px 24px;
  background: var(--text);
  color: white;
  border-radius: 24px;
  font-size: 14px;
  transition: transform 0.3s ease;
  z-index: 3000;
}

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

.toast.error {
  background: var(--danger);
}

.toast.success {
  background: var(--success);
}

/* ==================== 无宠物 ==================== */

.no-pet {
  text-align: center;
  padding: 60px 20px;
}

.no-pet-icon {
  font-size: 80px;
  margin-bottom: 16px;
}

.no-pet h2 {
  margin-bottom: 8px;
}

.no-pet p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}