/* Markdown wiki — viewer styles */

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-soft: #f0f2f5;
  --text: #1f2328;
  --text-soft: #3d444d;
  --muted: #6b7280;
  --border: #e2e5ea;
  --border-strong: #cfd5dd;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e8efff;
  --code-bg: #f1f3f6;
  --code-border: #e3e7ed;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 10px 30px rgba(16, 24, 40, .06);
  --sidebar-w: 288px;
  --content-max: 860px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --panel: #151b23;
  --panel-soft: #1c232d;
  --text: #e6edf3;
  --text-soft: #c3ccd6;
  --muted: #8b949e;
  --border: #2a323d;
  --border-strong: #3a4451;
  --accent: #62a0ff;
  --accent-hover: #8ab8ff;
  --accent-soft: #1b2b45;
  --code-bg: #1a222c;
  --code-border: #2c3642;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  scroll-padding-top: 80px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ------------------------------------------------------------------ */
/* Sidebar                                                            */
/* ------------------------------------------------------------------ */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 14px;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  min-width: 0;
}
.brand-link:hover { color: var(--text); text-decoration: none; }

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  color: #fff;
  background: linear-gradient(135deg, #3b82f6, #7c3aed);
  box-shadow: 0 6px 16px rgba(59, 130, 246, .35);
  flex: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  font-weight: 650;
  font-size: 18px;
}
.brand-text small {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: .04em;
  margin-top: 4px;
}

.icon-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  width: 36px;
  height: 36px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.icon-btn:hover { background: var(--panel-soft); color: var(--text); }
#themeBtn { margin-left: auto; }

.search-box {
  position: relative;
  margin: 0 16px 12px;
}
.search-box svg {
  position: absolute;
  left: 11px;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  fill: var(--muted);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 34px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
}
.search-box input::placeholder { color: var(--muted); }
.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--panel);
}

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 2px 12px 24px;
  scrollbar-width: thin;
}

.nav-home,
.nav-page {
  display: block;
  padding: 7px 11px;
  border-radius: 8px;
  color: var(--text-soft);
  font-size: 14.5px;
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-home { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; }
.nav-home-icon { color: var(--muted); font-size: 16px; }
.nav-page:hover, .nav-home:hover {
  background: var(--panel-soft);
  color: var(--text);
  text-decoration: none;
}
.nav-page.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.nav-group { margin: 4px 0; }
.nav-group > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  user-select: none;
}
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary:hover { background: var(--panel-soft); color: var(--text-soft); }
.nav-group > summary::before {
  content: "›";
  font-size: 16px;
  line-height: 1;
  transform: rotate(90deg);
  transition: transform .15s ease;
  display: inline-block;
  width: 10px;
  text-align: center;
}
.nav-group:not([open]) > summary::before { transform: rotate(0deg); }
.nav-book { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--panel-soft);
  border-radius: 20px;
  padding: 1px 7px;
}
.nav-group ul { list-style: none; margin: 2px 0 6px; padding: 0 0 0 6px; }
.nav-group li { margin: 1px 0; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 12px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
}

/* ------------------------------------------------------------------ */
/* Main                                                               */
/* ------------------------------------------------------------------ */

.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.menu-btn { display: none; }

.crumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
}
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { color: var(--border-strong); }
.crumbs .here {
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
}

.raw-link {
  margin-left: auto;
  flex: none;
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 11px;
  background: var(--panel);
}
.raw-link:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }

.layout {
  display: flex;
  align-items: flex-start;
  gap: 48px;
  max-width: calc(var(--content-max) + 300px);
  margin: 0 auto;
  padding: 34px 32px 64px;
}

.content-wrap {
  flex: 1;
  min-width: 0;
  max-width: var(--content-max);
}

/* Page header ------------------------------------------------------- */

.page-kicker { margin-bottom: 8px; }
.kicker-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 20px;
  padding: 2px 10px;
}
.kicker-tag.muted { color: var(--muted); background: var(--panel-soft); }

.page-title {
  margin: 0 0 8px;
  font-size: clamp(1.75rem, 2.4vw, 2.25rem);
  line-height: 1.25;
  letter-spacing: -.02em;
  font-weight: 720;
}
.page-meta {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 26px;
}
.page-meta .dot { margin: 0 7px; }

/* Markdown ---------------------------------------------------------- */

.markdown { min-height: 40vh; }
.markdown > :first-child { margin-top: 0; }

.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4,
.markdown h5,
.markdown h6 {
  position: relative;
  margin: 1.9em 0 .65em;
  line-height: 1.35;
  font-weight: 680;
  scroll-margin-top: 80px;
}
.markdown h1 { font-size: 1.85em; }
.markdown h2 {
  font-size: 1.45em;
  padding-bottom: .3em;
  border-bottom: 1px solid var(--border);
}
.markdown h3 { font-size: 1.2em; }
.markdown h4 { font-size: 1.05em; }
.markdown h5, .markdown h6 { font-size: .95em; color: var(--text-soft); }

.heading-anchor {
  margin-left: .4em;
  color: var(--border-strong);
  font-weight: 400;
  opacity: 0;
  transition: opacity .15s ease;
  text-decoration: none;
}
.markdown h1:hover .heading-anchor,
.markdown h2:hover .heading-anchor,
.markdown h3:hover .heading-anchor,
.markdown h4:hover .heading-anchor,
.markdown h5:hover .heading-anchor,
.markdown h6:hover .heading-anchor { opacity: 1; }

.markdown p { margin: 0 0 1.05em; }

.markdown ul, .markdown ol { margin: 0 0 1.05em; padding-left: 1.6em; }
.markdown li { margin: .3em 0; }
.markdown li > ul, .markdown li > ol { margin: .3em 0; }

.markdown blockquote {
  margin: 1.2em 0;
  padding: .2em 1em;
  color: var(--text-soft);
  border-left: 3px solid var(--border-strong);
  background: var(--panel-soft);
  border-radius: 0 8px 8px 0;
}

.markdown hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

.markdown code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: .875em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 5px;
  padding: .12em .38em;
}
.markdown pre {
  margin: 1.1em 0;
  padding: 15px 17px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 10px;
  overflow-x: auto;
  line-height: 1.6;
}
.markdown pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: .86em;
  white-space: pre;
}

.markdown table {
  border-collapse: collapse;
  display: block;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  margin: 1.2em 0;
  font-size: .94em;
}
.markdown th, .markdown td {
  border: 1px solid var(--border);
  padding: 8px 13px;
  text-align: left;
}
.markdown th { background: var(--panel-soft); font-weight: 650; }
.markdown tr:nth-child(even) td { background: color-mix(in srgb, var(--panel-soft) 45%, transparent); }

.markdown img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.markdown details {
  margin: 1.2em 0;
  padding: .55em 1em;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}
.markdown details > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-soft);
}
.markdown details[open] > summary { margin-bottom: .6em; }

/* Math -------------------------------------------------------------- */

.katex { font-size: 1.05em; }
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: .35em 0;
}
.math-fallback {
  color: #b42318;
  white-space: pre-wrap;
}

/* JSXGraph ---------------------------------------------------------- */

.jxgbox {
  max-width: 100%;
  background: #fff;
  border: 1px solid var(--border) !important;
  border-radius: 10px;
  box-shadow: var(--shadow);
  margin: 1.2em auto !important;
}
.jxgbox text { fill: #111; }

/* Loading / error --------------------------------------------------- */

.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  padding: 30px 0;
}
.loading span {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-page { padding: 34px 0; }
.error-code {
  font-size: 64px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.04em;
  color: var(--border-strong);
  margin-bottom: 12px;
}
.error-page h2 { margin: 0 0 10px; }
.error-detail { color: var(--muted); font-size: 13px; }

/* Book index -------------------------------------------------------- */

.book-index { padding-top: 4px; }
.book-intro { color: var(--muted); margin-bottom: 20px; }
.book-pages {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.book-pages li { margin: 0; }
.book-pages a {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--panel);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.book-pages a:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
  text-decoration: none;
}
.book-page-title { font-weight: 600; color: var(--text); }
.book-page-path { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Pager ------------------------------------------------------------- */

.pager {
  display: flex;
  gap: 14px;
  margin: 46px 0 0;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}
.pager:empty { display: none; }
.pager-link {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.pager-link:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  text-decoration: none;
}
.pager-link.next { text-align: right; margin-left: auto; }
.pager-label { font-size: 11.5px; color: var(--muted); letter-spacing: .02em; }
.pager-title {
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pager-spacer { flex: 1; }

.page-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 34px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

/* ------------------------------------------------------------------ */
/* Right-hand table of contents                                       */
/* ------------------------------------------------------------------ */

.toc {
  position: sticky;
  top: 82px;
  width: 220px;
  flex: none;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  padding: 4px 0 20px 18px;
  border-left: 1px solid var(--border);
  font-size: 13px;
}
.toc.hidden { display: none; }
.toc-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 2px 0; }
.toc a {
  display: block;
  padding: 3px 0;
  color: var(--muted);
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toc a:hover { color: var(--accent); text-decoration: none; }
.toc-d1 { padding-left: 11px; }
.toc-d2 { padding-left: 22px; }
.toc-d3 { padding-left: 33px; }

/* ------------------------------------------------------------------ */
/* Responsive                                                         */
/* ------------------------------------------------------------------ */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 25, .45);
  z-index: 35;
  backdrop-filter: blur(2px);
}

@media (max-width: 1250px) {
  .toc { display: none; }
  .layout { max-width: calc(var(--content-max) + 64px); }
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 0 0 50px rgba(0, 0, 0, .25);
    width: min(84vw, 320px);
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 14px; }
  .layout { padding: 24px 20px 48px; }
  .raw-link { padding: 5px 9px; }
}

@media (max-width: 520px) {
  body { font-size: 15.5px; }
  .layout { padding: 20px 15px 40px; }
  .page-title { font-size: 1.6rem; }
  .pager { flex-direction: column; }
  .pager-link.next { text-align: left; }
  .page-footer { flex-direction: column; align-items: flex-start; gap: 6px; }
}

@media print {
  .sidebar, .topbar, .toc, .pager, .page-footer, .backdrop { display: none !important; }
  .main { margin: 0; }
  .layout { max-width: none; padding: 0; }
  .markdown a { color: inherit; text-decoration: underline; }
}
