/* UniCourses Markdown viewer — styles */

:root {
  --bg: #ffffff;
  --bg-elev: #f6f8fa;
  --bg-sidebar: #f7f8fa;
  --text: #1f2328;
  --text-muted: #656d76;
  --text-faint: #8b949e;
  --border: #d0d7de;
  --border-muted: #e6e8eb;
  --link: #0969da;
  --link-hover: #0a5cc7;
  --accent: #0969da;
  --accent-soft: #ddf4ff;
  --code-bg: rgba(129, 139, 152, 0.12);
  --quote-border: #d0d7de;
  --table-stripe: #f6f8fa;
  --shadow: 0 1px 3px rgba(27, 31, 36, 0.08), 0 1px 2px rgba(27, 31, 36, 0.06);
  --mark: #fff8c5;
  --sidebar-w: 310px;
  --toc-w: 240px;
  --content-max: 860px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-sidebar: #0f141a;
  --text: #e6edf3;
  --text-muted: #9198a1;
  --text-faint: #6e7681;
  --border: #30363d;
  --border-muted: #21262d;
  --link: #4493f8;
  --link-hover: #6cb0ff;
  --accent: #4493f8;
  --accent-soft: #143056;
  --code-bg: rgba(110, 118, 129, 0.25);
  --quote-border: #30363d;
  --table-stripe: #161b22;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --mark: #4a3f00;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-head {
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--border-muted);
  position: sticky;
  top: 0;
  background: var(--bg-sidebar);
  z-index: 2;
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-weight: 700;
  font-size: 14.5px;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin-bottom: 10px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand:hover .brand-name { color: var(--accent); }
.brand .logo {
  flex: 0 0 auto;
  width: 22px; height: 22px; border-radius: 6px;
  margin-top: 1px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; font-weight: 800;
}
.brand-name { min-width: 0; overflow-wrap: anywhere; }

.filter {
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  outline: none;
}
.filter:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.nav { padding: 8px 8px 24px; flex: 1; }

.nav details { margin: 1px 0; }
.nav summary {
  list-style: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
  white-space: nowrap;
}
.nav summary::-webkit-details-marker { display: none; }
.nav summary:hover { background: var(--code-bg); color: var(--text); }
.nav summary .caret {
  transition: transform 0.15s ease;
  font-size: 10px;
  color: var(--text-faint);
  width: 10px;
  flex-shrink: 0;
}
.nav details[open] > summary .caret { transform: rotate(90deg); }
.nav .group-top > summary { color: var(--text); font-weight: 700; font-size: 13px; }

.nav .children { margin-left: 12px; border-left: 1px solid var(--border-muted); padding-left: 4px; }

.nav a.file {
  display: block;
  padding: 4px 8px 4px 22px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav a.file:hover { background: var(--code-bg); color: var(--text); text-decoration: none; }
.nav a.file.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav .empty { padding: 12px 8px; color: var(--text-faint); font-size: 13px; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb .sep { margin: 0 6px; color: var(--text-faint); }
.breadcrumb .current { color: var(--text); font-weight: 600; }

.topbar .actions { display: flex; align-items: center; gap: 6px; }
.btn {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-muted);
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  line-height: 1;
  text-decoration: none;
}
.btn:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }
.hamburger { display: none; }

.content-wrap { display: flex; gap: 32px; padding: 32px 28px 80px; align-items: flex-start; }
.content {
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  min-width: 0;
}

/* ---------- Table of contents ---------- */
.toc {
  width: var(--toc-w);
  flex: 0 0 var(--toc-w);
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  font-size: 13px;
}
.toc-title {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  margin: 0 0 8px 12px;
}
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border-muted); }
.toc li a {
  display: block;
  padding: 3px 12px;
  color: var(--text-muted);
  border-left: 2px solid transparent;
  margin-left: -1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toc li a:hover { color: var(--text); text-decoration: none; }
.toc li a.h3 { padding-left: 24px; font-size: 12px; }
.toc li a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.toc:empty { display: none; }

/* ---------- Markdown content ---------- */
.md { word-wrap: break-word; }
.md > *:first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  margin: 1.6em 0 0.6em;
  line-height: 1.3;
  font-weight: 700;
  scroll-margin-top: 72px;
}
.md h1 { font-size: 2em; padding-bottom: 0.3em; border-bottom: 1px solid var(--border); }
.md h2 { font-size: 1.5em; padding-bottom: 0.3em; border-bottom: 1px solid var(--border-muted); }
.md h3 { font-size: 1.25em; }
.md h4 { font-size: 1.05em; }
.md h5 { font-size: 0.95em; color: var(--text-muted); }
.md h6 { font-size: 0.9em; color: var(--text-muted); }

.md p { margin: 0 0 1em; }
.md a { text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 0.06em; }

.md ul, .md ol { margin: 0 0 1em; padding-left: 1.8em; }
.md li { margin: 0.25em 0; }
.md li > ul, .md li > ol { margin: 0.25em 0; }

.md blockquote {
  margin: 0 0 1em;
  padding: 0.2em 1em;
  color: var(--text-muted);
  border-left: 4px solid var(--quote-border);
  background: var(--bg-elev);
  border-radius: 0 6px 6px 0;
}
.md blockquote > *:last-child { margin-bottom: 0; }

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

/* inline code */
.md code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.2em 0.4em;
  border-radius: 5px;
}
/* code blocks */
.md pre {
  margin: 0 0 1em;
  padding: 14px 16px;
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border-muted);
  font-size: 13.5px;
  line-height: 1.5;
}
.md pre code { background: none; padding: 0; font-size: inherit; border-radius: 0; }
.md pre.hljs { background: var(--bg-elev); color: var(--text); }

/* tables */
.md .table-wrap { overflow-x: auto; margin: 0 0 1em; }
.md table { border-collapse: collapse; width: max-content; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 13px; text-align: left; }
.md th { background: var(--bg-elev); font-weight: 700; }
.md tr:nth-child(2n) td { background: var(--table-stripe); }

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

.md mark { background: var(--mark); color: inherit; padding: 0.1em 0.2em; border-radius: 3px; }

.md kbd {
  font-family: var(--mono);
  font-size: 0.85em;
  padding: 0.15em 0.45em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg-elev);
}

/* heading anchor links (markdown-it-anchor) */
.md .header-anchor {
  margin-left: 0.35em;
  color: var(--text-faint);
  opacity: 0;
  text-decoration: none;
  font-weight: 400;
  transition: opacity 0.12s ease;
}
.md .header-anchor:hover { color: var(--link); text-decoration: none; }
.md h1:hover .header-anchor,
.md h2:hover .header-anchor,
.md h3:hover .header-anchor,
.md h4:hover .header-anchor { opacity: 1; }

/* KaTeX: allow wide display math to scroll instead of overflowing */
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.md .katex { font-size: 1.05em; }

/* ---------- Directory listing ---------- */
.dirlist { list-style: none; padding: 0; margin: 1em 0; }
.dirlist li { border-bottom: 1px solid var(--border-muted); }
.dirlist a { display: flex; align-items: center; gap: 10px; padding: 10px 6px; color: var(--text); }
.dirlist a:hover { background: var(--bg-elev); text-decoration: none; }
.dirlist .ic { font-size: 16px; width: 20px; text-align: center; }

/* ---------- misc ---------- */
.doc-meta { color: var(--text-faint); font-size: 12.5px; margin: 24px 0 0; padding-top: 16px; border-top: 1px solid var(--border-muted); }
.scrim { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .toc { display: none; }
}
@media (max-width: 800px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim {
    display: block; position: fixed; inset: 0;
    background: rgba(0,0,0,0.4); z-index: 15;
  }
  .hamburger { display: inline-flex; }
  .content-wrap { padding: 20px 16px 60px; }
}
