/* =====================================================
   Base Styles v4.0 - 现代排版体系
   ===================================================== */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
               "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

#app {
  min-height: 100vh;
  max-width: var(--content-max);
  margin: 0 auto;
  position: relative;
  background: var(--bg);
}

/* 确保tab栏在桌面端也跟随内容宽度 */
@media (min-width: 768px) {
  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* ===== 排版层次 ===== */
h1, .h1 { font-size: var(--text-3xl); font-weight: var(--font-bold); line-height: 1.2; letter-spacing: -0.02em; }
h2, .h2 { font-size: var(--text-2xl); font-weight: var(--font-bold); line-height: 1.3; letter-spacing: -0.01em; }
h3, .h3 { font-size: var(--text-xl); font-weight: var(--font-semibold); line-height: 1.4; }
h4, .h4 { font-size: var(--text-lg); font-weight: var(--font-semibold); line-height: 1.5; }
p, .p { font-size: var(--text-base); line-height: 1.6; }
small, .small { font-size: var(--text-sm); line-height: 1.5; }
.caption { font-size: var(--text-xs); line-height: 1.4; color: var(--text-tertiary); }

/* ===== 链接 ===== */
a {
  color: var(--primary);
  text-decoration: none;
  transition: var(--transition-fast);
}
a:hover { color: var(--primary-light); }
a:active { opacity: 0.7; }

/* ===== 按钮重置 ===== */
button {
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
  outline: none;
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ===== 表单元素 ===== */
input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 80px;
}

/* ===== 列表 ===== */
ul, ol { list-style: none; }

/* ===== 图片 ===== */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ===== 滚动条（更精致）===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--text-tertiary);
  border-radius: var(--radius-full);
  transition: var(--transition);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--text-tertiary) transparent;
}

/* ===== 选择高亮 ===== */
::selection {
  background: rgba(24, 24, 27, 0.15);
  color: var(--text);
}

[data-theme="dark"] ::selection {
  background: rgba(250, 250, 250, 0.2);
  color: var(--text);
}

/* ===== 工具类 ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

.text-primary { color: var(--primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

.font-normal { font-weight: var(--font-normal); }
.font-medium { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold { font-weight: var(--font-bold); }

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }

.leading-tight { line-height: 1.3; }
.leading-normal { line-height: 1.6; }
.leading-relaxed { line-height: 1.8; }

.tracking-tight { letter-spacing: -0.02em; }
.tracking-normal { letter-spacing: 0; }

/* ===== 间距工具类 ===== */
.m-0 { margin: 0; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.ml-2 { margin-left: var(--space-2); }
.mr-2 { margin-right: var(--space-2); }
.mx-auto { margin-left: auto; margin-right: auto; }

.p-0 { padding: 0; }
.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.px-3 { padding-left: var(--space-3); padding-right: var(--space-3); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }
.py-3 { padding-top: var(--space-3); padding-bottom: var(--space-3); }

/* ===== Flex工具类 ===== */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-start { justify-content: flex-start; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.flex-1 { flex: 1; min-width: 0; }
.flex-shrink-0 { flex-shrink: 0; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

/* ===== 显示工具类 ===== */
.hidden { display: none !important; }
.invisible { visibility: hidden; }
.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.whitespace-nowrap { white-space: nowrap; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== 动画关键帧 ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes popIn {
  0% { transform: scale(0.9); opacity: 0; }
  60% { transform: scale(1.02); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes bounceIn {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.05); }
  70% { transform: scale(0.95); }
  100% { transform: scale(1); opacity: 1; }
}

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

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

@keyframes floatUp {
  0% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-40px); opacity: 0; }
}

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

@keyframes glow {
  0%, 100% { box-shadow: 0 0 5px rgba(245, 158, 11, 0.3); }
  50% { box-shadow: 0 0 20px rgba(245, 158, 11, 0.6); }
}

/* ===== 动画工具类 ===== */
.animate-fadeIn { animation: fadeIn 0.3s ease; }
.animate-fadeInUp { animation: fadeInUp 0.3s ease; }
.animate-popIn { animation: popIn 0.3s ease; }
.animate-bounceIn { animation: bounceIn 0.4s ease; }
.animate-spin { animation: spin 0.8s linear infinite; }

/* ===== Loading ===== */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-10);
  color: var(--text-tertiary);
  gap: var(--space-3);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ===== Skeleton Loading ===== */
.skeleton {
  background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--border-light) 50%, var(--bg-secondary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-10) var(--space-4);
  color: var(--text-tertiary);
  text-align: center;
}

.empty-state .emoji {
  font-size: 56px;
  margin-bottom: var(--space-4);
  line-height: 1;
}

.empty-state .title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.empty-state .desc {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  max-width: 280px;
}
