/* ========== 全局优化 ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  /* 启用平滑滚动 */
  scroll-behavior: smooth;
  /* 优化触摸滚动 */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  /* 启用硬件加速 */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  /* 启用硬件加速的触摸滚动 */
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* 优化触摸响应 */
  touch-action: pan-y;
  /* 减少重排 */
  text-rendering: optimizeSpeed;
}

/* ========== Toast 消息系统 ========== */
.toast-container {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast-item {
  padding: 12px 20px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: toast-in 0.3s ease;
  pointer-events: auto;
  max-width: 90vw;
  word-wrap: break-word;
}

.toast-item.error { background: #f8d7da; color: #721c24; }
.toast-item.success { background: #d4edda; color: #155724; }
.toast-item.warning { background: #fff3cd; color: #856404; }
.toast-item.info { background: #d1ecf1; color: #0c5460; }

.toast-item i { font-size: 18px; flex-shrink: 0; }
.toast-item span { flex: 1; }

.toast-retry-btn {
  margin-left: auto;
  background: transparent;
  border: none;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
  font-weight: 500;
  flex-shrink: 0;
}

.toast-close-btn {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 0 0 0 10px;
  opacity: 0.7;
  flex-shrink: 0;
}
.toast-close-btn:hover { opacity: 1; }

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

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-20px); }
}

/* ========== 按钮加载态 ========== */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.spin {
  display: inline-block;
  animation: spin 1s linear infinite;
}

.btn-loading {
  opacity: 0.8;
  cursor: not-allowed;
}

/* ========== 触摸优化 ========== */
/* 按钮触摸区域（iOS 推荐 44x44） */
.btn, .nav-item, .tier-item, .payment-btn, .copy-btn, .action-btn {
  min-height: 44px;
  min-width: 44px;
}

/* 禁用点击高亮 */
* {
  -webkit-tap-highlight-color: transparent;
}

/* 触摸反馈 */
.btn:active, .nav-item:active, .tier-item:active, .payment-btn:active {
  transform: scale(0.98);
  opacity: 0.9;
}

/* ========== 卡片优化 ========== */
.card {
  /* 启用 GPU 加速 */
  will-change: transform;
  transform: translateZ(0);
  /* 优化动画性能 */
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* ========== 图片优化 ========== */
img {
  /* 防止图片拖动 */
  -webkit-user-drag: none;
  user-drag: none;
  /* 图片加载时避免重排 */
  display: block;
  max-width: 100%;
}

/* ========== 底部导航栏优化 ========== */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  z-index: 999;
  padding: 8px 0;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}

.bottom-nav-items {
  display: flex;
  justify-content: space-around;
  align-items: center;
  max-width: 600px;
  margin: 0 auto;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 16px;
  text-decoration: none;
  color: #999;
  transition: all 0.3s;
  border-radius: 8px;
}

.bottom-nav-item:active {
  background: #f5f5f5;
}

.bottom-nav-item i {
  font-size: 22px;
  margin-bottom: 4px;
}

.bottom-nav-item span {
  font-size: 12px;
  font-weight: 500;
}

.bottom-nav-item.active {
  color: #3C8CE7;
}

.bottom-nav-item.active i {
  transform: scale(1.1);
}

/* 移动端显示底部导航 */
@media (max-width: 600px) {
  .bottom-nav {
    display: block;
    /* 固定定位优化 */
    position: fixed;
    -webkit-position: fixed;
    /* 防止闪烁 */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }

  /* 移动端为底部导航留出空间 */
  body {
    padding-bottom: 70px;
    /* 启用平滑滚动 */
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }
}

/* ========== 动画优化 ========== */
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

/* ========== 响应式断点 ========== */

/* 桌面（≥ 900px） */
@media (min-width: 900px) {
  .main { max-width: 800px; }
}

/* 字体缩放 */
html {
  font-size: 16px;
}

@media (max-width: 400px) {
  html { font-size: 14px; }
}

/* 移动端标题缩小 */
@media (max-width: 600px) {
  .hero h1 { font-size: 32px !important; }
  .hero p { font-size: 16px !important; }
  .card h2 { font-size: 16px !important; }
  .user-balance { font-size: 36px !important; }
  .balance-amount { font-size: 36px !important; }
}

/* 统计网格移动端单列 */
@media (max-width: 500px) {
  .stats-grid { grid-template-columns: 1fr !important; }
}

/* 充值档位移动端 2 列 */
@media (max-width: 600px) {
  .tier-grid { grid-template-columns: repeat(2, 1fr) !important; }
}