:root {
  color-scheme: light;
  --paper: #f6f2ea;
  --surface: #fffaf1;
  --surface-strong: #fffdf8;
  --ink: #1f2528;
  --muted: #6f7474;
  --line: rgba(38, 45, 46, 0.14);
  --line-strong: rgba(38, 45, 46, 0.24);
  --accent: #247b68;
  --accent-dark: #155d4e;
  --accent-soft: rgba(36, 123, 104, 0.12);
  --warm: #d66a35;
  --shadow: 0 20px 60px rgba(43, 38, 30, 0.12);
  --radius: 8px;
  --sidebar: 296px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(36, 123, 104, 0.08) 0 1px, transparent 1px 84px),
    linear-gradient(180deg, rgba(36, 123, 104, 0.06) 0 1px, transparent 1px 84px),
    var(--paper);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: rgba(255, 250, 241, 0.88);
  backdrop-filter: blur(18px);
  padding: 28px 20px;
}

.brand-block {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 30px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  background: var(--ink);
  color: #fffaf1;
  border-radius: var(--radius);
  font-family: "Songti SC", "STSong", serif;
  font-size: 25px;
  font-weight: 800;
  box-shadow: 0 10px 28px rgba(31, 37, 40, 0.16);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.12;
  letter-spacing: 0;
}

.sidebar-section {
  padding: 20px 0;
  border-top: 1px solid var(--line);
}

.section-label {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 740;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.42);
  padding: 3px;
}

.segment {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 720;
}

.segment.is-active {
  background: var(--ink);
  color: var(--surface);
}

.chip-list,
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.subcategory-list {
  max-height: 220px;
  overflow: auto;
  padding-right: 2px;
}

.category-tree {
  display: grid;
  gap: 7px;
  max-height: 360px;
  overflow: auto;
  padding-right: 2px;
}

.tree-item {
  display: grid;
  gap: 7px;
}

.tree-parent {
  display: grid;
  grid-template-columns: 13px minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.46);
  color: var(--ink);
  padding: 7px 9px;
  text-align: left;
  font-size: 13px;
  font-weight: 690;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.tree-parent:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
}

.tree-parent.is-active {
  border-color: rgba(36, 123, 104, 0.45);
  background: var(--accent);
  color: #fff;
}

.tree-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-parent small {
  color: currentColor;
  opacity: 0.66;
  font-size: 11px;
  font-weight: 720;
}

.tree-chevron {
  width: 7px;
  height: 7px;
  border-right: 1.8px solid currentColor;
  border-bottom: 1.8px solid currentColor;
  opacity: 0.62;
  transform: rotate(-45deg);
  transition: transform 160ms ease;
}

.tree-item.is-expanded .tree-chevron {
  transform: rotate(45deg);
}

.tree-children {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-left: 13px;
  padding: 1px 0 5px 12px;
  border-left: 1px solid var(--line);
}

.tree-children .filter-chip {
  min-height: 28px;
  padding: 5px 9px;
  font-size: 12px;
}

.filter-chip {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink);
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 650;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.filter-chip:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
}

.filter-chip.is-active {
  border-color: rgba(36, 123, 104, 0.45);
  background: var(--accent);
  color: #fff;
}

.filter-chip small {
  margin-left: 5px;
  color: currentColor;
  opacity: 0.68;
}

.tag-cloud .filter-chip {
  font-size: 12px;
  min-height: 30px;
}

.workspace {
  min-width: 0;
  padding: 34px clamp(18px, 4vw, 56px) 56px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 440px);
  gap: 24px;
  align-items: end;
}

.search-wrap {
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 14px;
  top: 50%;
  width: 19px;
  height: 19px;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
}

.search-wrap input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 241, 0.82);
  color: var(--ink);
  outline: 0;
  padding: 0 14px 0 44px;
  box-shadow: 0 10px 30px rgba(43, 38, 30, 0.06);
}

.search-wrap input:focus {
  border-color: rgba(36, 123, 104, 0.48);
  box-shadow: 0 0 0 4px rgba(36, 123, 104, 0.11);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin: 28px 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}

.summary-strip div {
  min-height: 82px;
  background: rgba(255, 250, 241, 0.82);
  padding: 16px;
}

.summary-strip strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 30px;
  line-height: 1;
}

.summary-strip span {
  color: var(--muted);
  font-size: 13px;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  min-height: 36px;
  gap: 8px;
  align-items: center;
  margin-bottom: 18px;
}

.active-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 5px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.active-pill button {
  display: grid;
  width: 20px;
  height: 20px;
  margin-left: 6px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: rgba(31, 37, 40, 0.08);
  color: var(--ink);
}

.cards-view,
.graph-view {
  display: none;
}

.cards-view.is-active,
.graph-view.is-active {
  display: block;
}

.masonry {
  columns: 4 248px;
  column-gap: 16px;
}

.note-card {
  position: relative;
  display: inline-block;
  width: 100%;
  margin: 0 0 16px;
  break-inside: avoid;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 241, 0.9);
  color: var(--ink);
  padding: 16px;
  text-align: left;
  box-shadow: 0 10px 28px rgba(43, 38, 30, 0.06);
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    border-color 180ms ease;
}

.note-card:hover {
  transform: translateY(-3px);
  border-color: rgba(36, 123, 104, 0.35);
  box-shadow: 0 18px 42px rgba(43, 38, 30, 0.12);
}

.load-more-card {
  border-style: dashed;
  background: rgba(36, 123, 104, 0.08);
}

.load-more-card::before {
  background: var(--warm);
}

.note-card::before {
  content: "";
  display: block;
  width: 46px;
  height: 4px;
  margin-bottom: 14px;
  border-radius: 999px;
  background: var(--accent);
}

.note-card h3 {
  margin: 0 0 8px;
  font-size: 20px;
  line-height: 1.25;
  letter-spacing: 0;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.meta-badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.note-card p {
  margin-bottom: 14px;
  color: #40484b;
  font-size: 14px;
  line-height: 1.7;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 760;
}

.relation-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.empty-state {
  display: grid;
  min-height: 220px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.empty-state p {
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 20px;
  font-weight: 760;
}

.graph-stage {
  position: relative;
  overflow: hidden;
  min-height: 70vh;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(31, 78, 121, 0.032) 0 1px, transparent 1px 44px),
    linear-gradient(180deg, rgba(31, 78, 121, 0.028) 0 1px, transparent 1px 44px),
    linear-gradient(180deg, #ffffff 0%, #fffdf7 58%, #faf5ea 100%);
  box-shadow: 0 18px 44px rgba(43, 38, 30, 0.08);
}

.graph-panel {
  position: absolute;
  z-index: 2;
  width: min(310px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  padding: 12px;
  box-shadow: 0 14px 34px rgba(43, 38, 30, 0.08);
  backdrop-filter: blur(14px);
}

.graph-panel h4 {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.2;
}

.graph-panel p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.graph-help-button {
  position: absolute;
  z-index: 3;
  top: 14px;
  left: 14px;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 26px rgba(43, 38, 30, 0.08);
  color: var(--muted);
  font-size: 15px;
  font-weight: 820;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(14px);
}

.graph-help-button:hover,
.graph-help-button[aria-expanded="true"] {
  border-color: rgba(31, 78, 121, 0.24);
  color: var(--ink);
}

.graph-help-panel {
  top: 56px;
  left: 14px;
  width: min(340px, calc(100% - 28px));
}

.graph-help-section,
.graph-help-panel details {
  border-top: 1px solid var(--line);
  padding: 8px 0 0;
}

.graph-help-section:first-of-type,
.graph-help-panel details:first-of-type {
  border-top: 0;
}

.graph-help-section h5,
.graph-help-panel summary {
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 780;
}

.graph-help-panel summary {
  cursor: pointer;
}

.graph-help-panel p {
  margin-bottom: 8px;
}

.metric-row {
  display: flex;
  min-height: 28px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.metric-row strong {
  color: var(--ink);
  font-size: 12px;
  text-align: right;
}

#graphCanvas {
  display: block;
  width: 100%;
  height: 74vh;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

#graphCanvas:active {
  cursor: grabbing;
}

.graph-hint {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  margin: 10px;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.note-dialog {
  width: min(860px, calc(100vw - 32px));
  max-height: min(840px, calc(100vh - 32px));
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  padding: 0;
  color: var(--ink);
}

.note-dialog::backdrop {
  background: rgba(31, 37, 40, 0.38);
  backdrop-filter: blur(8px);
}

.note-panel {
  position: relative;
  max-height: min(840px, calc(100vh - 32px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: clamp(22px, 5vw, 40px);
  box-shadow: var(--shadow);
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.close-button {
  position: sticky;
  z-index: 2;
  top: 0;
  float: right;
}

.detail-title {
  margin: 0 48px 12px 0;
  font-size: clamp(30px, 5vw, 48px);
  line-height: 1.08;
  letter-spacing: 0;
}

.detail-path {
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.detail-preview {
  margin: 24px 0;
  color: #343c3f;
  font-size: 17px;
  line-height: 1.9;
}

.markdown-body p {
  margin: 0 0 16px;
}

.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 26px 0 10px;
  color: var(--ink);
  line-height: 1.28;
}

.markdown-body h3 {
  font-size: 22px;
}

.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  font-size: 18px;
}

.markdown-body a,
.markdown-body .md-wikilink {
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  padding: 0;
  font: inherit;
  font-weight: 740;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.markdown-body blockquote {
  margin: 18px 0;
  border-left: 4px solid rgba(36, 123, 104, 0.35);
  background: rgba(36, 123, 104, 0.07);
  padding: 14px 16px;
  color: #465052;
}

.markdown-body blockquote p:last-child {
  margin-bottom: 0;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0 0 16px 20px;
  padding: 0;
}

.markdown-body li {
  margin: 6px 0;
}

.markdown-body code {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.72);
  padding: 1px 5px;
  font-size: 0.92em;
}

.markdown-body pre {
  margin: 18px 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(31, 37, 40, 0.92);
  color: #fffaf1;
  padding: 14px 16px;
  line-height: 1.65;
}

.markdown-body pre code {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 13px;
}

.markdown-body hr {
  margin: 24px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.md-table-wrap {
  margin: 18px 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(255, 255, 255, 0.55);
  font-size: 14px;
  line-height: 1.6;
}

.markdown-body th,
.markdown-body td {
  border-bottom: 1px solid var(--line);
  padding: 9px 11px;
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background: rgba(36, 123, 104, 0.08);
  color: var(--ink);
  font-weight: 760;
}

.markdown-body tr:last-child td {
  border-bottom: 0;
}

.md-image {
  margin: 18px 0;
}

.md-image img {
  max-width: 100%;
  border-radius: var(--radius);
}

.md-embed {
  display: inline-flex;
  max-width: 100%;
  border: 1px solid rgba(36, 123, 104, 0.24);
  border-radius: 999px;
  background: rgba(36, 123, 104, 0.08);
  color: var(--accent-dark);
  padding: 2px 9px;
  font-size: 0.92em;
  font-weight: 720;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.detail-box {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.detail-box h4 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.link-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.text-link {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 720;
  text-decoration: none;
}

.text-link:hover {
  border-color: rgba(36, 123, 104, 0.45);
  color: var(--accent-dark);
}

@media (max-width: 960px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .tags-panel {
    display: none;
  }

  .workspace {
    padding-top: 24px;
  }

  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
  }
}

@media (max-width: 620px) {
  .summary-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .masonry {
    columns: 1;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .graph-panel {
    position: relative;
    inset: auto;
    width: auto;
    margin: 10px 10px 0;
  }

  .graph-help-button {
    top: 10px;
    left: 10px;
  }

  .graph-hint {
    position: relative;
    right: auto;
    bottom: auto;
    margin: 10px;
  }
}
