:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --bg-sink: #eceff3;
  --fg: #1f2328;
  --fg-muted: #5b6570;
  --border: #d7dde3;
  --link: #0969da;
  --accent: #8a63d2;
  --radius: 10px;
  --maxw: 820px;
  --header-h: 56px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-soft: #161b22;
    --bg-sink: #010409;
    --fg: #e6edf3;
    --fg-muted: #9198a1;
    --border: #30363d;
    --link: #4493f8;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--fg);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--fg); font-weight: 650; }
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); font-size: 20px; transform: translateY(-1px); }
.brand-sep { color: var(--fg-muted); }
.topnav { display: flex; align-items: center; gap: 16px; font-size: 14px; }
.topnav a { color: var(--fg-muted); white-space: nowrap; }
.topnav a:hover { color: var(--fg); }

.view { padding: 36px clamp(18px, 5vw, 56px) 120px; }
.loading, .msg { color: var(--fg-muted); padding: 40px 0; }
.msg code { background: var(--bg-soft); padding: 2px 6px; border-radius: 6px; }

/* ---------- home ---------- */
.home { max-width: 1040px; margin: 0 auto; }
.hero { padding: 26px 0 8px; }
.hero h1 { font-size: clamp(28px, 4.5vw, 42px); margin: 0 0 10px; letter-spacing: -0.02em; }
.hero p { color: var(--fg-muted); font-size: 17px; max-width: 70ch; margin: 0; }
.hero .meta { margin-top: 14px; font-size: 13px; color: var(--fg-muted); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--fg-muted);
  background: var(--bg-soft); border: 1px solid var(--border);
  padding: 4px 12px; border-radius: 999px; cursor: pointer;
}
.chip:hover { color: var(--fg); border-color: var(--fg-muted); }
.chip[aria-pressed="true"] { color: var(--fg); border-color: var(--chip-accent, var(--accent)); background: color-mix(in srgb, var(--chip-accent, var(--accent)) 14%, transparent); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--chip-accent, var(--accent)); }
.chip .n { font-weight: 500; opacity: .7; font-variant-numeric: tabular-nums; }

.topic { margin-top: 38px; }
.topic-head { border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.topic-head h2 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.topic-head p { color: var(--fg-muted); font-size: 14px; margin: 4px 0 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin-top: 16px; }

.card {
  position: relative; display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-soft); padding: 18px 18px 14px; overflow: hidden;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--card-accent, var(--accent)); }
.card:hover { transform: translateY(-2px); border-color: var(--card-accent, var(--accent)); box-shadow: 0 8px 24px -14px rgba(0,0,0,.4); }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.card h3 { font-size: 18px; margin: 0; line-height: 1.3; }
.card h3 a { color: var(--fg); }
.card h3 a::after { content: ""; position: absolute; inset: 0; }
.card .desc { color: var(--fg); font-size: 14px; font-style: italic; margin: 2px 0 8px; opacity: .85; }
.card .summary { color: var(--fg-muted); font-size: 14px; margin: 0 0 12px; flex: 1 1 auto; }
.card-foot {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--fg-muted);
  border-top: 1px solid var(--border); padding-top: 10px; margin-top: 4px;
}
.card-foot .sep { opacity: .5; }
.card-foot .links { margin-left: auto; display: flex; gap: 12px; }
.card-foot .links a { position: relative; z-index: 1; font-weight: 600; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--fg);
  background: var(--bg-sink); border: 1px solid var(--border);
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--card-accent, var(--accent)); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; padding: 0; list-style: none; }
.tags li {
  font-family: var(--mono); font-size: 11.5px; color: var(--fg-muted);
  background: var(--bg); border: 1px solid var(--border);
  padding: 1px 8px; border-radius: 6px;
}

/* ---------- project page ---------- */
.doc { max-width: var(--maxw); margin: 0 auto; }
.doc-crumbs { font-size: 13px; color: var(--fg-muted); margin-bottom: 18px; overflow-wrap: anywhere; }
.proj-head {
  position: relative; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-soft); padding: 20px 22px 18px; margin-bottom: 30px; overflow: hidden;
}
.proj-head::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); }
.proj-head h1 { font-size: clamp(24px, 3.5vw, 32px); margin: 6px 0 4px; letter-spacing: -0.02em; line-height: 1.2; }
.proj-head .desc { font-style: italic; margin: 0 0 10px; color: var(--fg); opacity: .85; }
.proj-head .summary { color: var(--fg-muted); margin: 0 0 14px; }
.proj-head .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 13px; color: var(--fg-muted); }
.proj-head .meta .sep { opacity: .5; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; font-weight: 600; color: var(--fg);
  border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 6px 14px;
}
.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); }

/* ---------- rendered markdown ---------- */
.markdown { font-size: 16px; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { line-height: 1.25; margin: 1.8em 0 .6em; scroll-margin-top: calc(var(--header-h) + 12px); }
.markdown h1 { font-size: 28px; letter-spacing: -0.02em; margin-top: .2em; }
.markdown h2 { font-size: 22px; padding-bottom: .3em; border-bottom: 1px solid var(--border); }
.markdown h3 { font-size: 18px; }
.markdown h4 { font-size: 16px; }
.markdown p, .markdown li { overflow-wrap: break-word; }
.markdown a.ext-file::after { content: " ↗"; font-size: .85em; color: var(--fg-muted); }
.markdown a.anchor { color: var(--fg-muted); margin-left: .35em; opacity: 0; font-size: .8em; }
.markdown h1:hover a.anchor, .markdown h2:hover a.anchor, .markdown h3:hover a.anchor, .markdown h4:hover a.anchor { opacity: 1; }
.markdown img { max-width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--border); background: #fff; }
.markdown code { font-family: var(--mono); font-size: .88em; background: var(--bg-soft); padding: .15em .4em; border-radius: 6px; }
.markdown pre { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; overflow-x: auto; }
.markdown pre code { background: none; padding: 0; font-size: 13.5px; line-height: 1.5; }
.markdown blockquote { margin: 1em 0; padding: .4em 1em; border-left: 3px solid var(--accent); background: var(--bg-soft); border-radius: 0 8px 8px 0; color: var(--fg); }
.markdown blockquote p { margin: .4em 0; }
.markdown table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; font-size: 14.5px; margin: 1em 0; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; }
.markdown th { background: var(--bg-soft); }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.markdown details { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px; padding: .4em 1em; margin: 1em 0; }
.markdown summary { cursor: pointer; font-weight: 600; }
.markdown kbd { font-family: var(--mono); font-size: .85em; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 6px; padding: .1em .4em; background: var(--bg); }

.back { display: inline-block; margin-top: 48px; font-size: 14px; }

@media (max-width: 600px) {
  .topnav { gap: 12px; }
  .grid { grid-template-columns: 1fr; }
}
