:root {
  --link: #0645ad;
  --link-visited: #0b0080;
  --border: #a2a9b1;
  --sidebar-bg: #f6f6f6;
  --page-bg: #ffffff;
  --text: #202122;
  --muted: #54595d;
  --header-bg: #f8f9fa;
  --accent: #eaf3ff;
  --code-bg: #f5f5f5;
  --sans: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --serif: "Linux Libertine", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
}

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

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  max-width: 1400px;
  margin: 0 auto;
}
.sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 18px;
  padding: 4px 8px;
  cursor: pointer;
}
.site-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}
.site-logo:hover { text-decoration: none; }
.site-logo img { display: block; flex: 0 0 auto; }
.site-title-block {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  white-space: nowrap;
}
.site-title {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: 3px;
}
.site-logo:hover .site-title { color: var(--link); }
.site-subtitle {
  font-family: var(--sans);
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

.search-wrap {
  position: relative;
  margin-left: auto;
  width: 320px;
  max-width: 45vw;
}
#search-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 14px;
}
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.12);
  max-height: 420px;
  overflow-y: auto;
}
.search-results a {
  display: block;
  padding: 8px 10px;
  border-bottom: 1px solid #eee;
  color: var(--text);
}
.search-results a:hover { background: var(--accent); text-decoration: none; }
.search-results .sr-title { font-weight: 600; color: var(--link); }
.search-results .sr-path { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.search-results .sr-snippet { display: block; font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.search-results .sr-empty { padding: 10px; color: var(--muted); }
.search-results mark { background: #fff3a3; }

/* Layout */
.layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  align-items: flex-start;
}

.sidebar {
  width: 300px;
  flex: 0 0 300px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  min-height: calc(100vh - 53px);
  padding: 14px 10px 40px;
  position: sticky;
  top: 53px;
  align-self: flex-start;
  max-height: calc(100vh - 53px);
  overflow-y: auto;
  font-size: 13.5px;
}
.quicknav {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e2e2e2;
}
.quicknav a {
  padding: 4px 8px;
  border-radius: 3px;
  color: var(--text);
  font-weight: 600;
}
.quicknav a:hover { background: var(--accent); text-decoration: none; color: var(--link); }

.sidebar-section-title {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 4px 8px 8px;
}

.file-tree ul {
  list-style: none;
  margin: 0;
  padding-left: 14px;
}
.file-tree > ul { padding-left: 4px; }
.file-tree li { margin: 1px 0; }
.tree-folder {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 3px;
  color: var(--text);
  font-weight: 600;
  user-select: none;
}
.tree-folder:hover { background: var(--accent); }
.tree-folder .caret {
  display: inline-block;
  width: 10px;
  font-size: 10px;
  color: var(--muted);
  transition: transform 0.1s ease;
}
.tree-folder.collapsed .caret { transform: rotate(-90deg); }
.tree-folder.collapsed + ul { display: none; }
.tree-file {
  display: block;
  padding: 3px 6px 3px 20px;
  border-radius: 3px;
  color: var(--link);
}
.tree-file:hover { background: var(--accent); text-decoration: none; }
.tree-file.active {
  background: var(--accent);
  font-weight: 700;
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--link);
}

/* Content */
.content-wrap {
  flex: 1 1 auto;
  min-width: 0;
  padding: 20px 32px 60px;
}
.breadcrumb {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 10px;
  word-break: break-word;
}
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--link); }
.breadcrumb .sep { margin: 0 5px; color: #b0b3b8; }

.article {
  max-width: 900px;
  font-family: var(--serif);
  line-height: 1.7;
  font-size: 16.5px;
}
.article .loading { font-family: var(--sans); color: var(--muted); }

.article h1 {
  font-family: var(--serif);
  font-size: 30px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin: 0 0 6px;
}
.article h2 {
  font-size: 22px;
  border-bottom: 1px solid #eaecf0;
  padding-bottom: 4px;
  margin-top: 34px;
}
.article h3 { font-size: 18px; margin-top: 24px; }
.article h4 { font-size: 16px; margin-top: 18px; }
.article p { margin: 12px 0; }
.article em:first-of-type {
  display: inline-block;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}
.article ul, .article ol { padding-left: 28px; }
.article li { margin: 4px 0; }
.article code {
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.88em;
}
.article pre {
  background: var(--code-bg);
  padding: 12px 14px;
  overflow-x: auto;
  border-radius: 4px;
  border: 1px solid #e2e2e2;
}
.article pre code { background: none; padding: 0; }
.article blockquote {
  border-left: 4px solid var(--border);
  margin: 14px 0;
  padding: 4px 16px;
  color: var(--muted);
  background: #fafafa;
}
.article table {
  border-collapse: collapse;
  width: 100%;
  margin: 16px 0;
  font-family: var(--sans);
  font-size: 14px;
}
.article th, .article td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}
.article th { background: var(--header-bg); }
.article hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }
.article img { max-width: 100%; }

.article figure {
  float: right;
  width: 300px;
  max-width: 42%;
  margin: 4px 0 16px 22px;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px;
  font-family: var(--sans);
}
.article figure img { width: 100%; height: auto; border-radius: 2px; }
.article figcaption {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.4;
}
@media (max-width: 640px) {
  .article figure { float: none; width: 100%; max-width: 100%; margin: 14px 0; }
}

.contents-box {
  display: inline-block;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 20px;
  margin: 6px 0 20px;
  font-family: var(--sans);
  font-size: 13.5px;
}
.contents-box .contents-title {
  font-weight: 700;
  margin-bottom: 6px;
}
.contents-box ol {
  margin: 0;
  padding-left: 20px;
}
.contents-box li { margin: 3px 0; }
.contents-box a { color: var(--link); }
.contents-box ol ol { padding-left: 18px; margin-top: 3px; font-size: 0.95em; }

.categories-box {
  clear: both;
  margin-top: 36px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--muted);
}
.categories-box a {
  display: inline-block;
  background: var(--accent);
  color: var(--link);
  border: 1px solid #cfe1f7;
  border-radius: 3px;
  padding: 2px 8px;
  margin: 2px 4px 2px 0;
}
.categories-box a:hover { text-decoration: none; background: #dceafd; }

/* Home / landing */
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 18px;
}
.home-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  font-family: var(--sans);
}
.home-card h3 { margin: 0 0 6px; font-size: 15px; font-family: var(--sans); }
.home-card p { margin: 0; font-size: 13px; color: var(--muted); }

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--header-bg);
  padding: 16px;
  font-size: 12px;
  color: var(--muted);
}
.site-footer p { max-width: 1400px; margin: 8px auto 0; }
.footer-links {
  max-width: 1400px;
  margin: 0 auto;
  font-size: 13px;
}
.footer-links a { color: var(--link); font-weight: 600; }
.footer-sep { margin: 0 8px; color: var(--border); }

/* Responsive */
@media (max-width: 860px) {
  .sidebar-toggle { display: inline-block; }
  .layout { position: relative; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 53px;
    bottom: 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.15s ease;
    box-shadow: 2px 0 8px rgba(0,0,0,0.15);
  }
  .sidebar.open { transform: translateX(0); }
  .content-wrap { padding: 16px; }

  .header-inner { flex-wrap: wrap; row-gap: 8px; }
  .search-wrap {
    order: 3;
    flex: 1 1 100%;
    width: auto;
    max-width: none;
    margin-left: 0;
  }
  #search-input {
    width: 100%;
    padding: 10px 14px;
    font-size: 16px;
    border: 2px solid var(--link);
    border-radius: 20px;
    background: var(--page-bg);
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  }
  #search-input::placeholder { color: var(--muted); }
  .site-subtitle { display: none; }
}

/* Downloadable files (lesson slides) linked from a page */
.article a.file-link::after {
  content: "Download";
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 11px;
  line-height: 17px;
  font-weight: 600;
  color: var(--muted);
  vertical-align: 1px;
}
.article a.file-link:hover::after { color: var(--link); border-color: var(--link); }
