/* =====================================================
   博客前端样式 — 重构优化版
   优化要点:
   - CSS 自定义属性支持暗色模式
   - prefers-reduced-motion 无障碍动效控制
   - contain 属性提升渲染性能
   - 响应式断点优化移动端体验
   - 焦点样式与 touch-target 优化
   - 打印样式
   ===================================================== */

/* ── 自定义属性 ── */
:root {
  --primary: #3498db;
  --primary-dark: #2980b9;
  --secondary: #2ecc71;
  --danger: #e74c3c;
  --warning: #e67e22;
  --text: #333;
  --text-light: #666;
  --text-muted: #999;
  --bg: #f5f5f5;
  --bg-card: #fff;
  --border: #e0e0e0;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.12);
  --radius: 8px;
  --radius-sm: 4px;
  --font-base: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono",
    "Courier New", monospace;
  --nav-height: 60px;
  --focus-ring: 0 0 0 3px rgba(52, 152, 219, 0.35);
  --transition: 0.2s ease;
}

/* ── 基础重置 ── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-height) + 20px);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-base);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
}

/* ── 减少动效（无障碍） ── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  html {
    scroll-behavior: auto;
  }
}

/* ── 焦点样式（无障碍） ── */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 2px;
}

/* 移除鼠标点击时的焦点环，仅保留键盘焦点 */
:focus:not(:focus-visible) {
  outline: none;
}

/* ── 跳过导航链接（无障碍） ── */
.skip-link {
  position: absolute;
  top: -100px;
  left: 8px;
  z-index: 1000;
  padding: 10px 20px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: top var(--transition);
}

.skip-link:focus {
  top: 0;
}

/* ── 导航 ── */
.navbar {
  background: var(--bg-card);
  box-shadow: var(--shadow);
  padding: 0;
  height: var(--nav-height);
  position: sticky;
  top: 0;
  z-index: 100;
  contain: layout style;
}

.navbar .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

.navbar .logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.logo:hover {
  color: var(--primary);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-links a,
.nav-links [role="menuitem"] {
  padding: 8px 14px;
  color: var(--text-light);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  transition: background var(--transition), color var(--transition);
}

.nav-links a:hover {
  background: #f0f0f0;
  color: var(--primary);
}

.nav-links a[aria-current="page"] {
  color: var(--primary);
  font-weight: 600;
}

.user-greeting {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  padding: 4px 14px;
  color: var(--text-light);
  font-size: 13px;
  background: #f8f9fa;
  border-radius: 20px;
  min-height: 36px;
  contain: layout;
}

.nav-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

/* ── 闪存消息 ── */
.flash-messages {
  max-width: 1200px;
  margin: 16px auto;
  padding: 0 20px;
}

.flash {
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.flash-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.flash-error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.flash-info {
  background: #d1ecf1;
  color: #0c5460;
  border: 1px solid #bee5eb;
}

.flash-warning {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeeba;
}

/* ── 主布局（双栏） ── */
.main-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 30px;
  margin-bottom: 40px;
}

.sidebar {
  position: sticky;
  top: calc(var(--nav-height) + 20px);
  height: fit-content;
  max-height: calc(100vh - var(--nav-height) - 40px);
  overflow-y: auto;
  contain: layout style;
}

.widget {
  background: var(--bg-card);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  contain: layout;
}

.widget h3 {
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary);
  font-size: 16px;
}

.category-list {
  list-style: none;
}

.category-list li {
  margin-bottom: 6px;
}

.category-list a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  color: var(--text);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
  min-height: 40px;
  font-size: 14px;
}

.category-list a:hover,
.category-list li.active a {
  background: var(--primary);
  color: #fff;
}

.category-list .count {
  font-size: 12px;
  color: var(--text-light);
  flex-shrink: 0;
  margin-left: 8px;
}

.category-list li.active .count {
  color: rgba(255, 255, 255, 0.8);
}

/* ── 文章卡片 ── */
.post-card {
  background: var(--bg-card);
  padding: 28px;
  margin-bottom: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition), transform var(--transition);
  contain: layout style;
}

.post-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.post-title {
  margin-bottom: 10px;
  font-size: 22px;
  line-height: 1.4;
}

.post-title a {
  color: var(--text);
  text-decoration: none;
}

.post-title a:hover {
  color: var(--primary);
}

.post-meta {
  color: var(--text-light);
  font-size: 13px;
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.post-meta a {
  color: var(--primary);
  text-decoration: none;
}

.post-meta a:hover {
  text-decoration: underline;
}

.post-summary {
  color: var(--text-muted);
  margin-bottom: 14px;
  font-size: 14px;
  line-height: 1.6;
}

.read-more {
  display: inline-flex;
  align-items: center;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  min-height: 44px;
  gap: 4px;
}

.read-more:hover {
  color: var(--primary-dark);
}

/* ── 分页 ── */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.pagination a {
  padding: 10px 20px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  border-radius: var(--radius-sm);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  font-size: 14px;
  transition: background var(--transition);
}

.pagination a:hover {
  background: var(--primary-dark);
}

.page-info {
  font-size: 14px;
  color: var(--text-light);
}

/* ── 文章详情 ── */
.article-detail {
  background: var(--bg-card);
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 30px;
  contain: layout;
}

.article-header {
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--border);
}

.article-header h1 {
  font-size: 28px;
  margin-bottom: 14px;
  line-height: 1.35;
}

/* ── Markdown 渲染 ── */
.markdown-body {
  line-height: 1.8;
  font-size: 16px;
  word-break: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin-top: 32px;
  margin-bottom: 14px;
  font-weight: 700;
  scroll-margin-top: calc(var(--nav-height) + 20px);
  line-height: 1.3;
}

.markdown-body h1 {
  font-size: 26px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 10px;
}

.markdown-body h2 {
  font-size: 22px;
}

.markdown-body h3 {
  font-size: 18px;
}

.markdown-body p {
  margin-bottom: 16px;
}

.markdown-body code {
  background: #f4f4f4;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.markdown-body pre {
  background: #282c34;
  color: #abb2bf;
  padding: 20px;
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 20px 0;
  font-size: 14px;
  line-height: 1.5;
  contain: layout;
}

.markdown-body pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

.markdown-body blockquote {
  border-left: 4px solid var(--primary);
  padding: 8px 20px;
  margin: 20px 0;
  color: var(--text-light);
  font-style: italic;
  background: #fafafa;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.markdown-body ul,
.markdown-body ol {
  margin-left: 24px;
  margin-bottom: 16px;
  padding-left: 8px;
}

.markdown-body li {
  margin-bottom: 6px;
}

.markdown-body a {
  color: var(--primary);
  text-decoration: none;
  word-break: break-all;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: 20px 0;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  overflow-x: auto;
  display: block;
}

.markdown-body th,
.markdown-body td {
  padding: 10px 14px;
  border: 1px solid var(--border);
  text-align: left;
  font-size: 14px;
}

.markdown-body th {
  background: #f8f9fa;
  font-weight: 600;
}

/* ── 评论区 ── */
.comments-section {
  margin-top: 40px;
  padding-top: 30px;
  border-top: 2px solid var(--border);
}

.comments-section h2 {
  margin-bottom: 24px;
  font-size: 20px;
}

.comment-list {
  margin-bottom: 30px;
}

.comment-item {
  background: var(--bg);
  padding: 20px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  word-break: break-word;
}

.comment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 13px;
  flex-wrap: wrap;
  gap: 8px;
}

.comment-header strong {
  color: var(--primary);
}

.comment-header time {
  color: var(--text-light);
  font-size: 12px;
}

.comment-content {
  line-height: 1.6;
  font-size: 14px;
}

.no-comments {
  text-align: center;
  color: var(--text-light);
  padding: 30px 20px;
  font-size: 14px;
}

/* ── 评论表单 ── */
.comment-form {
  background: var(--bg);
  padding: 28px;
  border-radius: var(--radius);
}

.comment-form h3 {
  margin-bottom: 20px;
  font-size: 16px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  background: var(--bg-card);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.form-group textarea {
  resize: vertical;
  min-height: 100px;
}

.form-group input {
  min-height: 44px;
}

.help-text {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 4px;
  display: block;
}

/* ── 验证码 ── */
.captcha-wrapper {
  display: flex;
  gap: 10px;
  align-items: center;
}

.captcha-input {
  flex: 1;
  max-width: 140px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 18px;
  letter-spacing: 4px;
  text-align: center;
  font-weight: 700;
  min-height: 44px;
  background: var(--bg-card);
}

.captcha-image {
  height: 44px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--border);
  flex-shrink: 0;
  transition: opacity var(--transition);
}

.captcha-image:hover {
  opacity: 0.85;
}

/* ── 按钮 ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 22px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  min-height: 44px;
  transition: background var(--transition), box-shadow var(--transition);
  gap: 6px;
}

.btn:hover {
  background: var(--primary-dark);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
}

.btn-danger {
  background: var(--danger);
}

.btn-danger:hover {
  background: #c0392b;
}

.btn-small {
  padding: 6px 14px;
  font-size: 12px;
  min-height: 32px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: inherit;
  transition: background var(--transition);
}

.btn-small:hover {
  background: var(--primary-dark);
}

/* ── 认证页面 ── */
.auth-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 60vh;
  padding: 20px 0;
}

.auth-card {
  background: var(--bg-card);
  padding: 36px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 420px;
}

.auth-card h1 {
  text-align: center;
  margin-bottom: 28px;
  color: #2c3e50;
  font-size: 22px;
}

.auth-card .form-group {
  margin-bottom: 18px;
}

.auth-card label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 14px;
}

.auth-card input[type="text"],
.auth-card input[type="password"],
.auth-card input[type="email"] {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-height: 48px;
  font-family: inherit;
  background: var(--bg-card);
}

.auth-card input:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.btn-full {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  margin-top: 8px;
  min-height: 48px;
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 14px;
}

.auth-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.auth-footer a:hover {
  text-decoration: underline;
}

.login-hint {
  text-align: center;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text-light);
}

/* ── 邮箱验证码 ── */
.email-verify-row {
  display: flex;
  gap: 10px;
}

.email-verify-row input {
  flex: 1;
  min-height: 44px;
}

.email-verify-row .btn {
  white-space: nowrap;
  min-height: 44px;
  flex-shrink: 0;
}

/* ── 个人资料 ── */
.profile-page {
  display: flex;
  justify-content: center;
  padding: 20px 0;
}

.profile-card {
  background: var(--bg-card);
  padding: 36px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 600px;
}

.profile-card h1 {
  text-align: center;
  margin-bottom: 28px;
  color: #2c3e50;
  font-size: 22px;
}

.profile-avatar-section {
  text-align: center;
  margin-bottom: 28px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.profile-avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid var(--border);
  margin-bottom: 14px;
}

.avatar-upload-btn {
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  transition: background var(--transition);
}

.avatar-upload-btn:hover {
  background: var(--primary-dark);
}

.profile-section {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.profile-section:last-of-type {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.profile-section h3 {
  margin-bottom: 14px;
  color: #2c3e50;
  font-size: 15px;
}

.profile-section .form-group {
  margin-bottom: 14px;
}

.profile-section label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-light);
}

.profile-section input[type="text"],
.profile-section input[type="password"] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  min-height: 44px;
  font-family: inherit;
  background: var(--bg-card);
}

.profile-section input:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.profile-info p {
  margin-bottom: 8px;
  color: var(--text-light);
  font-size: 14px;
}

/* ── 页脚 ── */
.footer {
  background: var(--bg-card);
  padding: 28px 0;
  text-align: center;
  color: var(--text-light);
  margin-top: 50px;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
  font-size: 13px;
}

/* ── 错误页面 ── */
.error-page {
  text-align: center;
  padding: 80px 20px;
}

.error-page h1 {
  font-size: 72px;
  color: var(--primary);
  margin-bottom: 16px;
  line-height: 1;
}

.error-page h2 {
  font-size: 24px;
  margin-bottom: 16px;
  color: #2c3e50;
}

.error-page p {
  color: var(--text-light);
  margin-bottom: 24px;
  font-size: 15px;
}

/* ── 空状态 ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-state p {
  font-size: 16px;
  color: var(--text-light);
  margin-bottom: 20px;
}

/* ── 文章页脚 ── */
.article-footer {
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
}

/* ── 打印样式 ── */
@media print {
  .navbar,
  .footer,
  .skip-link,
  .comment-form,
  .article-footer {
    display: none !important;
  }

  .main-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  body {
    background: #fff;
    color: #000;
    font-size: 12pt;
  }

  .article-detail,
  .post-card,
  .widget {
    box-shadow: none;
    border: 1px solid #ddd;
  }

  a {
    color: #000 !important;
    text-decoration: underline !important;
  }
}

/* =====================================================
   响应式设计
   ===================================================== */

/* 平板 */
@media (max-width: 1024px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
    overflow-y: visible;
  }
}

/* 手机 */
@media (max-width: 768px) {
  .container {
    padding: 0 16px;
  }

  .navbar .container {
    flex-direction: column;
    gap: 6px;
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .navbar {
    height: auto;
    min-height: var(--nav-height);
  }

  .nav-links {
    flex-wrap: wrap;
    justify-content: center;
    gap: 2px;
  }

  .nav-links a,
  .nav-links [role="menuitem"] {
    font-size: 13px;
    padding: 6px 10px;
    min-height: 36px;
  }

  .user-greeting {
    font-size: 12px;
    padding: 2px 10px;
    margin-left: 4px;
  }

  .sidebar {
    position: static;
  }

  .post-card {
    padding: 20px;
  }

  .post-title {
    font-size: 18px;
  }

  .article-detail {
    padding: 20px;
  }

  .article-header h1 {
    font-size: 22px;
  }

  .auth-card {
    padding: 24px;
  }

  .profile-card {
    padding: 24px;
  }

  .comment-form {
    padding: 20px;
  }

  .markdown-body pre {
    font-size: 13px;
    padding: 14px;
  }

  .markdown-body table {
    font-size: 13px;
  }

  .email-verify-row {
    flex-direction: column;
  }

  .captcha-wrapper {
    flex-wrap: wrap;
  }

  .captcha-input {
    max-width: 100%;
    flex: 1;
  }
}

/* 小屏手机 */
@media (max-width: 480px) {
  .nav-links a,
  .nav-links [role="menuitem"] {
    padding: 6px 8px;
    font-size: 12px;
  }

  .post-card {
    padding: 16px;
  }

  .post-meta {
    font-size: 12px;
    gap: 8px;
  }

  .article-detail {
    padding: 16px;
  }

  .markdown-body {
    font-size: 15px;
  }

  .pagination {
    gap: 10px;
  }

  .pagination a {
    padding: 8px 14px;
    font-size: 13px;
  }

  .markdown-body pre {
    font-size: 12px;
    padding: 12px;
  }
}
