/* ==========================================================================
   CSS Variables — 单点修改，全局生效
   ========================================================================== */
:root {
  --c-bg: #faf8f5;
  --c-surface: #fffdf9;
  --c-text: #2d2a26;
  --c-text-2: #5c5752;
  --c-text-3: #8a8278;
  --c-text-4: #b0a99e;
  --c-border: #e8e0d5;
  --c-primary: #1a7a5a;
  --c-primary-light: #ecf7f2;
  --c-primary-hover: #145f45;
  --c-danger: #dc3545;
  --c-danger-bg: #fdecea;
  --c-success: #1a7a5a;
  --c-amber: #d4952a;
  --c-gold: #b0883c;
  --c-gold-dim: #9a8b6c;
  --c-parchment: #faf7f0;

  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-pill: 9999px;

  --shadow-sm: 0 1px 3px rgba(45, 42, 38, 0.06);
  --shadow-md: 0 4px 16px rgba(45, 42, 38, 0.08);
  --shadow-lg: 0 12px 32px rgba(45, 42, 38, 0.12);
  --shadow-xl: 0 20px 48px rgba(45, 42, 38, 0.16);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
  --font-heading: "Noto Serif SC", "STSong", "SimSun", "Songti SC", serif;
  --font-mono: Consolas, "Courier New", monospace;
  --transition: 0.25s ease;
}

body.dark-theme {
  --c-bg: #1a1815;
  --c-surface: #252320;
  --c-text: #e8e4dc;
  --c-text-2: #c5bfb4;
  --c-text-3: #9a9286;
  --c-text-4: #6e685e;
  --c-border: #3a3530;
  --c-primary-light: #1e3a30;
  --c-parchment: #252320;
  --c-gold: #c9a64a;
  --c-gold-dim: #8a7d60;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.55);
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background-color: var(--c-bg);
  background-image:
    radial-gradient(circle, rgba(26,122,90,0.03) 1px, transparent 1px),
    radial-gradient(circle, rgba(180,160,140,0.04) 1px, transparent 1px);
  background-size: 24px 24px, 48px 48px;
  background-position: 0 0, 12px 12px;
  color: var(--c-text);
  line-height: 1.6;
  transition:
    background-color 0.3s,
    color 0.3s;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(26,122,90,0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 90%, rgba(212,149,42,0.03) 0%, transparent 50%);
}
body.dark-theme::before {
  background:
    radial-gradient(ellipse at 20% 10%, rgba(26,122,90,0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 90%, rgba(200,160,60,0.04) 0%, transparent 50%);
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Header & Navigation
   ========================================================================== */
.blog-header {
  background: linear-gradient(135deg, rgba(255,253,249,0.92) 0%, rgba(250,247,240,0.92) 100%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--c-border);
  padding: 12px 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}
body.dark-theme .blog-header {
  background: linear-gradient(135deg, rgba(26,24,21,0.92) 0%, rgba(37,35,32,0.92) 100%);
}

.logo {
  font-size: 22px;
  font-weight: 700;
  color: var(--c-primary);
  letter-spacing: 0.5px;
  font-family: var(--font-heading);
}

/* ── Main Navigation ── */
.blog-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.blog-nav .nav-link {
  text-decoration: none;
  color: var(--c-text-3);
  font-size: 14px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  position: relative;
}
.blog-nav .nav-link:hover {
  color: var(--c-primary);
  background: var(--c-primary-light);
}
.blog-nav .nav-link.active {
  color: var(--c-primary);
  font-weight: 600;
}
.blog-nav .nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 3px;
  background: var(--c-primary);
  border-radius: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.auth-user-area,
.auth-guest-area {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-welcome {
  font-size: 14px;
  color: var(--c-text-2);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.toggle-btn {
  background-color: var(--c-primary);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: 14px;
  transition: all var(--transition);
}
.toggle-btn:hover {
  background-color: var(--c-primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.toggle-btn:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}
.toggle-btn:active,
.toggle-btn-outline:active,
.form-submit-btn:active,
.page-btn:active,
.cat-btn:active {
  transform: scale(0.97) !important;
}
.toggle-btn:disabled,
.toggle-btn-outline:disabled,
.form-submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.toggle-btn-outline {
  background: transparent;
  color: var(--c-primary);
  border: 1px solid var(--c-primary);
  padding: 7px 15px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: 13px;
  transition: all var(--transition);
}
.toggle-btn-outline:hover {
  background: var(--c-primary);
  color: white;
}
.toggle-btn-outline:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}

/* ==========================================================================
   Layout
   ========================================================================== */
.blog-layout {
  max-width: 1200px;
  margin: 40px auto;
  padding: 0 20px;
}

.intro-section {
  margin-bottom: 40px;
  text-align: center;
  padding: 40px 20px 36px;
  background: linear-gradient(160deg, var(--c-primary-light) 0%, var(--c-bg) 60%);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}
.intro-section::before {
  content: '';
  position: absolute;
  top: -40px;
  right: -40px;
  width: 160px;
  height: 160px;
  background: radial-gradient(circle, rgba(26,122,90,0.08) 0%, transparent 70%);
  border-radius: 50%;
}
.intro-section::after {
  content: '';
  position: absolute;
  bottom: -30px;
  left: -30px;
  width: 100px;
  height: 100px;
  background: radial-gradient(circle, rgba(212,149,42,0.06) 0%, transparent 70%);
  border-radius: 50%;
}
.intro-section h1 {
  font-size: 30px;
  font-weight: 700;
  color: var(--c-text);
  margin-bottom: 8px;
  font-family: var(--font-heading);
  position: relative;
  z-index: 1;
}
.intro-section p {
  color: var(--c-text-3);
  font-size: 16px;
  position: relative;
  z-index: 1;
}

/* Search */
.search-bar {
  display: flex;
  align-items: center;
  max-width: 520px;
  margin: 0 auto 40px;
}
.search-input {
  flex: 1;
  padding: 10px 18px;
  border: 1px solid var(--c-border);
  border-right: none;
  border-radius: var(--radius-pill) 0 0 var(--radius-pill);
  outline: none;
  font-family: inherit;
  font-size: 15px;
  background: var(--c-surface);
  color: var(--c-text);
  transition:
    border-color var(--transition),
    box-shadow var(--transition);
}
.search-input:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(26, 122, 90, 0.15);
}
.search-btn {
  padding: 10px 22px;
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
  font-size: 15px;
  white-space: nowrap;
}

/* ==========================================================================
   Blog Cards
   ========================================================================== */
.blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
}

.blog-card {
  background-color: var(--c-surface);
  padding: 24px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border-left: 4px solid transparent;
  position: relative;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition:
    transform 0.3s,
    box-shadow 0.3s,
    border-color 0.3s;
}
.blog-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-left-color: var(--c-primary);
}
.blog-card:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}

.blog-card h2 {
  color: var(--c-primary);
  margin-bottom: 10px;
  font-size: 20px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--c-text-3);
  font-size: 13px;
  margin-bottom: 12px;
}

.card-content {
  color: var(--c-text-2);
  font-size: 15px;
  line-height: 1.6;
}

.card-content-preview {
  display: -webkit-box;
  -webkit-line-clamp: 5;
  line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 7.5em;
  margin-bottom: 0;
}

.card-preview-area {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.read-more-hint {
  display: inline-block;
  font-size: 13px;
  color: var(--c-primary);
  font-weight: 500;
  margin-top: 8px;
}

.card-footer {
  margin-top: auto;
  padding-top: 14px;
}

/* Hot badge */
.hot-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  background: linear-gradient(135deg, #c0392b, #e74c3c);
  color: white;
  font-size: 11px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(192, 57, 43, 0.35);
  animation: hotPulse 2s ease-in-out infinite;
}
@keyframes hotPulse {
  0%, 100% { box-shadow: 0 2px 8px rgba(192, 57, 43, 0.35); }
  50% { box-shadow: 0 4px 18px rgba(192, 57, 43, 0.55); }
}

/* ==========================================================================
   Footer
   ========================================================================== */
.blog-footer {
  text-align: center;
  padding: 48px 20px;
  color: var(--c-text-4);
  font-size: 13px;
  line-height: 1.8;
  border-top: 1px solid var(--c-border);
  margin-top: 60px;
  background: linear-gradient(0deg, var(--c-parchment) 0%, var(--c-bg) 100%);
}

/* ==========================================================================
   Scrollbar
   ========================================================================== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--c-bg); }
::-webkit-scrollbar-thumb { background: var(--c-text-4); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--c-text-3); }

/* ==========================================================================
   Card fade-in animation
   ========================================================================== */
.blog-card {
  animation: cardFadeIn 0.5s ease-out both;
}
@keyframes cardFadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Delete Button & Modal
   ========================================================================== */
.delete-card-btn {
  background-color: var(--c-danger-bg);
  color: var(--c-danger);
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.delete-card-btn:hover {
  background-color: var(--c-danger);
  color: white;
  transform: translateY(-1px);
}

.custom-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  animation: fadeIn 0.25s ease-out;
}

.custom-modal-content {
  background: var(--c-surface);
  color: var(--c-text);
  padding: 36px;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 650px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-xl);
}

.custom-modal-close {
  position: absolute;
  top: 16px;
  right: 20px;
  font-size: 26px;
  color: var(--c-text-4);
  cursor: pointer;
  transition: color var(--transition);
}
.custom-modal-close:hover {
  color: var(--c-danger);
}

.modal-title {
  color: var(--c-primary);
  font-size: 24px;
  margin-right: 28px;
}
.modal-meta {
  font-size: 13px;
  color: var(--c-text-3);
  margin-top: 8px;
}
.modal-body-text {
  font-size: 16px;
  line-height: 1.8;
  color: var(--c-text-2);
  white-space: pre-wrap;
  word-break: break-word;
}
.modal-divider {
  border: none;
  border-top: 1px solid var(--c-border);
  margin: 20px 0;
}
.modal-actions {
  margin-top: 16px;
}

/* Like button */
.like-btn {
  background: var(--c-bg);
  color: var(--c-text-2);
  border: 1px solid var(--c-border);
  padding: 8px 18px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: 14px;
  transition: all var(--transition);
}
.like-btn:hover {
  background: var(--c-danger-bg);
  border-color: #fecaca;
  color: var(--c-danger);
}
.like-btn.liked {
  background: var(--c-danger-bg);
  border-color: var(--c-danger);
  color: var(--c-danger);
}
body.dark-theme .like-btn.liked {
  background: #7f1d1d;
  border-color: var(--c-danger);
  color: #fecaca;
}

/* Comments */
.comments-section {
  margin-top: 28px;
}
.comments-title {
  font-size: 18px;
  color: var(--c-primary);
  margin-bottom: 16px;
}
.comments-list {
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 16px;
}
.comments-empty {
  color: var(--c-text-4);
  font-size: 14px;
  text-align: center;
  padding: 16px 0;
}
.comment-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--c-border);
}
.comment-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--c-text-3);
  margin-bottom: 6px;
}
.comment-meta strong {
  color: var(--c-text);
}
.comment-text {
  font-size: 14px;
  line-height: 1.6;
  color: var(--c-text-2);
  white-space: pre-wrap;
  word-break: break-word;
}
.comment-form {
  margin-top: 8px;
}
.comment-submit-btn {
  margin-top: 10px;
  width: 100%;
  border-radius: var(--radius-sm);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ==========================================================================
   Forms
   ========================================================================== */
.publish-form-container,
.login-prompt-container {
  background: var(--c-surface);
  padding: 24px;
  border-radius: var(--radius-md);
  margin-bottom: 32px;
  box-shadow: var(--shadow-sm);
}

.publish-form-title {
  margin-bottom: 14px;
  color: var(--c-primary);
  font-size: 17px;
  font-weight: 600;
}
.login-prompt-container {
  text-align: center;
}
.login-prompt-container p {
  margin-bottom: 14px;
  color: var(--c-text-3);
}

.form-field {
  margin-bottom: 14px;
}
.form-field label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--c-text-2);
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  outline: none;
  font-family: inherit;
  background: var(--c-surface);
  color: var(--c-text);
  transition:
    border-color var(--transition),
    box-shadow var(--transition);
}
.form-input:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(26, 122, 90, 0.15);
}
.form-textarea {
  resize: vertical;
}
.form-submit-btn {
  border-radius: var(--radius-sm);
  width: 100%;
}

.empty-posts {
  text-align: center;
  color: var(--c-text-4);
  grid-column: 1 / -1;
  padding: 40px;
}

/* ==========================================================================
   Auth Modal
   ========================================================================== */
.auth-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  animation: fadeIn 0.25s ease-out;
}

.auth-modal-content {
  background: var(--c-surface);
  color: var(--c-text);
  padding: 32px;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 400px;
  position: relative;
  box-shadow: var(--shadow-xl);
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}
.auth-tab {
  flex: 1;
  padding: 10px 0;
  border: none;
  border-radius: 8px;
  background: var(--c-bg);
  color: var(--c-text-3);
  cursor: pointer;
  font-size: 15px;
  transition: all var(--transition);
}
.auth-tab.active {
  background: var(--c-primary);
  color: white;
}
.auth-form.hidden {
  display: none;
}
.auth-error {
  margin-bottom: 12px;
  color: var(--c-danger);
  font-size: 14px;
}

/* ==========================================================================
   Personal Page — Images & Files
   ========================================================================== */
.image-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.post-thumb {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--c-border);
  transition: transform 0.2s;
}
.post-thumb:hover {
  transform: scale(1.05);
}

.file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.file-link {
  display: inline-block;
  padding: 5px 14px;
  background: var(--c-bg);
  border-radius: var(--radius-sm);
  color: var(--c-primary);
  text-decoration: none;
  font-size: 13px;
  transition: background var(--transition);
}
.file-link:hover {
  background: var(--c-border);
}

.upload-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--c-text-3);
}

/* ==========================================================================
   Library — Category Bar
   ========================================================================== */
.category-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 30px;
  position: relative;
  z-index: 1;
}
.cat-btn {
  padding: 6px 16px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-pill);
  background: var(--c-surface);
  color: var(--c-text-2);
  cursor: pointer;
  font-size: 14px;
  transition: all var(--transition);
}
.cat-btn:hover {
  border-color: var(--c-primary);
  color: var(--c-primary);
}
.cat-btn.active {
  background: var(--c-primary);
  color: white;
  border-color: var(--c-primary);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(26, 122, 90, 0.3);
}
.cat-btn:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}

/* Category badge (resource cards) */
.category-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: var(--c-primary-light);
  color: var(--c-primary);
  font-size: 0.8em;
}

.resource-card h2 {
  margin-bottom: 8px;
}

/* --- Library: parchment cards with gold accent --- */
.library-main .blog-card {
  background: var(--c-parchment);
  border-right: 2px solid transparent;
  transition: transform 0.25s, box-shadow 0.25s, border-color 0.25s;
}
.library-main .blog-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-right: 2px solid var(--c-gold);
}
.cat-btn:not(.active):hover {
  border-color: var(--c-gold);
  color: var(--c-gold);
}

/* ==========================================================================
   Library — Sidebar
   ========================================================================== */
.library-layout {
  display: flex;
  min-height: calc(100vh - 160px);
  max-width: 1400px;
  margin: 0 auto;
}

.library-sidebar {
  width: 250px;
  min-width: 250px;
  background: linear-gradient(180deg, #2d2a26 0%, #3d3832 50%, #2d2a26 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  border-right: 2px solid var(--c-gold);
}

body.dark-theme .library-sidebar {
  background: linear-gradient(180deg, #1a1815 0%, #252320 50%, #1a1815 100%);
  border-right-color: var(--c-gold);
}

.sidebar-brand {
  text-align: center;
  writing-mode: vertical-rl;
  text-orientation: mixed;
}
.sidebar-crown {
  font-size: 48px;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 8px rgba(176, 136, 60, 0.5));
}
.sidebar-title {
  font-size: 36px;
  font-weight: 900;
  color: var(--c-gold);
  letter-spacing: 12px;
  text-shadow: 0 0 20px rgba(176, 136, 60, 0.25);
  margin-bottom: 20px;
  font-family: "KaiTi", "楷体", "STKaiti", serif;
}
.sidebar-line {
  width: 2px;
  height: 60px;
  background: linear-gradient(180deg, transparent, var(--c-gold), transparent);
  margin: 0 auto 20px;
}
.sidebar-sub {
  font-size: 14px;
  color: var(--c-gold-dim);
  letter-spacing: 6px;
  font-family: "KaiTi", "楷体", "STKaiti", serif;
}

.library-main {
  flex: 1;
  padding: 30px;
  overflow-y: auto;
}

body.dark-theme .sidebar-crown {
  filter: drop-shadow(0 0 12px rgba(200, 160, 60, 0.65));
}

/* ==========================================================================
   Like / Star Buttons (in-card)
   ========================================================================== */
.like-btn-card,
.comment-btn-card {
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.like-btn-card:hover,
.comment-btn-card:hover {
  transform: scale(1.15);
}
.like-btn-card.liked {
  color: var(--c-danger);
}

.star-btn-card {
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 14px;
}
.star-btn-card:hover {
  transform: scale(1.15);
}
.star-btn-card.starred {
  color: var(--c-amber);
}

.comment-form-detail {
  margin-top: 12px;
}

/* ==========================================================================
   Markdown Toolbar
   ========================================================================== */
.markdown-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
  padding: 6px 10px;
  background: var(--c-bg);
  border-radius: 8px 8px 0 0;
  border: 1px solid var(--c-border);
  border-bottom: none;
}
.md-btn {
  padding: 4px 10px;
  font-size: 13px;
  border: 1px solid #cbd5e1;
  background: var(--c-surface);
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--c-text-2);
  font-family: var(--font-mono);
}
.md-btn:hover {
  background: var(--c-primary);
  color: white;
  border-color: var(--c-primary);
}
body.dark-theme .md-btn {
  border-color: #475569;
}
.md-hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--c-text-4);
}

/* ==========================================================================
   Markdown Body
   ========================================================================== */
.markdown-body {
  line-height: 1.8;
  word-wrap: break-word;
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 1.2em 0 0.6em;
  font-weight: 600;
  line-height: 1.3;
  color: var(--c-text);
}
.markdown-body h1 {
  font-size: 1.75em;
  border-bottom: 2px solid var(--c-border);
  padding-bottom: 0.3em;
}
.markdown-body h2 {
  font-size: 1.4em;
  border-bottom: 1px solid var(--c-border);
  padding-bottom: 0.25em;
}
.markdown-body h3 {
  font-size: 1.2em;
}
.markdown-body h4 {
  font-size: 1.05em;
}
.markdown-body p {
  margin: 0.6em 0;
}
.markdown-body a {
  color: var(--c-primary);
  text-decoration: underline;
}
.markdown-body ul,
.markdown-body ol {
  padding-left: 1.8em;
  margin: 0.6em 0;
}
.markdown-body li {
  margin: 0.2em 0;
}
.markdown-body blockquote {
  margin: 0.8em 0;
  padding: 0.5em 1em;
  border-left: 4px solid var(--c-primary);
  background: var(--c-bg);
  color: var(--c-text-3);
  border-radius: 0 4px 4px 0;
}
.markdown-body code {
  font-family: var(--font-mono);
  background: var(--c-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  color: #e11d48;
}
body.dark-theme .markdown-body code {
  color: #fb7185;
}
.markdown-body pre {
  margin: 0.8em 0;
  padding: 0;
  background: #1e293b;
  border-radius: 8px;
  overflow-x: auto;
  position: relative;
}
.markdown-body pre code {
  display: block;
  padding: 16px;
  background: transparent;
  color: #e2e8f0;
  font-size: 0.85em;
  line-height: 1.6;
}
.code-lang {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 11px;
  color: var(--c-text-4);
  text-transform: uppercase;
  font-family: var(--font-mono);
}
.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.8em 0;
}
.markdown-body th,
.markdown-body td {
  border: 1px solid var(--c-border);
  padding: 8px 12px;
  text-align: left;
}
.markdown-body th {
  background: var(--c-bg);
  font-weight: 600;
}
.markdown-body img {
  max-width: 100%;
  border-radius: 8px;
}
.markdown-body hr {
  border: none;
  border-top: 1px solid var(--c-border);
  margin: 1.2em 0;
}

body.dark-theme .katex {
  color: #e2e8f0;
}
body.dark-theme .katex .mord,
body.dark-theme .katex .mbin,
body.dark-theme .katex .mrel {
  color: #e2e8f0;
}

.blog-card .markdown-body h1 {
  font-size: 1.2em;
  border: none;
  padding: 0;
  margin: 0.4em 0;
}
.blog-card .markdown-body h2 {
  font-size: 1.1em;
  border: none;
  padding: 0;
  margin: 0.3em 0;
}
.blog-card .markdown-body h3 {
  font-size: 1em;
  margin: 0.3em 0;
}
.blog-card .markdown-body pre {
  max-height: 200px;
}
.blog-card .markdown-body blockquote {
  padding: 0.3em 0.8em;
  margin: 0.3em 0;
}

/* ==========================================================================
   Resource Preview Modal
   ========================================================================== */
.preview-modal {
  max-width: 1000px;
  width: 95vw;
  height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-header {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}

.preview-title {
  font-size: 1.2em;
  margin: 0 0 4px;
  padding-right: 24px;
  color: var(--c-text);
}

.preview-meta {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--c-text-3);
  flex-wrap: wrap;
}

.preview-body {
  flex: 1;
  width: 100%;
  overflow: auto;
  position: relative;
  display: block;
  text-align: center;
}

.preview-iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100% !important;
  height: 100% !important;
  border: none;
  border-radius: 4px;
}

.preview-img { display: block; margin: 0 auto; max-width: 100%; max-height: 100%; object-fit: scale-down; border-radius: 8px; transition: transform 0.15s; }
.preview-text-wrap { width: 100%; }
.preview-text {
  background: var(--c-bg); padding: 16px; border-radius: 8px;
  font-family: var(--font-mono); font-size: 13px; line-height: 1.5;
  white-space: pre-wrap; word-wrap: break-word;
  max-height: 65vh; overflow: auto; color: var(--c-text);
}
.preview-unsupported { text-align: center; padding: 40px 20px; color: var(--c-text-3); }
.preview-unsupported-icon { font-size: 56px; margin-bottom: 14px; }
.preview-hint { font-size: 13px; color: var(--c-text-4); }

.preview-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--c-border);
  flex-wrap: wrap;
  gap: 10px;
  flex-shrink: 0;
}

.preview-file-info { font-size: 11px; color: var(--c-text-4); }

/* ==========================================================================
   Herb Recognition
   ========================================================================== */
.herb-drop-zone {
  text-align: center;
  margin: 15px auto;
  max-width: 500px;
  min-height: 220px;
  border-radius: var(--radius-md);
  border: 2px dashed var(--c-border);
  background: var(--c-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    border-color var(--transition),
    background var(--transition),
    border-width 0.2s;
  cursor: pointer;
  animation: dashFlow 20s linear infinite;
  position: relative;
  overflow: hidden;
}
@keyframes dashFlow {
  0% { border-color: var(--c-border); }
  50% { border-color: rgba(26,122,90,0.25); }
  100% { border-color: var(--c-border); }
}
.herb-drop-zone.drag-over {
  border-color: var(--c-primary);
  background: var(--c-primary-light);
  border-width: 3px;
  animation: none;
}
.herb-drop-placeholder {
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--c-text-3);
  font-size: 15px;
  padding: 30px;
}
.herb-drop-icon {
  font-size: 48px;
  opacity: 0.6;
}
.herb-drop-hint {
  font-size: 12px;
  color: var(--c-text-4);
}
.herb-loading-text {
  margin-top: 12px;
  color: var(--c-text-3);
}
.herb-drop-zone img {
  max-width: 100%;
  max-height: 360px;
  object-fit: contain;
  display: block;
}

.herb-result-primary {
  text-align: center;
  padding: 20px 0;
}
.herb-result-primary .herb-name {
  font-size: 2em;
  font-weight: bold;
  color: var(--c-primary);
  margin-bottom: 8px;
}
.herb-result-primary .herb-confidence {
  font-size: 1.2em;
  color: var(--c-success);
  margin-bottom: 8px;
}
body.dark-theme .herb-result-primary .herb-confidence {
  color: #4ade80;
}

.herb-confidence-bar {
  width: 60%;
  height: 8px;
  background: var(--c-border);
  border-radius: 4px;
  margin: 0 auto;
  overflow: hidden;
}
.herb-confidence-fill {
  height: 100%;
  background: linear-gradient(90deg, #16a34a, #22c55e);
  border-radius: 4px;
  transition: width 0.5s ease;
}

.herb-top3-list {
  list-style: none;
  padding: 0;
  margin-top: 20px;
}
.herb-top3-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--c-border);
}
.herb-top3-rank {
  font-size: 1.2em;
  width: 32px;
  text-align: center;
  flex-shrink: 0;
}
.herb-top3-name {
  width: 80px;
  flex-shrink: 0;
  font-weight: 500;
}
.herb-top3-bar-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}
.herb-top3-bar {
  flex: 1;
  height: 6px;
  background: var(--c-border);
  border-radius: 3px;
  overflow: hidden;
}
.herb-top3-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}
.herb-top3-percent {
  font-size: 0.9em;
  color: var(--c-text-3);
  width: 55px;
  text-align: right;
  flex-shrink: 0;
}

.herb-class-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 0;
}
.herb-class-tag {
  display: inline-block;
  padding: 10px 20px;
  background: var(--c-bg);
  border-radius: var(--radius-pill);
  font-size: 15px;
  line-height: 1.6;
  color: var(--c-text-2);
  border: 1px solid var(--c-border);
  transition: transform 0.15s;
  white-space: nowrap;
}
.herb-class-tag:hover {
  transform: scale(1.05);
}

.herb-spinner {
  display: inline-block;
  width: 40px;
  height: 40px;
  border: 4px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: herb-spin 0.8s linear infinite;
}
@keyframes herb-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
.toast {
  position: fixed;
  top: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  z-index: 99999;
  opacity: 0;
  transform: translateX(40px);
  transition: opacity 0.35s, transform 0.35s;
  pointer-events: none;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.4;
}
.toast-show { opacity: 1; transform: translateX(0); }
.toast-icon { flex-shrink: 0; font-size: 16px; }

.toast-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.toast-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.toast-info    { background: var(--c-primary-light); color: var(--c-primary); border: 1px solid var(--c-primary); }

body.dark-theme .toast-success { background: #064e3b; color: #a7f3d0; border-color: #065f46; }
body.dark-theme .toast-error   { background: #7f1d1d; color: #fecaca; border-color: #991b1b; }
body.dark-theme .toast-info    { background: #1e3a30; color: #6ee7b7; border-color: #1a7a5a; }

/* ==========================================================================
   Back to Top Button
   ========================================================================== */
#back-to-top {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--c-primary);
  color: white;
  border: none;
  font-size: 20px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  z-index: 999;
  box-shadow: var(--shadow-md);
}
#back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
#back-to-top:hover {
  background: var(--c-primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* ==========================================================================
   Skeleton Loading
   ========================================================================== */
.skeleton-card {
  background: var(--c-surface);
  border-radius: var(--radius-md);
  padding: 24px;
  min-height: 200px;
  box-shadow: var(--shadow-sm);
}
.skeleton-line {
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--c-border) 25%, rgba(232,224,213,0.4) 50%, var(--c-border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  margin-bottom: 12px;
}
.skeleton-line:last-child { margin-bottom: 0; }
.skeleton-line.w60 { width: 60%; }
.skeleton-line.w80 { width: 80%; }
.skeleton-line.w40 { width: 40%; }
.skeleton-line.title { height: 20px; margin-bottom: 16px; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

body.dark-theme .skeleton-line {
  background: linear-gradient(90deg, var(--c-border) 25%, rgba(58,53,48,0.5) 50%, var(--c-border) 75%);
  background-size: 200% 100%;
}

/* ==========================================================================
   Image Lightbox
   ========================================================================== */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: fadeIn 0.2s ease-out;
}
.lightbox-img {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 0 60px rgba(0,0,0,0.5);
}

body.dark-theme .lightbox-overlay {
  background: rgba(0,0,0,0.95);
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 32px;
  flex-wrap: wrap;
}
.page-btn {
  padding: 6px 14px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-text-2);
  cursor: pointer;
  font-size: 14px;
  transition: all var(--transition);
}
.page-btn:hover { border-color: var(--c-primary); color: var(--c-primary); }
.page-btn.active { background: var(--c-primary); color: white; border-color: var(--c-primary); }
.page-btn:disabled { opacity: 0.4; cursor: default; }
.page-info { font-size: 13px; color: var(--c-text-4); margin: 0 8px; }

/* ==========================================================================
   Responsive — Mobile
   ========================================================================== */
@media (max-width: 640px) {
  .blog-header {
    flex-direction: column;
    gap: 10px;
    padding: 12px 16px;
  }
  .header-actions {
    justify-content: center;
    gap: 6px;
  }
  .header-actions .toggle-btn,
  .header-actions .toggle-btn-outline {
    font-size: 12px;
    padding: 5px 10px;
  }

  .blog-layout {
    margin: 24px auto;
    padding: 0 12px;
  }
  .blog-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .blog-card {
    padding: 18px;
  }

  .intro-section h1 {
    font-size: 22px;
  }
  .search-bar {
    margin-bottom: 24px;
  }

  .custom-modal-content {
    padding: 24px;
  }
  .auth-modal-content {
    padding: 24px;
  }

  .modal-title {
    font-size: 20px;
  }
}

@media (max-width: 768px) {
  .library-layout {
    flex-direction: column;
  }
  .library-sidebar {
    width: 100%;
    min-width: 100%;
    padding: 20px;
    border-right: none;
    border-bottom: 2px solid #c9a84c;
  }
  .sidebar-brand {
    writing-mode: horizontal-tb;
  }
  .sidebar-title {
    font-size: 28px;
    letter-spacing: 8px;
  }
  .sidebar-crown {
    font-size: 32px;
  }
  .sidebar-line {
    width: 80px;
    height: 2px;
    margin: 12px auto;
  }
  .library-main {
    padding: 20px;
  }
}

/* Accessibility: respect user motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
