:root {
  --bg: #0f1115;
  --bg-soft: #161922;
  --card: #1b1f2a;
  --card-hover: #20253244;
  --border: #262b38;
  --fg: #e7e9ee;
  --fg-dim: #9aa3b2;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.12);
  --danger: #ff6b6b;
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--fg-dim); }
.small { font-size: 12px; }
.inline { display: inline; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; gap: 16px;
}
.brand { color: var(--fg); font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.search { flex: 1; }
.search input {
  width: 100%; padding: 9px 14px; border-radius: 999px;
  background: var(--bg-soft); border: 1px solid var(--border); color: var(--fg);
  font-size: 14px; outline: none;
}
.search input:focus { border-color: var(--accent); }
.actions { display: flex; align-items: center; gap: 8px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-block; padding: 8px 14px; border-radius: 9px; cursor: pointer;
  background: var(--bg-soft); border: 1px solid var(--border); color: var(--fg);
  font-size: 14px; font-family: inherit; white-space: nowrap; transition: all .15s;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.block { width: 100%; }

/* ---------- layout ---------- */
.container { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 28px 24px; }
.layout { display: grid; grid-template-columns: 220px 1fr; gap: 28px; align-items: start; }

/* ---------- sidebar ---------- */
.sidebar { position: sticky; top: 80px; }
.facet { margin-bottom: 26px; }
.facet h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--fg-dim); margin-bottom: 12px;
}
.facet-list { list-style: none; }
.facet-list li a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px; border-radius: 8px; color: var(--fg-dim); font-size: 14px;
}
.facet-list li a:hover { background: var(--bg-soft); color: var(--fg); text-decoration: none; }
.facet-list li a.active { background: var(--accent-soft); color: var(--accent); }
.facet-list em { font-style: normal; font-size: 12px; opacity: .7; }
.tagcloud { display: flex; flex-wrap: wrap; gap: 7px; }
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg-soft); border: 1px solid var(--border);
  color: var(--fg-dim); padding: 4px 10px; border-radius: 999px; font-size: 13px;
}
.tag:hover { border-color: var(--accent); color: var(--fg); text-decoration: none; }
.tag.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tag em { font-style: normal; opacity: .6; font-size: 11px; }

/* ---------- result bar ---------- */
.result-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid var(--border);
  font-size: 14px;
}

/* ---------- cards ---------- */
.cards { list-style: none; display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card-title { font-size: 17px; font-weight: 600; color: var(--fg); }
.card-title:hover { color: var(--accent); text-decoration: none; }
.snippet { color: var(--fg-dim); font-size: 14px; margin: 8px 0 12px; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.chip {
  display: inline-block; font-size: 12px; color: var(--fg-dim);
  background: var(--bg-soft); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 999px;
}
a.chip:hover { border-color: var(--accent); color: var(--fg); text-decoration: none; }
.chip.cat { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.date { color: var(--fg-dim); font-size: 12px; margin-left: auto; }

.empty { text-align: center; padding: 80px 20px; color: var(--fg-dim); }
.empty p { margin-bottom: 16px; }

/* ---------- login ---------- */
.login-wrap { display: grid; place-items: center; min-height: 60vh; }
.login-card {
  width: 100%; max-width: 340px; background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 36px 30px; text-align: center;
  display: flex; flex-direction: column; gap: 14px;
}
.login-logo { font-size: 38px; }
.login-card h1 { font-size: 22px; }
.login-card input {
  width: 100%; padding: 11px 14px; border-radius: 9px;
  background: var(--bg-soft); border: 1px solid var(--border); color: var(--fg);
  font-size: 15px; outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.error {
  background: rgba(255, 107, 107, .12); color: var(--danger);
  border: 1px solid rgba(255, 107, 107, .3); border-radius: 8px; padding: 8px; font-size: 14px;
}

/* ---------- entry detail ---------- */
.entry-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.entry-head h1 { font-size: 30px; letter-spacing: -0.4px; }
.entry-actions { display: flex; gap: 8px; flex-shrink: 0; }
.entry-meta { margin: 16px 0 24px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }

/* ---------- markdown ---------- */
.markdown { font-size: 16px; }
.markdown h1, .markdown h2, .markdown h3 { margin: 1.4em 0 .6em; line-height: 1.3; }
.markdown h1 { font-size: 26px; } .markdown h2 { font-size: 22px; } .markdown h3 { font-size: 18px; }
.markdown p { margin: 0 0 1em; }
.markdown ul, .markdown ol { margin: 0 0 1em 1.4em; }
.markdown li { margin: .3em 0; }
.markdown a { color: var(--accent); }
.markdown blockquote {
  border-left: 3px solid var(--accent); padding: 4px 16px; margin: 1em 0;
  color: var(--fg-dim); background: var(--bg-soft); border-radius: 0 8px 8px 0;
}
.markdown :not(pre) > code {
  background: var(--bg-soft); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 5px; font-size: 0.88em;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
.markdown pre {
  background: #1e1f1c; border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; overflow-x: auto; margin: 1em 0; font-size: 14px; line-height: 1.55;
}
.markdown pre code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.markdown table { border-collapse: collapse; margin: 1em 0; width: 100%; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.markdown th { background: var(--bg-soft); }
.markdown img { max-width: 100%; border-radius: 8px; }
.codehilite { background: transparent !important; }

/* ---------- editor ---------- */
.editor { display: flex; flex-direction: column; gap: 14px; max-width: 820px; }
.editor .title-input {
  font-size: 22px; font-weight: 600; padding: 12px 16px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--border); color: var(--fg); outline: none;
}
.editor .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.editor .row input, .editor textarea {
  padding: 11px 14px; border-radius: 9px;
  background: var(--card); border: 1px solid var(--border); color: var(--fg);
  font-size: 15px; outline: none; width: 100%; font-family: inherit;
}
.editor textarea {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  line-height: 1.6; resize: vertical;
}
.editor .title-input:focus, .editor .row input:focus, .editor textarea:focus { border-color: var(--accent); }
.editor-actions { display: flex; align-items: center; gap: 12px; }

/* ---------- footer ---------- */
.site-footer {
  padding: 24px; border-top: 1px solid var(--border);
  color: var(--fg-dim); font-size: 13px; text-align: center;
}
.site-footer a { color: var(--fg-dim); }
.site-footer a:hover { color: var(--accent); }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .editor .row { grid-template-columns: 1fr; }
  .topbar-inner { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; }
}
