:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --bg-sink: #eceff3;
  --fg: #1f2328;
  --fg-muted: #5b6570;
  --border: #d7dde3;
  --link: #0969da;
  --accent: #8a63d2;
  --radius: 10px;
  --maxw: 820px;
  --sidebar-w: 300px;
  --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: 12px; }
#course-switcher {
  font: inherit; font-size: 14px; color: var(--fg);
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; max-width: 46vw;
}
.gh-link { font-size: 13px; color: var(--fg-muted); white-space: nowrap; }

/* ---------- layout ---------- */
#layout { display: flex; align-items: flex-start; }
.sidebar {
  position: sticky; top: var(--header-h);
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg-soft);
  padding: 18px 10px 40px;
}
.sidebar-head { padding: 6px 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.sidebar-course { display: block; font-weight: 650; font-size: 15px; color: var(--fg); line-height: 1.35; }
.toc { display: flex; flex-direction: column; gap: 1px; }
.toc a {
  display: block; padding: 7px 10px; border-radius: 7px;
  color: var(--fg-muted); font-size: 14px; line-height: 1.35;
}
.toc a:hover { background: var(--bg-sink); color: var(--fg); text-decoration: none; }
.toc a.active { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--fg); font-weight: 600; }
.toc a.active::before { content: ""; }
.toc .toc-num { color: var(--fg-muted); font-variant-numeric: tabular-nums; margin-right: 8px; font-size: 12px; }
.toc .toc-sec-label {
  padding: 14px 10px 4px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--fg-muted); font-weight: 650;
}

.view { flex: 1 1 auto; min-width: 0; 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(26px, 4vw, 38px); 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); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin-top: 26px; }
.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; }
.topic .grid { 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 16px; 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 h2 { font-size: 18px; margin: 0; line-height: 1.3; }
.card h2 a { color: var(--fg); }
.card h2 a::after { content: ""; position: absolute; inset: 0; }
.card p { color: var(--fg-muted); font-size: 14px; margin: 0 0 14px; flex: 1 1 auto; }
.card-foot { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--fg-muted); }
.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)); }
.card-foot .sep { opacity: .5; }

/* ---------- rendered markdown ---------- */
.doc { max-width: var(--maxw); margin: 0 auto; }
.doc .doc-crumbs { font-size: 13px; color: var(--fg-muted); margin-bottom: 18px; }
.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: 30px; letter-spacing: -0.02em; margin-top: .2em; }
.markdown h2 { font-size: 23px; padding-bottom: .3em; border-bottom: 1px solid var(--border); }
.markdown h3 { font-size: 19px; }
.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 a.anchor::after { content: none; }
.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); }

.pager { display: flex; justify-content: space-between; gap: 12px; margin: 48px auto 0; max-width: var(--maxw); border-top: 1px solid var(--border); padding-top: 20px; }
.pager a { flex: 1 1 0; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; color: var(--fg); background: var(--bg-soft); }
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager a.next { text-align: right; }
.pager .dir { display: block; font-size: 12px; color: var(--fg-muted); }
.pager .ttl { font-weight: 600; font-size: 14px; }
.pager .spacer { flex: 1 1 0; }

/* ---------- mobile ---------- */
.menu-toggle { display: none; }
@media (max-width: 860px) {
  :root { --sidebar-w: 260px; }
  .menu-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg-soft); color: var(--fg); cursor: pointer; font-size: 16px;
  }
  .sidebar {
    position: fixed; left: 0; top: var(--header-h); z-index: 15;
    height: calc(100vh - var(--header-h));
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 0 0 40px -10px rgba(0,0,0,.5);
  }
  .sidebar.open { transform: translateX(0); }
  #course-switcher { max-width: 40vw; }
}
