:root {
  --bg: #ffffff;
  --fg: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --border: #e5e7eb;
  --nav-bg: #f8fafc;
  --code-bg: #f3f4f6;
  --nav-w: 320px;
  --toc-w: 260px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.65;
}

/* sidebar */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--nav-w);
  height: 100vh;
  overflow-y: auto;
  background: var(--nav-bg);
  border-right: 1px solid var(--border);
  padding: 1rem 0.75rem 3rem;
}
.brand {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--fg);
  padding: 0.25rem 0.5rem 0.75rem;
}
.tree { font-size: 0.9rem; }
.tree details { margin: 0; }
.tree summary {
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
  font-weight: 600;
  color: var(--fg);
  list-style: revert;
}
.tree summary:hover { background: #eef2ff; }
.tree-children { padding-left: 0.85rem; border-left: 1px solid var(--border); margin-left: 0.4rem; }
.tree-link {
  display: block;
  padding: 0.18rem 0.45rem;
  margin: 1px 0;
  border-radius: 6px;
  text-decoration: none;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree-link:hover { background: #eef2ff; color: var(--accent); }
.tree-link.active { background: var(--accent); color: #fff; }
.tree-link.type-pdf { color: #b91c1c; }
.tree-link.type-drawio { color: #7c3aed; }
.tree-link.type-pdf.active, .tree-link.type-drawio.active { color: #fff; }
/* directory hub link (clickable folder summary with a .hub.index.md landing page) */
.tree summary .tree-hub { display: inline; padding: 0; margin: 0; color: inherit; font-weight: inherit; white-space: normal; }
.tree summary .tree-hub:hover { background: transparent; text-decoration: underline; }
.tree summary .tree-hub.active { background: transparent; color: var(--accent); text-decoration: underline; }

/* content */
.content {
  margin-left: var(--nav-w);
  padding: 2rem 3rem 6rem;
  max-width: 900px;
}
.md { font-size: 1rem; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { line-height: 1.3; margin: 1.6em 0 0.6em; font-weight: 700; }
.md h1 { font-size: 2rem; }
.md h2 { font-size: 1.75rem; }
.md h3 { font-size: 1.55rem; border-bottom: 1px solid var(--border); padding-bottom: 0.2em; }
.md h4 { font-size: 1.35rem; }
.md h5 { font-size: 1.18rem; }
.md h6 { font-size: 1.05rem; }
.md a { color: var(--accent); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md code {
  background: var(--code-bg);
  padding: 0.12em 0.4em;
  border-radius: 5px;
  font-size: 0.9em;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace;
}
.md pre {
  background: var(--code-bg);
  padding: 1rem;
  border-radius: 10px;
  overflow-x: auto;
}
.md pre code { background: none; padding: 0; }
.md pre.mermaid { background: #fff; border: 1px solid var(--border); text-align: center; }
.md blockquote {
  margin: 0.8em 0;
  padding: 0.5em 1.1em;
  border-left: 4px solid var(--accent);
  background: #e9eef4;
  color: #243140;
  border-radius: 6px;
  /* handwriting-but-professional: Kai (楷体) for CJK on macOS/Windows, elegant serif fallback elsewhere */
  font-family: "Kaiti SC", "STKaiti", KaiTi, "楷体", "TW-Kai", Georgia, "Times New Roman", serif;
  font-weight: 300;
  font-size: 1.02em;
  line-height: 1.7;
}
.md blockquote p { margin: 0; } /* drop the inner paragraph margins -> no blank line above/below the text */
.md table { border-collapse: collapse; width: 100%; margin: 1em 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 0.45em 0.7em; text-align: left; }
.md th { background: var(--nav-bg); }
.md img { max-width: 100%; height: auto; border-radius: 8px; }
.doc-frame { width: 100%; height: 80vh; border: 1px solid var(--border); border-radius: 8px; margin-top: 0.5rem; }
.doc-diagram { border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem; background: #fff; overflow: auto; margin-top: 0.5rem; }
.content.has-toc { margin-right: var(--toc-w); }
html { scroll-behavior: smooth; }
.md :is(h1, h2, h3, h4, h5, h6) { scroll-margin-top: 1rem; }

/* right "On this page" header outline (built from the article's heading ids; no extra files) */
.toc {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--toc-w);
  height: 100vh;
  overflow-y: auto;
  padding: 1.4rem 0.9rem 3rem;
  border-left: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.85rem;
}
.toc-title {
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.72rem;
  margin: 0 0 0.5rem 0.6rem;
}
.toc-nav { display: flex; flex-direction: column; border-left: 1px solid var(--border); }
.toc-link {
  display: block;
  margin-left: -1px;
  padding: 0.16rem 0.5rem;
  border-left: 2px solid transparent;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toc-link:hover { color: var(--accent); }
.toc-link.active { color: var(--accent); border-left-color: var(--accent); background: #eef2ff; }
@media (max-width: 1100px) {
  .toc { display: none; }
  .content.has-toc { margin-right: 0; }
}

/* search */
#search { margin: 0 0.4rem 0.75rem; }

/* user bar — account dropdown under the brand title, left-aligned */
.userbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem 0.7rem;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.user-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  max-width: 100%;
  cursor: pointer;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.55rem;
  font-size: 0.85rem;
}
.user-menu-btn:hover { background: var(--code-bg); }
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 9rem; }
[hidden] { display: none !important; } /* ensure the hidden attr wins over class display rules (menu-btn/sign-in/modals) */
.user-acct { position: relative; flex: 0 0 auto; }
.user-signin { display: inline-block; text-decoration: none; color: var(--fg); border: 1px solid var(--border); border-radius: 6px; padding: 0.2rem 0.6rem; font-size: 0.85rem; }
.user-signin:hover { background: var(--code-bg); }
.user-menu-btn .caret { color: var(--muted); font-size: 0.7rem; }
.user-menu {
  position: absolute;
  left: auto;
  right: 0;
  top: 100%;
  z-index: 30;
  min-width: 11rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}
.user-menu[hidden] { display: none; }
.user-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 0.5rem 0.8rem;
  font-size: 0.88rem;
  color: var(--fg);
  cursor: pointer;
}
.user-menu button:hover { background: var(--code-bg); }
.user-menu button.danger { color: #dc2626; }
.user-menu button.danger:hover { background: #fee2e2; }

/* account self-service modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(92vw, 360px);
  background: var(--bg);
  color: var(--fg);
  border-radius: 12px;
  padding: 1.2rem 1.3rem 1rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.modal-card h3 { margin: 0 0 0.8rem; font-size: 1.1rem; }
.modal-card label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.6rem; }
.modal-card input[type="text"], .modal-card input[type="password"] {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--fg);
}
.modal-card label.modal-show { flex-direction: row; align-items: center; gap: 0.4rem; }
.modal-card label.modal-show input { width: auto; }
.modal-msg { min-height: 1.1em; margin: 0.2rem 0 0.6rem; font-size: 0.85rem; color: #dc2626; }
.modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; }
.modal-actions button {
  cursor: pointer;
  border-radius: 8px;
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  background: var(--accent);
  color: #fff;
}
.modal-actions button.ghost { background: transparent; color: var(--fg); border: 1px solid var(--border); font-weight: 500; }
.modal-actions button.danger { background: #dc2626; color: #fff; }

/* mobile */
#navToggle {
  display: none;
  position: fixed;
  top: 0.6rem;
  left: 0.6rem;
  z-index: 20;
  font-size: 1.2rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
}
@media (max-width: 768px) {
  #navToggle { display: block; }
  .nav { transform: translateX(-100%); transition: transform 0.2s; z-index: 15; }
  .nav.open { transform: translateX(0); }
  .content { margin-left: 0; padding: 3.2rem 1.2rem 4rem; }
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --fg: #e2e8f0; --muted: #94a3b8; --accent: #60a5fa;
    --border: #1e293b; --nav-bg: #0b1220; --code-bg: #1e293b;
  }
  .tree summary:hover, .tree-link:hover { background: #1e293b; }
  .toc-link.active { background: #1e293b; }
  .md blockquote { background: #111827; color: #cbd5e1; }
  .md pre.mermaid { background: #0b1220; }
}

/* ---- client-side search (single-index; replaces pagefind UI) ---- */
.search { position: relative; margin: 0.6rem 0 0.4rem; }
.search input {
  width: 100%; padding: 0.45rem 0.6rem; font-size: 0.95rem;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--fg);
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37,99,235,0.15); }
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30;
  max-height: 60vh; overflow-y: auto; background: #fff;
  border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}
.search-hit { display: block; padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--fg); }
.search-hit:last-child { border-bottom: 0; }
.search-hit:hover { background: var(--nav-bg); }
.search-hit-title { display: block; font-weight: 600; font-size: 0.9rem; color: var(--accent); }
.search-hit-snip { display: block; font-size: 0.8rem; color: var(--muted); margin-top: 0.15rem; line-height: 1.4; }
.search-empty { padding: 0.6rem 0.7rem; color: var(--muted); font-size: 0.85rem; }

/* ---------- gallery view (Gallery-pattern album pages, wiki-gallery-fusion) ---------- */
.doc-media { max-width: 100%; max-height: 80vh; border-radius: 10px; display: block; margin: 1rem 0; background: #000; cursor: zoom-in; }
.gx-header { margin-bottom: 1rem; }
.gx-modes { display: inline-flex; margin: 0.4rem 0 1rem; }
.gx-modes button { background: #fff; border: 1px solid #e5e7eb; padding: 0.35rem 0.7rem; cursor: pointer; font-size: 0.85rem; }
.gx-modes button:first-child { border-radius: 6px 0 0 6px; }
.gx-modes button:last-child { border-radius: 0 6px 6px 0; }
.gx-modes button.active { background: #2563eb; color: #fff; border-color: #2563eb; }
.gx-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.8rem; }
.gx-tile { position: relative; cursor: pointer; border: 1px solid #e5e7eb; border-radius: 8px; overflow: hidden; background: #000; aspect-ratio: 4/3; }
.gx-tile img, .gx-tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.gx-tile .gx-badge { position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 0.7rem; padding: 1px 6px; border-radius: 4px; }
.gx-tile .gx-play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 2.4rem; text-shadow: 0 2px 8px rgba(0,0,0,.6); pointer-events: none; }
.gx-tile-cap { padding: 0.35rem 0.5rem; font-size: 0.8rem; background: #fff; }
.gx-list { display: flex; flex-direction: column; gap: 0.2rem; }
.gx-list-item { display: flex; gap: 0.6rem; align-items: center; padding: 0.5rem 0.6rem; border-bottom: 1px solid #e5e7eb; cursor: pointer; }
.gx-list-item:hover { background: #f3f4f6; }
.gx-list-item .gx-li-icon { color: #6b7280; }
.gx-list-item .gx-li-cap { color: #6b7280; font-size: 0.85rem; margin-left: auto; }
.gx-single { display: flex; flex-direction: column; align-items: center; gap: 0.8rem; }
.gx-stage { position: relative; width: 100%; max-width: 900px; display: flex; align-items: center; justify-content: center; background: #000; border-radius: 10px; min-height: 240px; }
.gx-stage img, .gx-stage video { max-width: 100%; max-height: 70vh; display: block; border-radius: 10px; }
.gx-arrow { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.5); color: #fff; border: none; font-size: 1.6rem; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; }
.gx-arrow:hover { background: rgba(0,0,0,.75); }
.gx-arrow.prev { left: 8px; } .gx-arrow.next { right: 8px; }
.gx-arrow:disabled { opacity: 0.3; cursor: default; }
.gx-caption { max-width: 900px; width: 100%; text-align: center; }
.gx-caption .gx-cap-title { font-weight: 600; }
.gx-counter { color: #6b7280; font-size: 0.85rem; }
.gx-empty { color: #6b7280; padding: 2rem 0; }
@media (max-width: 820px) { .gx-grid { grid-template-columns: repeat(2, 1fr); } }

/* ---------- image lightbox (zoom): click a content/gallery image to enlarge; click image to toggle actual size ---------- */
.gx-stage img { cursor: zoom-in; }
.lightbox { position: fixed; inset: 0; z-index: 200; background: rgba(0, 0, 0, 0.92); display: flex; align-items: center; justify-content: center; overflow: auto; cursor: zoom-out; padding: 1rem; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 95vw; max-height: 95vh; cursor: zoom-in; border-radius: 4px; background: #000; }
.lightbox img.actual { max-width: none; max-height: none; cursor: zoom-out; } /* actual size -> lightbox scrolls to pan */
