/* ========== 全局重置 & 基础 ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #397BFA;
  --primary-light: #4482FC;
  --primary-dark: #2A5FC7;
  --purple: #894FD9;
  --purple-light: #8747E3;
  --text-primary: #171717;
  --text-secondary: #788092;
  --text-muted: #9198A8;
  --bg-page: #FCFDFF;
  --bg-card: #FFFFFF;
  --border: #E8EAF0;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 2px 12px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 32px rgba(0,0,0,0.06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-height: 56px;
}

html, body {
  font-family: 'PingFang SC', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }
button { border: none; background: none; cursor: pointer; font-family: inherit; }
input, textarea { font-family: inherit; outline: none; }

/* ========== 容器 ========== */
.page-container {
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-height) + 20px + var(--safe-bottom));
  background: var(--bg-page);
}

/* ========== 底部 TabBar ========== */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tabbar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 1000;
}

.tabbar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.tabbar-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  opacity: 0.5;
  transition: opacity 0.2s;
}

.tabbar-item.active .tabbar-icon {
  opacity: 1;
}

.tabbar-label {
  font-size: 10px;
  color: var(--text-muted);
  transition: color 0.2s;
}

.tabbar-item.active .tabbar-label {
  color: var(--primary);
}

/* ========== 顶部导航 ========== */
.nav-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(252,253,255,0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(0,0,0,0.03);
}

.nav-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.nav-back {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.2s;
}

.nav-back:hover {
  background: rgba(0,0,0,0.05);
}

/* ========== 通用卡片 ========== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin: 12px 16px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.8);
}

/* ========== 按钮 ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 24px;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
  user-select: none;
}

.btn-primary {
  background: linear-gradient(90deg, var(--primary-light) 0%, var(--purple-light) 100%);
  color: #fff;
  box-shadow: 0 4px 16px rgba(68,130,252,0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(68,130,252,0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: rgba(137,79,217,0.1);
  color: var(--purple);
}

.btn-secondary:hover {
  background: rgba(137,79,217,0.15);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ========== 弹窗 ========== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal-content {
  background: #fff;
  border-radius: var(--radius-lg);
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* ========== 登录弹窗 ========== */
.login-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.login-modal {
  background: #fff;
  border-radius: 16px;
  width: 85%;
  max-width: 380px;
  padding: 32px 24px 24px;
  animation: slideUp 0.3s ease;
}

.login-modal-title {
  font-size: 22px;
  font-weight: 700;
  color: #1a1a2e;
  margin-bottom: 4px;
}

.login-modal-sub {
  font-size: 14px;
  color: #999;
  margin-bottom: 24px;
}

.login-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  background: #f5f5f5;
  border-radius: 8px;
  padding: 3px;
}

.login-tab {
  flex: 1;
  text-align: center;
  padding: 8px 0;
  font-size: 14px;
  font-weight: 500;
  color: #666;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.login-tab.active {
  background: #fff;
  color: #667eea;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  font-size: 13px;
  color: #666;
  margin-bottom: 6px;
  font-weight: 500;
}

.login-field input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #e8e8e8;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.login-field input:focus {
  border-color: #667eea;
}

.login-submit-btn {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: opacity 0.2s;
}

.login-submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-divider {
  text-align: center;
  color: #ccc;
  font-size: 13px;
  margin: 20px 0 16px;
  position: relative;
}

.login-divider::before,
.login-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: #eee;
}

.login-divider::before { left: 0; }
.login-divider::after { right: 0; }

.wechat-login-btn {
  width: 100%;
  padding: 12px;
  background: #07c160;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.2s;
}

.wechat-login-btn:hover {
  opacity: 0.9;
}

/* ========== Toast ========== */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 9999;
  animation: fadeIn 0.2s ease;
  pointer-events: none;
  text-align: center;
  max-width: 80vw;
}

/* ========== Loading ========== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
}

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

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

/* ========== 空状态 ========== */
.empty-state {
  text-align: center;
  padding: 80px 20px;
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.6;
}

.empty-text {
  font-size: 16px;
  color: var(--text-muted);
}

/* ========== 图片加载骨架 ========== */
.image-container {
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(250,240,245,0.8) 0%, rgba(245,235,250,0.7) 50%, rgba(240,235,248,0.8) 100%);
}

.image-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}

.loading-shimmer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.4) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite ease-in-out;
}

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

/* ========== 响应式 ========== */
@media (min-width: 768px) {
  .page-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    padding-bottom: calc(var(--tabbar-height) + 20px + var(--safe-bottom));
    min-height: 100vh;
  }
  
  .tabbar {
    max-width: 1200px;
    left: 50%;
    transform: translateX(-50%);
  }
  
  /* PC 端模板网格改为 4 列 */
  .template-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
  }
  
  /* PC 端首页头部居中 */
  .home-header {
    text-align: center;
    padding: 40px 20px;
  }
  
  .home-title {
    font-size: 36px;
  }
  
  .home-subtitle {
    font-size: 16px;
  }
  
  /* PC 端分类标签居中 */
  .category-tabs {
    justify-content: center;
  }
}

/* ========== 滚动条美化 ========== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
}

/* ========== 工具类 ========== */
.text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
