:root {
  --bg: #0b0d10;
  --bg-2: #12161c;
  --bg-3: #1a2029;
  --panel: #0f1318;
  --border: #243041;
  --text: #e7edf5;
  --muted: #8b9bb0;
  --accent: #6ee7b7;
  --accent-2: #60a5fa;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, #132033 0%, var(--bg) 55%);
  color: var(--text);
}

.app {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100vh;
  min-height: 0;
}

.sidebar {
  background: linear-gradient(180deg, var(--panel), #0a0c10);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 16px 16px 8px;
}
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 9px;
  display: grid; place-items: center;
  font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, #34d399, #3b82f6);
  color: #041018;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }

.lifecycle {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  padding: 8px 14px 12px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.lifecycle span[data-jump] {
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.lifecycle span[data-jump]:hover {
  color: var(--accent);
  border-color: var(--border);
  background: var(--bg-2);
}
.lifecycle .arrow { opacity: 0.4; }

.search-wrap { padding: 10px 12px; }
.search-wrap input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
.search-wrap input:focus { border-color: #3b82f6; }

.nav-sections {
  overflow: auto;
  padding: 0 8px 20px;
  flex: 1;
  min-height: 0;
}

.section { margin-bottom: 14px; }
.section-title {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #0f1318ee;
  backdrop-filter: blur(6px);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 8px 6px;
  display: flex;
  justify-content: space-between;
}
.section-title .count {
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.nav-item:hover { background: var(--bg-2); border-color: var(--border); }
.nav-item.active {
  background: #163024;
  border-color: #245c45;
  color: var(--accent);
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.toolbar {
  padding: 14px 20px 10px;
  border-bottom: 1px solid var(--border);
  background: #0c1016cc;
  backdrop-filter: blur(8px);
}
.path-line {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 10px;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.status-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.status-label select {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: #3a4d66; background: #222a36; }
.btn.primary {
  background: linear-gradient(180deg, #1f6f54, #155e45);
  border-color: #2a8a68;
  color: #eafff5;
}
.btn.ghost { background: transparent; }

.viewer {
  flex: 1;
  overflow: auto;
  padding: 24px 28px 48px;
  max-width: 920px;
}
.viewer.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
}

/* markdown */
.md h1, .md h2, .md h3, .md h4 {
  line-height: 1.25;
  margin: 1.2em 0 0.45em;
  letter-spacing: -0.02em;
}
.md h1 { font-size: 1.85rem; border-bottom: 1px solid var(--border); padding-bottom: 0.35em; }
.md h2 { font-size: 1.35rem; color: #d7e4f5; }
.md h3 { font-size: 1.1rem; color: #c5d4e8; }
.md p, .md li { line-height: 1.65; color: #d5deea; }
.md a { color: var(--accent-2); }
.md code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: #18202b;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.1em 0.35em;
}
.md pre {
  background: #0a0e14;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow: auto;
}
.md pre code { background: none; border: none; padding: 0; }
.md blockquote {
  margin: 1em 0;
  padding: 0.2em 0 0.2em 14px;
  border-left: 3px solid #3b82f6;
  color: var(--muted);
}
.md table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: 14px; }
.md th, .md td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.md th { background: var(--bg-2); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }
.md ul, .md ol { padding-left: 1.4em; }
.md .frontmatter {
  background: #121820;
  border: 1px dashed #2d3c52;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 1.2em;
  font-family: var(--mono);
  font-size: 12px;
  color: #9fb2c9;
  white-space: pre-wrap;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #10151c;
  color: var(--text);
  padding: 0;
  width: min(480px, calc(100vw - 32px));
  box-shadow: 0 24px 80px #000a;
}
dialog::backdrop { background: #0009; }
#modal-form { padding: 18px 18px 14px; }
#modal-form h2 { margin: 0 0 12px; font-size: 1.1rem; }
#modal-fields label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 4px;
}
#modal-fields input,
#modal-fields textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}
#modal-fields textarea { min-height: 110px; resize: vertical; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #163024;
  border: 1px solid #2a8a68;
  color: #d9ffe9;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 50;
  box-shadow: 0 10px 40px #0008;
}
.toast.error {
  background: #2a1418;
  border-color: #8a2a3a;
  color: #ffd5dc;
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { max-height: 42vh; border-right: none; border-bottom: 1px solid var(--border); }
}
