/* ========================================
   MD Reader — Design System & Styles
   ======================================== */

/* ---------- CSS Custom Properties ---------- */
:root {
  /* Brand */
  --brand-hue: 230;
  --brand: hsl(var(--brand-hue) 65% 55%);
  --brand-light: hsl(var(--brand-hue) 70% 62%);
  --brand-dim: hsl(var(--brand-hue) 40% 44%);
  --brand-bg: hsl(var(--brand-hue) 70% 96%);

  /* Surfaces */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fb;
  --bg-tertiary: #f1f3f6;
  --bg-elevated: #ffffff;
  --bg-inset: #eef0f4;

  /* Text */
  --text-primary: #1a1d26;
  --text-secondary: #5a6070;
  --text-tertiary: #8b92a5;
  --text-on-brand: #ffffff;

  /* Borders */
  --border-primary: #e2e5eb;
  --border-secondary: #eef0f4;
  --border-focus: var(--brand);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.1), 0 8px 20px rgba(0,0,0,0.06);

  /* Code */
  --code-bg: #f5f7fa;
  --code-border: #e2e5eb;
  --code-text: #d63384;

  /* Misc */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --toolbar-height: 52px;
  --tabs-height: 38px;
  --current-tabs-height: 0px;
  --toc-width: 280px;
  --outline-width: 260px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.35s cubic-bezier(0.4, 0, 0.2, 1);

  /* Content */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-serif: 'Noto Serif SC', 'Source Han Serif SC', 'Georgia', serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Consolas', monospace;
  --content-font-family: var(--font-sans);
  --content-max-width: 820px;
  --content-font-size: 17px;
  --content-line-height: 1.8;
  --content-columns: 1;

  /* Scrollbar */
  --scrollbar-width: 6px;
  --scrollbar-bg: transparent;
  --scrollbar-thumb: rgba(0,0,0,0.15);
  --scrollbar-thumb-hover: rgba(0,0,0,0.25);

  /* Highlight search */
  --search-highlight: hsl(48 100% 65%);
  --search-highlight-active: hsl(30 100% 55%);
}

/* ---------- Dark Theme ---------- */
[data-theme="dark"] {
  --brand: hsl(var(--brand-hue) 70% 65%);
  --brand-light: hsl(var(--brand-hue) 75% 72%);
  --brand-dim: hsl(var(--brand-hue) 50% 55%);
  --brand-bg: hsl(var(--brand-hue) 30% 14%);

  --bg-primary: #0f1117;
  --bg-secondary: #161820;
  --bg-tertiary: #1c1f2a;
  --bg-elevated: #1e2130;
  --bg-inset: #13151c;

  --text-primary: #e4e7ee;
  --text-secondary: #9ba1b2;
  --text-tertiary: #6a7086;
  --text-on-brand: #ffffff;

  --border-primary: #2a2e3d;
  --border-secondary: #22253100;
  --border-focus: var(--brand);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.4);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.5);

  --code-bg: #1a1d28;
  --code-border: #2a2e3d;
  --code-text: #f0a6ca;

  --scrollbar-thumb: rgba(255,255,255,0.12);
  --scrollbar-thumb-hover: rgba(255,255,255,0.22);

  --search-highlight: hsl(48 80% 35%);
  --search-highlight-active: hsl(30 90% 45%);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition-normal), color var(--transition-normal);
  overflow: hidden;
}

body.has-tabs {
  --current-tabs-height: var(--tabs-height);
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: var(--scrollbar-width); height: var(--scrollbar-width); }
::-webkit-scrollbar-track { background: var(--scrollbar-bg); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

::selection {
  background: hsl(var(--brand-hue) 60% 80%);
  color: var(--text-primary);
}
[data-theme="dark"] ::selection {
  background: hsl(var(--brand-hue) 50% 30%);
}

/* ---------- Reading Progress ---------- */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 1000;
  background: transparent;
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.reading-progress.visible { opacity: 1; }

.reading-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--brand), var(--brand-light));
  border-radius: 0 2px 2px 0;
  transition: width 0.1s linear;
}

/* ---------- Toolbar ---------- */
.toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--toolbar-height);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 900;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: background var(--transition-normal), border-color var(--transition-normal);
}

[data-theme="dark"] .toolbar { background: rgba(15, 17, 23, 0.85); }
[data-theme="light"] .toolbar { background: rgba(255, 255, 255, 0.85); }

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.toolbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 480px;
  margin: 0 16px;
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border-primary);
  margin: 0 8px;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.toolbar-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.toolbar-btn.active {
  background: var(--brand-bg);
  color: var(--brand);
}

.logo-btn {
  width: auto;
  gap: 8px;
  padding: 0 10px;
  font-weight: 600;
}

.logo-text { font-size: 14px; letter-spacing: -0.3px; color: var(--text-primary); }
.file-name { font-size: 13px; color: var(--text-tertiary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.doc-stats { font-size: 12px; color: var(--text-tertiary); white-space: nowrap; display: flex; align-items: center; gap: 12px; }
.doc-stats span { display: flex; align-items: center; gap: 4px; }

/* Dropdown menu */
.toolbar-dropdown-container {
  position: relative;
}

.toolbar-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 6px;
  min-width: 120px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--transition-fast);
  z-index: 1000;
}

.toolbar-dropdown-container:hover .toolbar-dropdown,
.toolbar-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-primary);
  border-radius: 4px;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.dropdown-item:hover {
  background: var(--bg-tertiary);
}

/* ---------- Tabs ---------- */
.tabs-container {
  position: fixed;
  top: var(--toolbar-height);
  left: 0;
  right: 0;
  height: var(--tabs-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 6px;
  overflow-x: auto;
  z-index: 890;
}
.tabs-container::-webkit-scrollbar {
  height: 0;
}

.tab {
  display: flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
  max-width: 180px;
  flex-shrink: 0;
}
.tab:hover {
  background: var(--bg-elevated);
}
.tab.active {
  background: var(--bg-primary);
  color: var(--brand);
  border-color: var(--brand);
  font-weight: 500;
}

.tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 6px;
}

.tab-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  color: var(--text-tertiary);
  margin-right: -4px;
}
.tab-close:hover {
  background: rgba(0,0,0,0.1);
  color: var(--text-primary);
}
[data-theme="dark"] .tab-close:hover {
  background: rgba(255,255,255,0.1);
}

/* ---------- Search ---------- */
.search-container {
  display: flex;
  align-items: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-md);
  padding: 0 12px;
  height: 36px;
  width: 100%;
  transition: all var(--transition-fast);
}

.search-container:focus-within {
  border-color: var(--brand);
  background: var(--bg-primary);
  box-shadow: 0 0 0 3px hsl(var(--brand-hue) 60% 50% / 0.12);
}

.search-icon { color: var(--text-tertiary); flex-shrink: 0; }
.search-input {
  flex: 1; border: none; background: transparent; color: var(--text-primary);
  font-size: 13.5px; font-family: inherit; padding: 0 8px; outline: none; min-width: 0;
}
.search-input::placeholder { color: var(--text-tertiary); }
.search-results-count { font-size: 11px; color: var(--text-tertiary); white-space: nowrap; padding: 0 6px; }

.search-nav-btn, .search-clear-btn {
  display: flex; align-items: center; justify-content: center; width: 24px; height: 24px;
  border: none; background: transparent; color: var(--text-tertiary); border-radius: 4px; cursor: pointer; transition: all var(--transition-fast);
}
.search-nav-btn:hover, .search-clear-btn:hover { background: var(--border-primary); color: var(--text-primary); }

/* ---------- Font Size Popover ---------- */
.popover {
  position: fixed; background: var(--bg-elevated); border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-lg); z-index: 950;
  opacity: 0; visibility: hidden; transform: translateY(-8px); transition: all var(--transition-normal); min-width: 260px;
}
.popover.visible { opacity: 1; visibility: visible; transform: translateY(0); }
.popover-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-tertiary); margin-bottom: 12px; }
.popover-divider { height: 1px; background: var(--border-primary); margin: 16px 0; }
.font-size-slider-container { display: flex; align-items: center; gap: 12px; }
.font-size-label { font-size: 13px; color: var(--text-tertiary); width: 20px; text-align: center; flex-shrink: 0; }
.font-size-label-lg { font-size: 18px; }
.font-size-slider {
  flex: 1; -webkit-appearance: none; appearance: none; height: 4px; background: var(--bg-tertiary); border-radius: 2px; outline: none;
}
.font-size-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; background: var(--brand); border-radius: 50%;
  cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,0.15); transition: transform var(--transition-fast);
}
.font-size-slider::-webkit-slider-thumb:hover { transform: scale(1.15); }
.font-size-value { text-align: center; font-size: 12px; color: var(--text-tertiary); margin-top: 6px; }

.font-family-selector { display: flex; gap: 8px; }
.font-btn { flex: 1; padding: 6px 0; border: 1px solid var(--border-primary); background: var(--bg-tertiary); color: var(--text-secondary); font-size: 13px; border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition-fast); }
.font-btn:hover { background: var(--bg-elevated); }
.font-btn.active { background: var(--brand-bg); color: var(--brand); border-color: var(--brand); font-weight: 500; }
.font-btn[data-font="sans"] { font-family: var(--font-sans); }
.font-btn[data-font="serif"] { font-family: var(--font-serif); }
.font-btn[data-font="mono"] { font-family: var(--font-mono); }

/* ---------- Main Layout ---------- */
.main-layout {
  display: flex;
  height: 100vh;
  padding-top: calc(var(--toolbar-height) + var(--current-tabs-height));
  transition: all var(--transition-normal);
}

.main-layout.edit-mode .content-area {
  flex: 1;
  border-left: 1px solid var(--border-primary);
}

/* ---------- Editor Area ---------- */
.editor-area {
  display: none;
  flex: 1;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'JetBrains Mono', 'Cascadia Code', monospace;
  font-size: 14.5px;
  line-height: 1.6;
  padding: 40px;
  border: none;
  resize: none;
  outline: none;
  white-space: pre-wrap;
}

.main-layout.edit-mode .editor-area {
  display: block;
}

/* ---------- History Sidebar ---------- */
.history-sidebar {
  position: fixed;
  top: calc(var(--toolbar-height) + var(--current-tabs-height));
  left: 0;
  bottom: 0;
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-primary);
  z-index: 850;
  transform: translateX(-100%);
  transition: transform var(--transition-slow);
  display: flex;
  flex-direction: column;
}

.history-sidebar.open {
  transform: translateX(0);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.history-item {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  margin-bottom: 6px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.history-item:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow-sm);
}

.history-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-meta {
  font-size: 11px;
  color: var(--text-tertiary);
  display: flex;
  justify-content: space-between;
}

.history-item-delete {
  color: hsl(0 70% 55%);
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  font-size: 11px;
}

.history-item:hover .history-item-delete {
  opacity: 1;
}

/* ---------- TOC Sidebar ---------- */
.toc-sidebar {
  width: var(--toc-width);
  min-width: var(--toc-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(-100%);
  margin-left: calc(-1 * var(--toc-width));
  transition: transform var(--transition-slow), margin var(--transition-slow);
}
.toc-sidebar.open { transform: translateX(0); margin-left: 0; }
.toc-header {
  display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-secondary); flex-shrink: 0;
}
.toc-header h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-tertiary); }
.toc-close-btn {
  display: flex; align-items: center; justify-content: center; width: 28px; height: 28px;
  border: none; background: transparent; color: var(--text-tertiary); border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition-fast);
}
.toc-close-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.toc-nav { flex: 1; overflow-y: auto; padding: 12px 8px; }
.toc-item {
  display: block; padding: 6px 12px; font-size: 13px; color: var(--text-secondary); text-decoration: none; border-radius: var(--radius-sm);
  cursor: pointer; transition: all var(--transition-fast); line-height: 1.5; border-left: 2px solid transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toc-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.toc-item.active { background: var(--brand-bg); color: var(--brand); border-left-color: var(--brand); font-weight: 500; }
.toc-item[data-level="2"] { padding-left: 28px; }
.toc-item[data-level="3"] { padding-left: 44px; font-size: 12.5px; }
.toc-item[data-level="4"] { padding-left: 56px; font-size: 12px; }
.toc-item[data-level="5"] { padding-left: 68px; font-size: 12px; }
.toc-item[data-level="6"] { padding-left: 78px; font-size: 11.5px; }

/* ---------- Outline Sidebar ---------- */
.outline-sidebar {
  width: var(--outline-width); min-width: var(--outline-width); background: var(--bg-secondary);
  border-left: 1px solid var(--border-primary); display: flex; flex-direction: column; overflow: hidden;
  transform: translateX(100%); margin-right: calc(-1 * var(--outline-width)); transition: transform var(--transition-slow), margin var(--transition-slow);
}
.outline-sidebar.open { transform: translateX(0); margin-right: 0; }
.outline-content { flex: 1; overflow-y: auto; padding: 12px 16px; font-size: 13px; color: var(--text-secondary); line-height: 1.7; }
.outline-section { margin-bottom: 16px; }
.outline-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-tertiary); margin-bottom: 6px; }
.outline-stat { display: flex; justify-content: space-between; padding: 3px 0; }
.outline-stat-label { color: var(--text-tertiary); }
.outline-stat-value { font-weight: 500; color: var(--text-primary); font-variant-numeric: tabular-nums; }

/* ---------- Content Area ---------- */
.content-area { flex: 1; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; position: relative; }

/* ---------- Welcome Screen ---------- */
.welcome-screen { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - var(--toolbar-height)); padding: 40px 24px; }
.welcome-inner { text-align: center; max-width: 520px; animation: fadeInUp 0.6s ease; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.welcome-icon { color: var(--brand); margin-bottom: 20px; opacity: 0.8; }
.welcome-title { font-size: 36px; font-weight: 700; letter-spacing: -1px; background: linear-gradient(135deg, var(--brand), var(--brand-light)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; margin-bottom: 8px; }
.welcome-subtitle { font-size: 16px; color: var(--text-tertiary); margin-bottom: 36px; }
.welcome-drop-zone { border: 2px dashed var(--border-primary); border-radius: var(--radius-xl); padding: 40px 24px; margin-bottom: 28px; cursor: pointer; transition: all var(--transition-normal); }
.welcome-drop-zone:hover, .welcome-drop-zone.drag-over { border-color: var(--brand); background: var(--brand-bg); }
.welcome-drop-zone.drag-over { transform: scale(1.02); }
.drop-zone-content { display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--text-secondary); }
.drop-zone-content p { font-size: 15px; font-weight: 500; }
.drop-zone-hint { font-size: 13px; color: var(--text-tertiary); }
.welcome-actions { display: flex; gap: 12px; justify-content: center; margin-bottom: 36px; flex-wrap: wrap; }
.welcome-btn { display: flex; align-items: center; gap: 8px; padding: 10px 20px; border: 1px solid var(--border-primary); background: var(--bg-elevated); color: var(--text-primary); font-size: 14px; font-weight: 500; font-family: inherit; border-radius: var(--radius-md); cursor: pointer; transition: all var(--transition-fast); }
.welcome-btn:hover { border-color: var(--brand); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.welcome-btn.primary { background: var(--brand); border-color: var(--brand); color: var(--text-on-brand); }
.welcome-btn.primary:hover { background: var(--brand-light); border-color: var(--brand-light); box-shadow: var(--shadow-md); }
.welcome-shortcuts { padding-top: 8px; }
.welcome-shortcuts h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-tertiary); margin-bottom: 14px; }
.shortcut-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.shortcut-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-tertiary); justify-content: center; }
kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 5px; background: var(--bg-tertiary); border: 1px solid var(--border-primary); border-radius: 4px; font-size: 11px; font-family: inherit; font-weight: 500; color: var(--text-secondary); box-shadow: 0 1px 0 var(--border-primary); }

/* ---------- Markdown Body ---------- */
.markdown-body {
  font-family: var(--content-font-family);
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 48px 40px 120px;
  font-size: var(--content-font-size);
  line-height: var(--content-line-height);
  color: var(--text-primary);
  animation: fadeIn 0.35s ease;
  column-count: var(--content-columns);
  column-gap: 40px;
}

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

/* Headings */
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4, .markdown-body h5, .markdown-body h6 {
  font-weight: 600; line-height: 1.35; margin-top: 2em; margin-bottom: 0.6em; color: var(--text-primary); letter-spacing: -0.3px; scroll-margin-top: calc(var(--toolbar-height) + var(--current-tabs-height) + 20px);
}
.markdown-body h1 { font-size: 2em; font-weight: 700; letter-spacing: -0.5px; padding-bottom: 0.4em; border-bottom: 2px solid var(--border-primary); margin-top: 0; }
.markdown-body h2 { font-size: 1.55em; padding-bottom: 0.3em; border-bottom: 1px solid var(--border-secondary); }
.markdown-body h3 { font-size: 1.3em; } .markdown-body h4 { font-size: 1.1em; } .markdown-body h5 { font-size: 1em; } .markdown-body h6 { font-size: 0.9em; color: var(--text-secondary); }

.heading-anchor { opacity: 0; color: var(--brand); text-decoration: none; margin-left: 8px; font-weight: 400; transition: opacity var(--transition-fast); }
.markdown-body h1:hover .heading-anchor, .markdown-body h2:hover .heading-anchor, .markdown-body h3:hover .heading-anchor, .markdown-body h4:hover .heading-anchor, .markdown-body h5:hover .heading-anchor, .markdown-body h6:hover .heading-anchor { opacity: 0.6; }
.heading-anchor:hover { opacity: 1 !important; }

/* Paragraphs & Inline */
.markdown-body p { margin-bottom: 1.2em; }
.markdown-body a { color: var(--brand); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color var(--transition-fast); }
.markdown-body a:hover { border-bottom-color: var(--brand); }
.markdown-body strong { font-weight: 600; }
.markdown-body em { font-style: italic; }
.markdown-body del { color: var(--text-tertiary); text-decoration: line-through; }
.markdown-body mark, .search-mark { background: var(--search-highlight); color: inherit; padding: 1px 3px; border-radius: 2px; }
.search-mark.active { background: var(--search-highlight-active); box-shadow: 0 0 0 2px var(--search-highlight-active); }

/* Lists */
.markdown-body ul, .markdown-body ol { margin-bottom: 1.2em; padding-left: 1.8em; }
.markdown-body li { margin-bottom: 0.4em; }
.markdown-body li > ul, .markdown-body li > ol { margin-top: 0.4em; margin-bottom: 0.4em; }
.markdown-body .task-list-item { list-style: none; margin-left: -1.4em; }
.markdown-body .task-list-item input[type="checkbox"] { margin-right: 8px; accent-color: var(--brand); transform: scale(1.1); }

/* Blockquote */
.markdown-body blockquote { margin: 0 0 1.2em; padding: 12px 20px; border-left: 4px solid var(--brand); background: var(--brand-bg); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--text-secondary); }
.markdown-body blockquote > p:last-child { margin-bottom: 0; }

/* Alerts */
.markdown-body .alert { padding: 12px 20px; margin: 0 0 1.2em; border-radius: var(--radius-sm); border-left: 4px solid; }
.markdown-body .alert-note { background: hsl(210 80% 96%); border-left-color: hsl(210 80% 55%); }
.markdown-body .alert-tip { background: hsl(150 60% 95%); border-left-color: hsl(150 60% 40%); }
.markdown-body .alert-important { background: hsl(270 60% 96%); border-left-color: hsl(270 60% 55%); }
.markdown-body .alert-warning { background: hsl(40 80% 95%); border-left-color: hsl(40 80% 50%); }
.markdown-body .alert-caution { background: hsl(0 70% 96%); border-left-color: hsl(0 70% 55%); }
[data-theme="dark"] .markdown-body .alert-note { background: hsl(210 40% 14%); }
[data-theme="dark"] .markdown-body .alert-tip { background: hsl(150 30% 14%); }
[data-theme="dark"] .markdown-body .alert-important { background: hsl(270 30% 14%); }
[data-theme="dark"] .markdown-body .alert-warning { background: hsl(40 30% 14%); }
[data-theme="dark"] .markdown-body .alert-caution { background: hsl(0 30% 14%); }

/* Code */
.markdown-body code { font-family: 'JetBrains Mono', 'Cascadia Code', monospace; font-size: 0.875em; background: var(--code-bg); border: 1px solid var(--code-border); border-radius: 4px; padding: 2px 6px; color: var(--code-text); }
.markdown-body pre { position: relative; margin-bottom: 1.4em; border-radius: var(--radius-md); overflow: hidden; background: var(--code-bg); border: 1px solid var(--code-border); }
.markdown-body pre code { display: block; padding: 20px; overflow-x: auto; font-size: 13.5px; line-height: 1.6; border: none; background: transparent; color: inherit; }
.code-block-header { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px 6px 16px; background: var(--bg-tertiary); border-bottom: 1px solid var(--code-border); font-size: 12px; color: var(--text-tertiary); }
.code-lang { font-family: 'JetBrains Mono', monospace; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.code-copy-btn { display: flex; align-items: center; gap: 5px; padding: 4px 10px; border: none; background: transparent; color: var(--text-tertiary); font-size: 12px; font-family: inherit; border-radius: 4px; cursor: pointer; transition: all var(--transition-fast); }
.code-copy-btn:hover { background: var(--border-primary); color: var(--text-primary); }
.code-copy-btn.copied { color: hsl(150 60% 45%); }

/* Mermaid */
.mermaid { text-align: center; margin-bottom: 1.4em; }

/* Table */
.markdown-body table { width: 100%; border-collapse: collapse; margin-bottom: 1.4em; font-size: 0.92em; overflow-x: auto; display: block; }
.markdown-body thead { background: var(--bg-tertiary); }
.markdown-body th { font-weight: 600; text-align: left; padding: 10px 14px; border: 1px solid var(--border-primary); white-space: nowrap; }
.markdown-body td { padding: 10px 14px; border: 1px solid var(--border-primary); }
.markdown-body tbody tr:hover { background: var(--brand-bg); }

/* HR & Images & Footnotes */
.markdown-body hr { border: none; height: 2px; background: var(--border-primary); margin: 2em 0; border-radius: 1px; }
.markdown-body img { max-width: 100%; height: auto; border-radius: var(--radius-md); margin: 8px 0; box-shadow: var(--shadow-sm); }
.markdown-body .footnotes { border-top: 1px solid var(--border-primary); margin-top: 2em; padding-top: 1em; font-size: 0.9em; color: var(--text-secondary); }

/* ---------- Back to Top ---------- */
.back-to-top {
  position: fixed; bottom: 32px; right: 32px; width: 44px; height: 44px; border: none; background: var(--bg-elevated); color: var(--text-secondary);
  border-radius: 50%; box-shadow: var(--shadow-md); cursor: pointer; display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transform: translateY(12px); transition: all var(--transition-normal); z-index: 800;
}
.back-to-top.visible { opacity: 1; visibility: visible; transform: translateY(0); }
.back-to-top:hover { background: var(--brand); color: var(--text-on-brand); box-shadow: var(--shadow-lg); transform: translateY(-2px); }

/* ---------- Modals (Paste & Settings) ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: center; justify-content: center;
  z-index: 1000; opacity: 0; visibility: hidden; transition: all var(--transition-normal); backdrop-filter: blur(4px);
}
.modal-overlay.visible { opacity: 1; visibility: visible; }
.modal {
  background: var(--bg-elevated); border: 1px solid var(--border-primary); border-radius: var(--radius-lg); box-shadow: var(--shadow-xl);
  width: 90%; max-width: 640px; max-height: 80vh; display: flex; flex-direction: column; transform: scale(0.95) translateY(10px); transition: transform var(--transition-normal);
}
.modal-overlay.visible .modal { transform: scale(1) translateY(0); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 16px; }
.modal-header h3 { font-size: 18px; font-weight: 600; }
.modal-close-btn {
  display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: none; background: transparent;
  color: var(--text-tertiary); border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition-fast);
}
.modal-close-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.modal-body { flex: 1; padding: 0 24px; overflow: auto; }
.settings-section { margin-bottom: 20px; }
.settings-section h4 { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.settings-desc { font-size: 12px; color: var(--text-tertiary); margin-bottom: 12px; }
.paste-textarea {
  width: 100%; height: 320px; border: 1px solid var(--border-primary); border-radius: var(--radius-md); padding: 16px;
  font-family: 'JetBrains Mono', monospace; font-size: 13.5px; line-height: 1.6; background: var(--bg-secondary); color: var(--text-primary);
  resize: vertical; outline: none; transition: border-color var(--transition-fast);
}
.paste-textarea:focus { border-color: var(--brand); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px 20px; }
.modal-btn {
  padding: 8px 20px; border: 1px solid var(--border-primary); background: var(--bg-elevated); color: var(--text-primary);
  font-size: 14px; font-weight: 500; font-family: inherit; border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition-fast);
}
.modal-btn:hover { background: var(--bg-tertiary); }
.modal-btn.primary { background: var(--brand); border-color: var(--brand); color: var(--text-on-brand); }
.modal-btn.primary:hover { background: var(--brand-light); }

/* ---------- Toast & Drag Overlay ---------- */
.toast-container { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%); z-index: 1100; display: flex; flex-direction: column-reverse; align-items: center; gap: 8px; }
.toast { padding: 10px 20px; background: var(--text-primary); color: var(--bg-primary); font-size: 13.5px; font-weight: 500; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); animation: toastIn 0.35s ease, toastOut 0.35s ease 2.5s forwards; white-space: nowrap; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastOut { from { opacity: 1; transform: translateY(0) scale(1); } to { opacity: 0; transform: translateY(-8px) scale(0.95); } }

.drag-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; z-index: 1200; opacity: 0; visibility: hidden; transition: all var(--transition-normal); }
.drag-overlay.visible { opacity: 1; visibility: visible; }
.drag-overlay-content { display: flex; flex-direction: column; align-items: center; gap: 16px; color: white; font-size: 20px; font-weight: 500; }

/* Theme Icons */
[data-theme="dark"] .theme-icon-light { display: none !important; }
[data-theme="dark"] .theme-icon-dark { display: block !important; }
[data-theme="light"] .theme-icon-light { display: block; }
[data-theme="light"] .theme-icon-dark { display: none; }

[data-theme="dark"] #hljs-theme-light { disabled: true; }
[data-theme="light"] #hljs-theme-dark { disabled: true; }

/* ---------- Print & Export Styles ---------- */
.export-hide {
  display: none !important;
}

@media print {
  .toolbar, .toc-sidebar, .outline-sidebar, .reading-progress, .back-to-top, .heading-anchor, .code-block-header, .history-sidebar { display: none !important; }
  .main-layout { padding-top: 0; }
  .main-layout.edit-mode .editor-area { display: none !important; }
  .main-layout.edit-mode .content-area { border-left: none; }
  .markdown-body { max-width: 100%; padding: 0; font-size: 12pt; }
  .markdown-body pre { border: 1px solid #ddd; page-break-inside: avoid; }
  .markdown-body img { page-break-inside: avoid; }
  .markdown-body h1, .markdown-body h2, .markdown-body h3 { page-break-after: avoid; }
}

@media (max-width: 768px) {
  .toolbar-center { display: none; }
  .doc-stats { display: none; }
  .logo-text { display: none; }
  .welcome-title { font-size: 28px; }
  .shortcut-grid { grid-template-columns: repeat(2, 1fr); }
  .markdown-body { padding: 24px 20px 80px; }
  .main-layout.edit-mode { flex-direction: column; }
  .main-layout.edit-mode .content-area { border-left: none; border-top: 1px solid var(--border-primary); }
  .toc-sidebar, .outline-sidebar, .history-sidebar { position: fixed; top: calc(var(--toolbar-height) + var(--current-tabs-height)); bottom: 0; z-index: 850; box-shadow: var(--shadow-lg); }
  .toc-sidebar { left: 0; } .outline-sidebar { right: 0; }
}
