/* ============================================
   人生RPG - 设计系统与主样式
   基于 awesome-design-md 提炼的设计规范
   ============================================ */

/* ---------- 设计Token系统 ---------- */
:root {
  /* 品牌主色 - 成长绿 */
  --color-primary: #4a9d6e;
  --color-primary-active: #3a7d56;
  --color-primary-soft: #e8f5ed;
  --color-primary-disabled: #c5e0d0;

  /* 表面色 */
  --color-canvas: #faf9f5;        /* 温暖米色画布 */
  --color-surface-card: #ffffff;   /* 卡片白 */
  --color-surface-soft: #f5f3ee;   /* 软表面 */
  --color-surface-dark: #1a1c19;   /* 深色成就殿堂 */
  --color-surface-dark-elevated: #252824;

  /* 文字色 */
  --color-ink: #1c1b18;            /* 主文字 - 温暖近黑 */
  --color-body: #4a4842;           /* 正文 */
  --color-muted: #8a8780;           /* 辅助文字 */
  --color-muted-soft: #a8a59e;
  --color-on-primary: #ffffff;
  --color-on-dark: #f0ede5;
  --color-on-dark-soft: #a09d96;

  /* 边框 */
  --color-hairline: #e6e3dc;
  --color-hairline-soft: #efede7;

  /* 任务状态色 - 借鉴Cursor时间线调色板 */
  --status-todo: #c4b5a0;
  --status-doing: #5b9bd5;
  --status-paused: #d4a843;
  --status-done: #4a9d6e;
  --status-review: #9b6db5;

  /* 语义色 */
  --color-success: #4a9d6e;
  --color-warning: #d4a843;
  --color-error: #c64545;
  --color-xp-gold: #e8b84b;

  /* 属性色 */
  --attr-intelligence: #5b9bd5;   /* 智力 - 蓝 */
  --attr-physique: #e07b5a;        /* 体质 - 橙红 */
  --attr-charisma: #9b6db5;        /* 魅力 - 紫 */

  /* ---------- 字体系统 ---------- */
  --font-display: Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* 字体大小 */
  --text-display-xl: 56px;
  --text-display-lg: 40px;
  --text-display-md: 28px;
  --text-title-lg: 20px;
  --text-title-md: 16px;
  --text-title-sm: 14px;
  --text-body-md: 15px;
  --text-body-sm: 13px;
  --text-caption: 12px;
  --text-caption-uppercase: 11px;
  --text-xp-number: 24px;

  /* 行高 */
  --line-height-tight: 1.1;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.6;

  /* ---------- 圆角系统 ---------- */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-xxl: 24px;
  --radius-pill: 9999px;

  /* ---------- 间距系统 ---------- */
  --space-xxs: 4px;
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-xxl: 48px;
  --space-section: 80px;

  /* ---------- 阴影系统（克制使用） ---------- */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.08);

  /* ---------- 动画 ---------- */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.4s ease;
}

/* ---------- 基础重置 ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-body-md);
  line-height: var(--line-height-normal);
  color: var(--color-body);
  background-color: var(--color-canvas);
  min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: var(--color-ink);
  font-weight: 400;
  line-height: var(--line-height-tight);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

ul, ol {
  list-style: none;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

/* ---------- 应用外壳布局 ---------- */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 var(--space-lg);
  background-color: var(--color-canvas);
  border-bottom: 1px solid var(--color-hairline);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left .logo {
  font-family: var(--font-display);
  font-size: var(--text-title-lg);
  color: var(--color-ink);
}

.header-center {
  flex: 1;
  max-width: 400px;
  margin: 0 var(--space-lg);
}

.xp-bar-container {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.level-badge {
  background-color: var(--color-primary);
  color: var(--color-on-primary);
  padding: var(--space-xxs) var(--space-xs);
  border-radius: var(--radius-sm);
  font-size: var(--text-caption);
  font-weight: 600;
  white-space: nowrap;
}

.xp-bar {
  flex: 1;
  height: 8px;
  background-color: var(--color-surface-soft);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-xp-gold));
  border-radius: var(--radius-pill);
  transition: width var(--transition-slow);
}

.xp-text {
  font-size: var(--text-caption);
  color: var(--color-muted);
  white-space: nowrap;
}

.header-right {
  display: flex;
  gap: var(--space-xs);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  font-size: 18px;
  transition: background-color var(--transition-fast);
}

.icon-btn:hover {
  background-color: var(--color-surface-soft);
}

.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 200px;
  background-color: var(--color-canvas);
  border-right: 1px solid var(--color-hairline);
  display: flex;
  flex-direction: column;
  padding: var(--space-md) 0;
}

.nav-list {
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  cursor: pointer;
  transition: all var(--transition-fast);
  border-left: 2px solid transparent;
  color: var(--color-body);
}

.nav-item:hover {
  background-color: var(--color-surface-soft);
}

.nav-item.active {
  background-color: var(--color-primary-soft);
  border-left-color: var(--color-primary);
  color: var(--color-primary-active);
  font-weight: 500;
}

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

.nav-label {
  font-size: var(--text-body-sm);
}

.sidebar-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-hairline-soft);
}

.sync-status {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--text-caption);
  color: var(--color-muted);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--color-muted);
}

.sync-dot.syncing {
  background-color: var(--color-warning);
  animation: pulse 1s infinite;
}

.sync-dot.synced {
  background-color: var(--color-success);
}

.sync-dot.error {
  background-color: var(--color-error);
}

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

/* ---------- 主内容区 ---------- */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xl);
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-muted);
}

/* ---------- 通用组件 ---------- */
.card {
  background-color: var(--color-surface-card);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: box-shadow var(--transition-fast);
}

.card:hover {
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-family: var(--font-display);
  font-size: var(--text-title-lg);
  color: var(--color-ink);
  margin-bottom: var(--space-md);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: var(--text-title-sm);
  font-weight: 500;
  transition: all var(--transition-fast);
  cursor: pointer;
}

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

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

.btn-secondary {
  background-color: var(--color-surface-card);
  color: var(--color-ink);
  border: 1px solid var(--color-hairline);
}

.btn-secondary:hover {
  background-color: var(--color-surface-soft);
}

.btn-sm {
  padding: 6px 12px;
  font-size: var(--text-body-sm);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-caption);
  font-weight: 500;
}

.badge-primary {
  background-color: var(--color-primary-soft);
  color: var(--color-primary-active);
}

.badge-gold {
  background-color: #fdf3d8;
  color: #8a6d1b;
}

/* ---------- 通知系统 ---------- */
.notification-container {
  position: fixed;
  top: 80px;
  right: var(--space-lg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.notification {
  background-color: var(--color-surface-card);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-lg);
  padding: var(--space-md) var(--space-lg);
  box-shadow: var(--shadow-lg);
  min-width: 280px;
  animation: slideIn var(--transition-normal);
}

.notification.success {
  border-left: 4px solid var(--color-success);
}

.notification.warning {
  border-left: 4px solid var(--color-warning);
}

.notification.error {
  border-left: 4px solid var(--color-error);
}

.notification.xp-gain {
  border-left: 4px solid var(--color-xp-gold);
  background: linear-gradient(135deg, #fffdf5, #ffffff);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ---------- 模态框 ---------- */
.modal-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-container.active {
  display: flex;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
}

.modal-content {
  position: relative;
  background-color: var(--color-surface-card);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  z-index: 1;
}

.modal-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  font-size: 18px;
  color: var(--color-muted);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background-color: var(--color-surface-soft);
  color: var(--color-ink);
}

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
  .sidebar {
    width: 60px;
  }

  .nav-label {
    display: none;
  }

  .header-center {
    display: none;
  }

  .main-content {
    padding: var(--space-md);
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 0 var(--space-md);
  }

  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 60px;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--color-hairline);
    z-index: 100;
  }

  .nav-list {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
  }

  .nav-item {
    flex-direction: column;
    padding: var(--space-xs);
    border-left: none;
    border-top: 3px solid transparent;
  }

  .nav-item.active {
    border-left: none;
    border-top-color: var(--color-primary);
  }

  .sidebar-footer {
    display: none;
  }

  .main-content {
    padding-bottom: 80px;
  }
}

/* ============================================
   动画效果增强
   ============================================ */

/* 页面切换淡入动画 */
.main-content > * {
  animation: fadeInUp 0.4s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 卡片入场交错动画 */
.card {
  animation: cardEnter 0.3s ease-out backwards;
}

.card:nth-child(1) { animation-delay: 0.05s; }
.card:nth-child(2) { animation-delay: 0.1s; }
.card:nth-child(3) { animation-delay: 0.15s; }
.card:nth-child(4) { animation-delay: 0.2s; }
.card:nth-child(5) { animation-delay: 0.25s; }

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* XP条光泽流动效果 */
.xp-fill {
  position: relative;
  overflow: hidden;
}

.xp-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* 按钮点击反馈 */
.btn:active, .task-action-btn:active, .category-tab:active, .filter-btn:active {
  transform: scale(0.97);
}

/* 导航项激活指示动画 */
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--color-primary);
  border-radius: 0 2px 2px 0;
  animation: navIndicator 0.3s ease-out;
}

@keyframes navIndicator {
  from { height: 0; }
  to { height: 60%; }
}

/* 任务卡片悬停提升 */
.task-card {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.task-card:hover {
  transform: translateX(4px);
  box-shadow: var(--shadow-md);
}

/* 复选框自定义动画 */
.task-checkbox {
  position: relative;
  transition: all 0.2s ease;
}

.task-checkbox.checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  color: white;
  font-size: 14px;
  font-weight: bold;
  animation: checkPop 0.3s ease-out forwards;
}

@keyframes checkPop {
  0% { transform: translate(-50%, -50%) scale(0); }
  50% { transform: translate(-50%, -50%) scale(1.3); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* 成就解锁光效 */
.achievement-card.unlocked {
  animation: achievementGlow 2s ease-in-out infinite alternate;
}

@keyframes achievementGlow {
  from { box-shadow: 0 0 8px rgba(232, 184, 75, 0.3); }
  to { box-shadow: 0 0 20px rgba(232, 184, 75, 0.6); }
}

/* 属性条增长动画 */
.attribute-bar-fill {
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 数字滚动效果容器 */
.stat-value, .coin-value {
  display: inline-block;
  transition: transform 0.2s ease;
}

.stat-value:hover, .coin-value:hover {
  transform: scale(1.05);
}

/* 加载骨架屏 */
.skeleton {
  background: linear-gradient(90deg, var(--color-surface-soft) 25%, var(--color-hairline-soft) 50%, var(--color-surface-soft) 75%);
  background-size: 200% 100%;
  animation: skeletonLoading 1.5s infinite;
  border-radius: var(--radius-md);
}

@keyframes skeletonLoading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* 减少动画偏好（无障碍） */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================
   响应式优化增强
   ============================================ */

/* 平板优化 */
@media (max-width: 1024px) {
  .main-content {
    padding: var(--space-lg);
  }

  .character-header {
    flex-wrap: wrap;
  }

  .character-stats-quick {
    width: 100%;
    justify-content: space-around;
    padding-top: 16px;
    border-top: 1px solid var(--color-hairline-soft);
  }
}

/* 移动端优化 */
@media (max-width: 640px) {
  .app-header {
    height: 56px;
    padding: 0 var(--space-sm);
  }

  .header-left .logo {
    font-size: var(--text-title-md);
  }

  .main-content {
    padding: var(--space-md);
  }

  .page-title {
    font-size: 22px !important;
  }

  .card {
    padding: var(--space-md);
    border-radius: var(--radius-md);
  }

  .card-title {
    font-size: var(--text-title-md);
  }

  /* 任务卡片移动端 */
  .task-card {
    padding: 12px;
  }

  .task-meta {
    gap: 6px;
  }

  .task-tag {
    font-size: 10px;
    padding: 2px 6px;
  }

  .task-xp {
    font-size: 12px;
  }

  /* 按钮移动端 */
  .btn {
    padding: 8px 14px;
    font-size: var(--text-body-sm);
  }

  /* 通知移动端 */
  .notification-container {
    top: 64px;
    right: var(--space-sm);
    left: var(--space-sm);
  }

  .notification {
    min-width: auto;
    width: 100%;
  }

  /* 模态框移动端 */
  .modal-content {
    width: 95%;
    padding: var(--space-lg);
    max-height: 85vh;
  }

  /* 属性网格移动端 */
  .attributes-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }

  .attribute-card {
    padding: 12px !important;
  }

  /* 奖励商店移动端 */
  .rewards-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }

  .reward-icon {
    font-size: 36px !important;
  }

  .reward-name {
    font-size: 13px !important;
  }
}

/* 超小屏优化 */
@media (max-width: 360px) {
  .attributes-grid {
    grid-template-columns: 1fr !important;
  }

  .rewards-grid {
    grid-template-columns: 1fr !important;
  }

  .task-actions {
    flex-direction: column;
  }

  .task-action-btn {
    width: 100%;
  }
}

/* 横屏优化 */
@media (max-height: 500px) and (orientation: landscape) {
  .app-header {
    height: 48px;
  }

  .sidebar {
    padding: var(--space-xs) 0;
  }

  .nav-item {
    padding: var(--space-xs) var(--space-md);
  }
}

/* 打印样式 */
@media print {
  .app-header, .sidebar, .notification-container, .modal-container {
    display: none !important;
  }

  .main-content {
    padding: 0;
    overflow: visible;
  }

  .card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
  }
}
