/* ============================================================
   拾言录 — Claude-inspired Design System
   Warm cream · Amber accent · Serif titles · Airy whitespace
   ============================================================ */

/* ---- CSS Custom Properties ---- */
:root {
  /* Light theme (default) */
  --bg-root: #FBF9F5;
  --bg-layer: #F5F2ED;
  --bg-card: #FFFFFF;
  --bg-elevated: #FAFAF9;
  --bg-hover: #F7F5F0;

  --text-primary: #1C1917;
  --text-secondary: #6B6560;
  --text-tertiary: #9E9892;
  --text-link: #B45309;

  --border-default: #E7E5E1;
  --border-hover: #D1CDC7;
  --border-focus: #D97706;

  --accent: #D97706;
  --accent-light: #FDE68A;
  --accent-bg: #FFFBEB;
  --accent-hover: #B45309;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.08);
  --shadow-card: 0 1px 3px rgba(0,0,0,0.04), 0 0 0 1px rgba(0,0,0,0.03);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 99px;
  --radius-full: 50%;

  --font-serif: "Noto Serif SC", "Source Han Serif SC", "STSong", "SimSun", "Songti SC", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;

  --sidebar-width: 260px;
  --sidebar-collapsed: 0px;
  --topbar-height: 56px;
  --toc-width: 200px;

  --transition-fast: 180ms cubic-bezier(0.4,0,0.2,1);
  --transition-normal: 280ms cubic-bezier(0.4,0,0.2,1);
  --transition-slow: 380ms cubic-bezier(0.4,0,0.2,1);
}

/* ---- Dark Theme ---- */
[data-theme="dark"] {
  --bg-root: #0D0D0E;
  --bg-layer: #131316;
  --bg-card: #1A1A1D;
  --bg-elevated: #202024;
  --bg-hover: #1E1E22;

  --text-primary: #ECECEE;
  --text-secondary: #A1A1A6;
  --text-tertiary: #6B6B70;
  --text-link: #F59E0B;

  --border-default: #2A2A2E;
  --border-hover: #3E3E44;
  --border-focus: #D97706;

  --accent: #D97706;
  --accent-light: #78350F;
  --accent-bg: #1C1917;
  --accent-hover: #F59E0B;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.06);
  --shadow-card: 0 1px 3px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.04);
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-root);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; display: block; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; font-size: inherit; }
ul, ol { list-style: none; }
svg { flex-shrink: 0; }

/* ---- Progress Bar ---- */
.progress-bar {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  width: 0%;
  background: var(--accent);
  z-index: 1000;
  transition: width 100ms linear;
}

/* ---- App Layout ---- */
/* ═══════════════════════════════════════════════════════════
   TOP NAVBAR
   ═══════════════════════════════════════════════════════════ */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 4px;
  padding: 0 20px;
  height: var(--topbar-height);
  background: var(--bg-root);
  border-bottom: 1px solid var(--border-default);
}

/* Brand */
.navbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  transition: opacity var(--transition-fast);
  flex-shrink: 0;
  margin-right: 12px;
}
.navbar-logo:hover { opacity: 0.7; }
.logo-icon { color: var(--accent); }
.logo-text {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ---- Category menu bar ---- */
.navbar-menu {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 1px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: visible;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.navbar-menu::-webkit-scrollbar { display: none; }

/* Mask shown only when menu overflows */
.navbar-menu.has-overflow {
  mask-image: linear-gradient(to right, black calc(100% - 48px), transparent 100%);
  -webkit-mask-image: linear-gradient(to right, black calc(100% - 48px), transparent 100%);
}

/* Category button */
.navbar-cat {
  flex-shrink: 0;
}
.navbar-cat-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-secondary);
  transition: color var(--transition-fast), background-color var(--transition-fast);
  white-space: nowrap;
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  line-height: 1.4;
}
.navbar-cat-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.navbar-cat-btn .cat-arrow {
  width: 10px; height: 10px;
  transition: transform var(--transition-fast);
  opacity: 0.5;
}
.navbar-cat.open .navbar-cat-btn .cat-arrow {
  transform: rotate(180deg);
}

/* Direct post link in navbar */
.navbar-post-link {
  display: flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-secondary);
  transition: color var(--transition-fast), background-color var(--transition-fast);
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
}
.navbar-post-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Category dropdown panel (child of .navbar, positioned via JS) */
.navbar-cat-panel {
  position: absolute;
  top: 100%;
  /* left is set by JS */
  margin-top: 4px;
  min-width: 200px;
  max-width: 320px;
  max-height: 65vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 200;
}
.navbar-cat-panel.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Nav item (reused in mobile panel) */
.navbar-nav-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-secondary);
  transition: color var(--transition-fast), background-color var(--transition-fast);
  white-space: nowrap;
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  line-height: 1.4;
  position: relative;
}
.navbar-nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.navbar-nav-item.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 500;
}
.navbar-nav-item.active svg { color: var(--accent); }

/* Random button + dropdown */
.nav-random-wrap { position: relative; flex-shrink: 0; display: flex; align-items: center; }
.nav-random-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.nav-random-btn:hover {
  background: var(--bg-hover);
  color: var(--accent);
}
.nav-random-caret {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 32px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.nav-random-caret:hover {
  background: var(--bg-hover);
  color: var(--accent);
}
.nav-random-drop {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  display: none;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  min-width: 100px;
  white-space: nowrap;
}
.nav-random-wrap.open .nav-random-drop { display: flex; }

/* Actions area */
.navbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-left: auto;
}

/* Logo / brand (reused from old code, keep) */
.logo { display: none; }

/* Theme toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  transition: color var(--transition-fast), background-color var(--transition-fast);
  background: none;
  border: none;
  cursor: pointer;
}
.theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

/* Default light theme: show moon (to switch to dark) */
:root .icon-moon { display: inline; }
:root .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: inline; }

/* Nav section (legacy compatibility) */
.nav-section { margin-bottom: 4px; }
.nav-item { display: none; } /* old nav-item hidden */
.nav-item-home { display: none; }
.nav-item-random { display: none; }
.nav-divider { display: none; }
/* Mobile random mode toggle */
.mobile-random-mode {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 0;
  margin-top: 4px;
  border-top: 1px solid var(--border-default);
}
.random-mode-label {
  font-size: 12.5px;
  color: var(--text-tertiary);
}
.random-mode-btn {
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-layer);
  border: 1px solid var(--border-default);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.random-mode-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.random-mode-btn.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}

/* Menu tree styles (shared: desktop dropdown + mobile panel) */

/* Section header — sub-category that can expand/collapse */
.menu-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  margin-top: 1px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  transition: color var(--transition-fast), background var(--transition-fast);
  user-select: none;
}
.menu-item:first-child { margin-top: 0; }
.menu-item:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}
.menu-item .menu-arrow {
  width: 14px; height: 14px;
  flex-shrink: 0;
  transition: transform 0.25s ease;
  opacity: 0.45;
  color: var(--text-tertiary);
}
.menu-item.open .menu-arrow {
  transform: rotate(90deg);
}

/* Nested content block — indent creates visual hierarchy */
.menu-children {
  overflow: hidden;
  max-height: 0;
  padding-left: 18px;
  transition: max-height 0.3s ease;
}

/* Article link */
.menu-post {
  display: block;
  padding: 5px 10px;
  font-size: 12.5px;
  color: var(--text-secondary);
  border-radius: 6px;
  transition: color var(--transition-fast), background-color var(--transition-fast);
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.menu-post:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.menu-post.active {
  color: var(--accent);
  font-weight: 500;
}

/* Deeper nested separator — slightly smaller, lower contrast */
.menu-sep-inner {
  font-weight: 500;
  font-size: 12px;
  padding: 6px 10px;
  color: var(--text-tertiary);
}

/* Hamburger (mobile) */
.hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
}
.hamburger-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Mobile nav panel */
.mobile-nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 150;
}
.mobile-nav-panel {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 280px;
  height: 100vh;
  background: var(--bg-card);
  z-index: 151;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateX(-100%);
  transition: transform var(--transition-normal);
}
.mobile-nav-panel.open {
  transform: translateX(0);
}
.mobile-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-default);
}
.mobile-nav-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}
.mobile-nav-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  background: none;
  border: none;
  cursor: pointer;
}
.mobile-nav-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.mobile-nav-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}
.mobile-nav-body .navbar-nav-item {
  width: 100%;
  margin-bottom: 2px;
}
.mobile-nav-divider {
  height: 1px;
  background: var(--border-default);
  margin: 8px 0;
}

/* ---- Main Area ---- */
.main-area {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Topbar ---- (DEPRECATED — keeping empty for now) */
.topbar { display: none; }
.menu-btn { display: none; }
.topbar-actions { display: none; }
.topbar-theme-toggle { display: none; }
.sidebar-theme-toggle { display: none; }
.sidebar { display: none; }
.sidebar-header { display: none; }
.sidebar-nav { display: none; }
.sidebar-footer { display: none; }
.sidebar-collapse { display: none; }
.old-nav-item { position: relative; }

/* Search */
.search-box {
  flex: 1;
  max-width: 480px;
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-tertiary);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  background: var(--bg-layer);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
  font-size: 14px;
  line-height: 1.4;
}
.search-input::placeholder {
  color: var(--text-tertiary);
}
.search-input:focus {
  border-color: var(--border-focus);
  background: var(--bg-card);
}
.search-kbd {
  position: absolute;
  right: 10px;
  padding: 1px 5px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
  background: var(--bg-root);
  border: 1px solid var(--border-default);
  border-radius: 4px;
  pointer-events: none;
}
.search-input:focus ~ .search-kbd {
  opacity: 0;
}
.search-clear {
  position: absolute;
  right: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  color: var(--text-tertiary);
  transition: color var(--transition-fast), background-color var(--transition-fast);
}
.search-clear:hover {
  background: var(--border-default);
  color: var(--text-primary);
}

/* Topbar actions */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  margin-left: auto;
}
.sort-select select {
  padding: 6px 28px 6px 10px;
  background: var(--bg-layer);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 6px center;
  background-repeat: no-repeat;
  background-size: 16px;
}
.sort-select select:hover {
  border-color: var(--border-hover);
}
.result-count {
  font-size: 13px;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.topbar-theme-toggle { display: flex; }
.sidebar-theme-toggle { display: flex; }

/* ---- Active Filters ---- */
.active-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px 0;
  flex-wrap: wrap;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}
.filter-chip:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
  transform: translateY(-1px);
}
.filter-clear {
  background: none;
  border-style: dashed;
  color: var(--text-tertiary);
}

/* ---- Content ---- */
.content {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* Loading */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 80px 0;
}
.loading-spinner {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  border: 2px solid var(--border-default);
  border-top-color: var(--accent);
  animation: spin 600ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-secondary);
}
.empty-state svg { margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}
.empty-state p { font-size: 14px; }
.empty-state button {
  margin-top: 16px;
  padding: 8px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-pill);
  font-size: 14px;
  transition: background-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}
.empty-state button:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* ---- Hero (Homepage) ---- */
.hero {
  text-align: center;
  padding: 48px 0 36px;
}
.hero-title {
  font-family: var(--font-serif);
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.hero-sub {
  font-size: 15px;
  color: var(--text-tertiary);
  margin-bottom: 0;
}
.hero-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-top: 28px;
}
.hero-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.hero-stat-value {
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 600;
  color: var(--accent);
}
.hero-stat-label {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ---- Timeline (Homepage) — compact horizontal slider ---- */
.timeline-wrap {
  margin-bottom: 44px;
}
.timeline-rail-wrap {
  position: relative;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  padding: 28px 0 28px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
  /* Snap scrolling — proximity mode lets programmatic scrolls win */
  scroll-snap-type: x proximity;
}
.timeline-rail-wrap::-webkit-scrollbar {
  height: 4px;
}
.timeline-rail-wrap::-webkit-scrollbar-track {
  background: transparent;
}
.timeline-rail-wrap::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 2px;
}
.timeline-rail-wrap::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}
.timeline-rail {
  display: flex;
  align-items: center;
  gap: 0;
  position: relative;
  padding: 0;
  height: 36px;
  box-sizing: content-box;  /* padding adds to scrollable area, not deducted from content */
}
.timeline-rail::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: 2px;
  background: var(--border-default);
  border-radius: 1px;
  transform: translateY(-50%);
}
.timeline-dot {
  flex-shrink: 0;
  width: 80px;
  text-align: center;
  position: relative;
  cursor: pointer;
  z-index: 1;
  transition: transform var(--transition-fast);
  scroll-snap-align: center;
}
.timeline-dot:hover { transform: scale(1.15); }
.timeline-dot::after {
  content: '';
  display: block;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--border-hover);
  margin: 0 auto;
  transition: all var(--transition-fast);
}
.timeline-dot.active::after {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 5px var(--accent-bg);
}
.timeline-dot-label {
  display: block;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-family: var(--font-serif);
  color: var(--text-tertiary);
  white-space: nowrap;
  transition: color var(--transition-fast), font-weight var(--transition-fast);
  pointer-events: none;
}
/* Odd-index dots: label above */
.timeline-dot-odd .timeline-dot-label {
  top: -24px;
}
/* Even-index dots: label below */
.timeline-dot-even .timeline-dot-label {
  top: auto;
  bottom: -24px;
}
.timeline-dot.active .timeline-dot-label {
  color: var(--accent);
  font-weight: 600;
}
.timeline-rail-hint {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 3;
  opacity: 0.5;
  transition: opacity var(--transition-fast);
  animation: timelineHintPulse 2s ease-in-out infinite;
}
@keyframes timelineHintPulse {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 0.6; }
}
.timeline-rail-wrap:hover .timeline-rail-hint,
.timeline-rail-wrap:active .timeline-rail-hint {
  opacity: 0;
  animation: none;
}

/* Detail card — single event display */
.timeline-detail {
  max-width: 600px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
  animation: timelineFadeIn var(--transition-normal);
}
.timeline-detail:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-hover);
}
@keyframes timelineFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.timeline-detail-year {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}
.timeline-detail-ages {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}
.timeline-detail-summary {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.55;
}
.timeline-detail-body {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.65;
  max-height: 260px;
  overflow-y: auto;
}
.timeline-detail-body p {
  margin-bottom: 6px;
}
.timeline-detail-body ul {
  padding-left: 16px;
  margin-bottom: 6px;
}
.timeline-detail-body li {
  list-style: disc;
  margin-bottom: 2px;
  font-size: 13px;
}
.timeline-detail-footer {
  margin-top: 10px;
  text-align: right;
}
.timeline-detail-footer a {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.timeline-detail-footer a:hover { color: var(--accent-hover); }

@media (max-width: 640px) {
  .timeline-wrap { margin-bottom: 32px; }
  .timeline-rail-wrap { padding: 24px 0 24px; }
  .timeline-dot { width: 64px; }
  .timeline-dot::after { width: 11px; height: 11px; }
  .timeline-dot-label { font-size: 9px; }
  .timeline-dot-odd .timeline-dot-label { top: -20px; }
  .timeline-dot-even .timeline-dot-label { bottom: -20px; }
  .timeline-detail { padding: 12px 14px; }
  .timeline-detail-year { font-size: 14px; }
}

/* ---- Featured Section ---- */
.featured-section {
  margin-bottom: 40px;
}
.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.section-header-line {
  flex: 1;
  height: 1px;
  background: var(--border-default);
}
.section-header-text {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  white-space: nowrap;
}
.featured-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.featured-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal), border-color var(--transition-normal);
  box-shadow: var(--shadow-card);
}
.featured-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-hover);
}
.featured-card-image {
  aspect-ratio: 16/9;
  background: var(--bg-layer);
  overflow: hidden;
}
.featured-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}
.featured-card:hover .featured-card-image img {
  transform: scale(1.03);
}
.featured-card-image .featured-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  opacity: 0.3;
}
.featured-card-body {
  padding: 16px 18px;
}
.featured-card-title {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 6px;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.featured-card-summary {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- Article List ---- */
.article-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.article-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  position: relative;
  transition: background-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}
.article-row::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 16px;
  right: 16px;
  height: 1px;
  background: var(--border-default);
}
.article-row:last-child::after {
  display: none;
}
.article-row:hover {
  background: var(--bg-hover);
  border-color: var(--border-default);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.article-row:hover::after,
.article-row:hover + .article-row::after {
  background: transparent;
}
.article-row-left {
  flex: 1;
  min-width: 0;
}
.article-row-title {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.article-row-summary {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.article-row-summary mark {
  background: var(--accent-light);
  color: var(--accent-hover);
  padding: 0 2px;
  border-radius: 3px;
  font-weight: 500;
}
.article-row-date {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-default);
}
.pagination-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast), background-color var(--transition-fast);
  user-select: none;
}
.pagination-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}
.pagination-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  pointer-events: none;
}
.pagination-btn.disabled {
  opacity: 0.35;
  pointer-events: none;
}
.pagination-info {
  font-size: 12.5px;
  color: var(--text-tertiary);
  margin: 0 8px;
}

/* Tags */
.card-tag {
  display: inline-block;
  padding: 2px 10px;
  background: var(--bg-layer);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
  white-space: nowrap;
}
.card-tag:hover {
  background: var(--accent-bg);
  border-color: var(--accent-light);
  color: var(--accent);
  transform: translateY(-1px);
}

/* ---- Tag Cloud (improved: card grid) ---- */
.tag-cloud {
  margin-top: 48px;
  padding: 32px 0;
  border-top: 1px solid var(--border-default);
}
.tag-cloud-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}
.tag-cloud-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.tag-cloud-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  font-size: 13.5px;
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}
.tag-cloud-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}
.tag-cloud-card .tag-name {
  font-weight: 500;
}
.tag-cloud-card .tag-count {
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-layer);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

/* ============================================================
   Article Detail Page
   ============================================================ */
.article-page {
  display: flex;
  gap: 32px;
  margin: 0 auto;
  padding: 16px 0;
}
.article-body {
  flex: 1;
  min-width: 0;
}
.article-toc {
  width: var(--toc-width);
  flex-shrink: 0;
  display: none;
}
.article-toc.visible {
  display: block;
}

/* Article header */
.article-header {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-default);
}
.article-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-tertiary);
  margin-bottom: 16px;
  transition: color var(--transition-fast);
  cursor: pointer;
}
.article-back:hover { color: var(--text-primary); }
.article-post-title {
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.02em;
  margin-bottom: 14px;
  color: var(--text-primary);
}
.article-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  color: var(--text-tertiary);
}
.article-meta-dot {
  width: 3px;
  height: 3px;
  border-radius: var(--radius-full);
  background: var(--text-tertiary);
  opacity: 0.5;
}
.article-meta-tags { display: flex; gap: 6px; flex-wrap: wrap; }

/* Article content */
.article-content {
  font-size: 15px;
  line-height: 1.85;
  color: var(--text-primary);
}
.article-content h1, .article-content h2, .article-content h3, .article-content h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.35;
  margin: 32px 0 12px;
  scroll-margin-top: 80px;
}
.article-content h2 { font-size: 22px; margin-top: 40px; }
.article-content h3 { font-size: 18px; margin-top: 28px; }
.article-content h4 { font-size: 16px; }
.article-content p { margin-bottom: 14px; }
.article-content a { color: var(--text-link); text-decoration: underline; text-underline-offset: 2px; }
.article-content a:hover { color: var(--accent-hover); }
.article-content img { border-radius: var(--radius); margin: 16px auto; }
.article-content figure { margin: 20px 0; }
.article-content figure img { margin-bottom: 0; }
.article-content figcaption { font-size: 12.5px; color: var(--text-tertiary); text-align: center; margin-top: 8px; }
.article-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 16px;
  margin: 16px 0;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.article-content ul, .article-content ol {
  padding-left: 20px;
  margin-bottom: 14px;
}
.article-content li { margin-bottom: 4px; }
.article-content ul > li { list-style: disc; }
.article-content ol > li { list-style: decimal; }
.article-content hr {
  border: none;
  border-top: 1px solid var(--border-default);
  margin: 32px 0;
}
.article-content .search-highlight-mark {
  background: var(--accent-light);
  color: var(--accent-hover);
  padding: 2px 4px;
  border-radius: 3px;
  font-weight: 500;
  scroll-margin-top: 100px;
}
/* Gallery — Publii native format with data-columns and wide-wrapper support */
.article-content .gallery {
  display: flex;
  flex-wrap: wrap;
  margin: calc(1rem + 1vw) -0.25rem;
}
.gallery-wrapper {
  overflow: hidden;
}
/* Wide gallery — breaks out to fill full article width on desktop */
@media (min-width: 56.25em) {
  .gallery-wrapper--wide {
    display: flex;
    justify-content: center;
    margin-left: calc(-50vw + 50%);
    margin-right: calc(-50vw + 50%);
    padding: 0 2.5rem;
  }
  .gallery-wrapper--wide .gallery {
    max-width: calc(100vw - 5rem);
  }
}

/* Gallery items — default: 4/row desktop, 3/row tablet, 2/row mobile */
.gallery .gallery__item,
.article-content .gallery > figure,
.article-content .gallery > a {
  margin: 0;
  padding: 0.25rem;
  position: relative;
  flex: 1 0 50%;               /* mobile: 2/row */
}
@media (min-width: 30em) {
  .gallery .gallery__item,
  .article-content .gallery > figure,
  .article-content .gallery > a {
    flex: 1 0 33.333%;         /* tablet: 3/row */
  }
}
@media (min-width: 37.5em) {
  .gallery .gallery__item,
  .article-content .gallery > figure,
  .article-content .gallery > a {
    flex: 1 0 25%;             /* desktop: 4/row */
  }
}

/* data-columns overrides (matches Publii semantics) */
@media (min-width: 56.25em) {
  .gallery[data-columns="1"] .gallery__item { flex: 1 0 100%; }
  .gallery[data-columns="2"] .gallery__item { flex: 1 0 50%; }
  .gallery[data-columns="3"] .gallery__item { flex: 1 0 33.333%; }
  .gallery[data-columns="4"] .gallery__item { flex: 1 0 25%; }
  .gallery[data-columns="5"] .gallery__item { flex: 1 0 20%; }
  .gallery[data-columns="6"] .gallery__item { flex: 1 0 16.666%; }
  .gallery[data-columns="7"] .gallery__item { flex: 1 0 14.285%; }
  .gallery[data-columns="8"] .gallery__item { flex: 1 0 12.5%; }
}

.gallery .gallery__item > a,
.article-content .gallery > a {
  display: block;
  height: 100%;
  width: 100%;
}
.gallery img {
  display: block;
  width: 100%;
  object-fit: cover;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  margin: 0;
}
/* Publii gallery items have fixed-height thumbnails — maintain aspect */
.gallery .gallery__item img {
  height: 100%;
}
.gallery img:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-md);
}
.gallery figcaption {
  font-size: 12.5px;
  color: var(--text-tertiary);
  text-align: center;
  margin-top: 8px;
}
.article-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
}
.article-content th, .article-content td {
  padding: 8px 12px;
  border: 1px solid var(--border-default);
  text-align: left;
}
.article-content th {
  background: var(--bg-elevated);
  font-weight: 600;
}

/* TOC */
.toc-sticky {
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding-right: 4px;
}
.toc-sticky::-webkit-scrollbar {
  width: 3px;
}
.toc-sticky::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 3px;
}
.toc-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 12px;
}
.toc-list { display: flex; flex-direction: column; gap: 1px; }
.toc-link {
  display: block;
  padding: 4px 8px;
  font-size: 12.5px;
  color: var(--text-tertiary);
  border-radius: 5px;
  transition: color var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast);
  border-left: 2px solid transparent;
  line-height: 1.4;
}
.toc-link:hover { color: var(--text-secondary); background: var(--bg-hover); }
.toc-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-bg);
}
.toc-link.toc-h3 { padding-left: 20px; }

/* ---- Article Footer Nav (prev/next) ---- */
.article-footer-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border-default);
}
.article-footer-nav.single-nav {
  grid-template-columns: 1fr;
}
.article-nav-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
  text-align: left;
}
.article-nav-card:only-child { grid-column: 1 / -1; }
.article-nav-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-hover);
}
.article-nav-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
}
.article-nav-card.next { text-align: right; }
.article-nav-title {
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

/* ---- Related Articles ---- */
.related-section {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border-default);
}
.related-title {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
}
.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.related-card {
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}
.related-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-hover);
}
.related-card-title {
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.related-card-summary {
  font-size: 12px;
  color: var(--text-tertiary);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- Back to Top ---- */
.back-to-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal), transform var(--transition-normal), box-shadow var(--transition-normal), color var(--transition-normal), border-color var(--transition-normal);
  z-index: 50;
}
.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}
.back-to-top:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  color: var(--accent);
  border-color: var(--accent);
}

/* ---- Lightbox ---- */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox-img {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 4px;
  cursor: default;
}
.lightbox-caption {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.65);
  color: #fff;
  padding: 8px 20px;
  border-radius: 20px;
  font-family: var(--font-serif);
  font-size: 15px;
  letter-spacing: 0.05em;
  z-index: 501;
  pointer-events: none;
}
.lightbox-close-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius-full);
  color: #fff;
  z-index: 501;
  transition: background var(--transition-fast);
}
.lightbox-close-btn:hover { background: rgba(255,255,255,0.2); }

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  /* Hide desktop category menu, show hamburger */
  .navbar-menu { display: none; }
  .hamburger-btn { display: flex; }
  /* Show mobile panel */
  .mobile-nav-overlay.show { display: block; }
  .mobile-nav-panel { display: flex; }
  .mobile-nav-panel.open {
    transform: translateX(0);
  }
  /* Shrink navbar padding */
  .navbar { padding: 0 12px; }
  .article-page {
    flex-direction: column;
  }
  .article-toc {
    position: static;
    width: 100%;
    order: -1;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-default);
  }
  .toc-sticky { position: static; }
  .toc-list { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .toc-link { border-left: none; border-radius: var(--radius-pill); padding: 3px 10px; font-size: 12px; background: var(--bg-layer); }
  .toc-link.active { background: var(--accent-bg); }
}

@media (max-width: 640px) {
  .navbar { padding: 0 10px; }
  .navbar-logo .logo-text { display: none; }
  .navbar-actions .sort-select select { font-size: 12px; padding: 6px 20px 6px 8px; }
  .navbar-actions .result-count { display: none; }
  .search-box { max-width: none; }
  .search-kbd { display: none; }
  .content { padding: 16px; }
  .hero { padding: 32px 0 24px; }
  .hero-title { font-size: 28px; }
  .hero-stats { gap: 20px; }
  .hero-stat-value { font-size: 20px; }
  .featured-grid { grid-template-columns: 1fr; }
  .article-row { padding: 14px 12px; }
  .article-row-date { display: none; }
  .article-post-title { font-size: 24px; }
  .article-footer-nav { grid-template-columns: 1fr; }
  .tag-cloud-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---- Reduced Motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}
