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

:root {
  --bg: #fafaf8;
  --bg-sidebar: #f3f2ef;
  --text: #1a1a1a;
  --text-muted: #6b6b6b;
  --border: #e5e3dd;
  --accent: #5b7a6f;
  --accent-hover: #3d5a4f;
  --card-bg: #fff;
  --code-bg: #f5f4f0;
  --highlight-border: #e0ddd6;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "Source Code Pro", "Fira Code", Consolas, monospace;
  --sidebar-width: 260px;
}

:root[data-theme="dark"] {
  --bg: #0b1220;
  --bg-sidebar: #0f172a;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --border: #1f2937;
  --accent: #76b39d;
  --accent-hover: #9cd3c2;
  --card-bg: #111827;
  --code-bg: #0b1324;
  --highlight-border: #25304a;
}

html { font-size: 16px; scroll-behavior: smooth; color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.15s, color 0.15s;
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

/* === Layout === */
.layout { display: flex; min-height: 100vh; }

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 10;
  transition: transform 0.25s ease;
}

.sidebar-header {
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.sidebar-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.sidebar-title:hover { color: var(--accent); }

.theme-toggle {
  font-size: 0.75rem;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  position: relative;
  z-index: 30;
}
.theme-toggle:hover { border-color: var(--accent); }

.topbar {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.search-toggle {
  font-size: 0.75rem;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
}
.search-toggle:hover { border-color: var(--accent); }

.skip-link {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  transform: translateY(-200%);
  transition: transform 0.15s ease;
  z-index: 100;
}
.skip-link:focus { transform: translateY(0); }

.search-dialog {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(720px, calc(100% - 2rem));
}
.search-dialog::backdrop { background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(6px); }
.search-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}
.search-bar { display: flex; gap: 0.5rem; }
.search-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.search-close {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
}
.search-close:hover { border-color: var(--accent); color: var(--text); }
.search-results { margin-top: 0.75rem; max-height: 60vh; overflow: auto; }
.search-item {
  display: block;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
}
.search-item:hover,
.search-item.is-active { background: var(--code-bg); }
.search-item-title { font-weight: 600; }
.search-item-meta { margin-top: 0.15rem; font-size: 0.8rem; color: var(--text-muted); }

/* === Tree Navigation === */
.tree { list-style: none; font-size: 0.875rem; }
.tree li { margin: 0; }
.tree-folder, .tree-file { position: relative; }

.tree-toggle {
  cursor: pointer;
  user-select: none;
  font-size: 0.625rem;
  color: var(--text-muted);
  display: inline-block;
  width: 14px;
  text-align: center;
  vertical-align: middle;
  background: transparent;
  border: 0;
  padding: 0;
}

.tree-folder-name {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
}

.tree-link {
  text-decoration: none;
  color: var(--text);
  display: inline-block;
  padding: 2px 4px;
  border-radius: 3px;
  transition: background 0.1s;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
.tree-link:hover { background: var(--border); }
.vault-link { font-weight: 600; color: var(--text); }
.file-link { font-size: 0.85rem; }

.tree-children { padding-left: 16px; list-style: none; }

/* Highlight current file in sidebar */
.file-link[data-current="true"] {
  background: var(--accent);
  color: #fff;
}

/* === Sidebar Toggle (mobile) === */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 20;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.hamburger {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  position: relative;
}
.hamburger::before, .hamburger::after {
  content: '';
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  position: absolute;
  left: 0;
}
.hamburger::before { top: -6px; }
.hamburger::after { top: 6px; }

/* === Main Content === */
.content {
  flex: 1;
  max-width: 1040px;
  padding: 2.5rem 2rem 4rem;
  margin: 0 auto;
}

/* === Breadcrumbs === */
.breadcrumbs {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}
.breadcrumbs a {
  color: var(--text-muted);
  text-decoration: none;
}
.breadcrumbs a:hover { color: var(--accent); text-decoration: underline; }
.breadcrumbs .sep { margin: 0 0.35rem; color: var(--border); }
.breadcrumbs .current { color: var(--text); font-weight: 500; }

/* === Home Page === */
.home-hero {
  text-align: center;
  padding: 3rem 0 2.5rem;
}
.home-title {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.home-subtitle {
  margin-top: 0.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.vault-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
}

.vault-card {
  display: block;
  padding: 1.5rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.vault-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.vault-card-title {
  font-size: 1.15rem;
  font-weight: 600;
}
.vault-card-desc {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.vault-card-stats {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* === Vault Index === */
.vault-header { margin-bottom: 2rem; }
.vault-header h1 { font-size: 1.9rem; font-weight: 700; }
.vault-description { margin-top: 0.25rem; color: var(--text-muted); font-size: 1rem; }
.vault-actions { margin-top: 0.6rem; font-size: 0.9rem; }
.vault-actions a { color: var(--accent); text-decoration: none; }
.vault-actions a:hover { text-decoration: underline; }

.graph-container {
  height: calc(100vh - 260px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  overflow: hidden;
}

.note-listing { margin-top: 1rem; }
.note-group { margin-bottom: 1.75rem; }
.note-group-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

.note-list { list-style: none; }
.note-item { margin: 0; }
.note-link {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.4rem 0;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}
.note-link:hover { border-bottom-color: var(--border); }
.note-item-title { font-size: 1rem; }
.note-tags { display: flex; gap: 0.35rem; flex-shrink: 0; }
.tag {
  font-size: 0.7rem;
  background: var(--code-bg);
  color: var(--text-muted);
  padding: 1px 6px;
  border-radius: 3px;
  white-space: nowrap;
}

/* === Note Page === */
.note-layout { display: flex; align-items: flex-start; gap: 2rem; }
.note-main { flex: 1; min-width: 0; max-width: 760px; }
.note-toc {
  width: 240px;
  position: sticky;
  top: 1.25rem;
  padding: 0.75rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
}
.note-toc-title { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.5rem; }
.note-toc .toc { font-size: 0.85rem; }
.note-toc .toc ul { list-style: none; padding-left: 0; }
.note-toc .toc li { margin: 0.2rem 0; }
.note-toc .toc ul ul { padding-left: 0.9rem; margin-top: 0.2rem; }
.note-toc a { color: var(--text-muted); text-decoration: none; }
.note-toc a:hover { color: var(--accent); text-decoration: underline; }
.note-toc a.is-active { color: var(--accent); font-weight: 600; text-decoration: none; }

.note-toc-mobile { display: none; margin: 1rem 0; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 8px; background: var(--card-bg); }
.note-toc-mobile summary { cursor: pointer; font-weight: 600; color: var(--text-muted); }
.note-toc-mobile .toc { margin-top: 0.5rem; }
.note-toc-mobile .toc ul { list-style: none; padding-left: 0; }
.note-toc-mobile .toc ul ul { padding-left: 0.9rem; }

.note-header { margin-bottom: 2rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
.note-title { font-size: 1.6rem; font-weight: 700; line-height: 1.35; }
.note-summary { margin-top: 0.65rem; color: var(--text-muted); font-size: 1rem; }
.note-meta { margin-top: 0.5rem; }
.note-dates { margin-top: 0.35rem; font-size: 0.8rem; color: var(--text-muted); }

/* === Note Content Typography === */
.note-content { overflow-wrap: break-word; }
.note-content h1 { font-size: 1.5rem; font-weight: 700; margin: 2rem 0 0.75rem; scroll-margin-top: 1.25rem; text-wrap: balance; }
.note-content h2 { font-size: 1.25rem; font-weight: 600; margin: 1.75rem 0 0.6rem; scroll-margin-top: 1.25rem; text-wrap: balance; }
.note-content h3 { font-size: 1.1rem; font-weight: 600; margin: 1.5rem 0 0.5rem; scroll-margin-top: 1.25rem; text-wrap: balance; }
.note-content h4 { font-size: 1rem; font-weight: 600; margin: 1.25rem 0 0.4rem; scroll-margin-top: 1.25rem; text-wrap: balance; }
.note-content h5, .note-content h6 { font-weight: 600; margin: 1rem 0 0.3rem; }

.note-content p { margin: 0.75rem 0; }
.note-content a { color: var(--accent); text-decoration: none; }
.note-content a:hover { text-decoration: underline; }
.note-content strong { font-weight: 600; }
.note-content em { font-style: italic; }

.note-content ul, .note-content ol { margin: 0.6rem 0; padding-left: 1.5rem; }
.note-content li { margin: 0.25rem 0; }
.note-content blockquote {
  margin: 1rem 0;
  padding: 0.5rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--code-bg);
  color: var(--text-muted);
}

.note-content hr { margin: 2rem 0; border: none; border-top: 1px solid var(--border); }

/* === Tables === */
.note-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}

.site-footer {
  margin-top: 2.5rem;
  padding: 1.25rem 0;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.site-footer a { color: var(--accent); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.note-content th, .note-content td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border: 1px solid var(--border);
}
.note-content th {
  background: var(--code-bg);
  font-weight: 600;
}
.note-content tr:nth-child(even) { background: var(--bg); }

.table-wrap { overflow-x: auto; margin: 1rem 0; }
.table-wrap table { margin: 0; min-width: 520px; }

/* === Code === */
.note-content code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--code-bg);
  padding: 2px 5px;
  border-radius: 3px;
}

.note-content pre {
  margin: 1rem 0;
  padding: 1rem;
  background: var(--code-bg);
  border: 1px solid var(--highlight-border);
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
}
.code-block { position: relative; margin: 1rem 0; }
.code-block pre { margin: 0; }
.code-copy {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 0.75rem;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
}
.code-copy:hover { border-color: var(--accent); color: var(--text); }
.note-content pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

/* Pygments code highlighting */
.highlight .hll { background-color: #ffc; }
.highlight .c { color: #8b8b7a; font-style: italic; }   /* Comment */
.highlight .k { color: #a05020; font-weight: bold; }    /* Keyword */
.highlight .o { color: #666; }                           /* Operator */
.highlight .s { color: #4a8c3f; }                        /* String */
.highlight .n { color: #333; }                           /* Name */
.highlight .p { color: #666; }                           /* Punctuation */
.highlight .nb { color: #2e6b3f; }                       /* Builtin */
.highlight .nc { color: #3a5f8f; font-weight: bold; }    /* Class */
.highlight .nf { color: #5b3f8f; }                       /* Function */
.highlight .nd { color: #707; }                          /* Decorator */
.highlight .mi { color: #8f5f2f; }                       /* Number */
.highlight .mf { color: #8f5f2f; }                       /* Float */
.highlight .kc { color: #a05020; font-weight: bold; }    /* Keyword.Constant */
.highlight .kd { color: #a05020; font-weight: bold; }    /* Keyword.Declaration */
.highlight .kn { color: #a05020; font-weight: bold; }    /* Keyword.Namespace */
.highlight .kp { color: #a05020; }                       /* Keyword.Pseudo */
.highlight .kr { color: #a05020; font-weight: bold; }    /* Keyword.Reserved */
.highlight .kt { color: #3a5f8f; font-weight: bold; }    /* Keyword.Type */
.highlight .m  { color: #8f5f2f; }                       /* Literal.Number */

/* === Callouts === */
.callout {
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  border-left: 4px solid var(--accent);
  background: var(--code-bg);
}
.callout .callout-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  color: var(--accent);
}
.callout p { margin: 0.35rem 0; }

.callout-summary { border-left-color: #5b7a6f; }
.callout-note { border-left-color: #4a8cc7; }
.callout-warning { border-left-color: #d4a03c; }
.callout-danger, .callout-error { border-left-color: #c74a4a; }
.callout-tip, .callout-success { border-left-color: #4a8c3f; }
.callout-info { border-left-color: #5b8fbf; }
.callout-abstract { border-left-color: #7a6f9f; }
.callout-question { border-left-color: #c78f3f; }

.callout-summary .callout-title { color: #5b7a6f; }
.callout-note .callout-title { color: #4a8cc7; }
.callout-warning .callout-title { color: #d4a03c; }
.callout-danger .callout-title, .callout-error .callout-title { color: #c74a4a; }
.callout-tip .callout-title, .callout-success .callout-title { color: #4a8c3f; }
.callout-info .callout-title { color: #5b8fbf; }
.callout-abstract .callout-title { color: #7a6f9f; }
.callout-question .callout-title { color: #c78f3f; }

/* === Note Backlinks === */
.note-backlinks {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.note-backlinks h2 { font-size: 1rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.note-backlinks ul { list-style: none; }
.note-backlinks li { margin: 0.25rem 0; font-size: 0.9rem; }
.note-backlinks a { color: var(--accent); text-decoration: none; }
.note-backlinks a:hover { text-decoration: underline; }

/* === Images === */
.note-content img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 0.75rem 0;
}
.note-content img { cursor: zoom-in; }

.note-content .figure { margin: 1rem 0; }
.note-content .figure img { display: block; margin: 0 auto; }
.note-content .figcaption { margin-top: 0.5rem; font-size: 0.85rem; color: var(--text-muted); text-align: center; }

.image-dialog {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(1100px, calc(100% - 2rem));
}
.image-dialog::backdrop { background: rgba(0, 0, 0, 0.65); backdrop-filter: blur(6px); }
.image-panel { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 0.75rem; }
.image-toolbar { display: flex; justify-content: flex-end; margin-bottom: 0.5rem; }
.image-close {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
}
.image-close:hover { border-color: var(--accent); color: var(--text); }
.image-figure { margin: 0; }
.image-figure img { width: 100%; height: auto; border-radius: 8px; cursor: zoom-out; }
.image-caption { margin-top: 0.5rem; font-size: 0.85rem; color: var(--text-muted); }

/* === Footer === */
.content-footer {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

/* === Mobile === */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    box-shadow: 2px 0 12px rgba(0,0,0,0.1);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-toggle { display: flex; }
  .sidebar-toggle.open { left: 270px; }

  .content {
    padding: 1.5rem 1rem 3rem;
    max-width: 100%;
  }

  .vault-grid { grid-template-columns: 1fr; }
  .home-title { font-size: 1.5rem; }
  .note-content pre { font-size: 0.8rem; padding: 0.75rem; }
}

@media (max-width: 1024px) {
  .note-toc { display: none; }
  .note-main { max-width: 100%; }
  .note-toc-mobile { display: block; }
}

/* === Print === */
@media print {
  .sidebar, .sidebar-toggle, .breadcrumbs, .note-backlinks { display: none; }
  .content { max-width: 100%; padding: 0; }
}
