/* Local theme with GitBook-inspired layout and styles (closer to sighingnow/jekyll-gitbook) */
:root {
  --bg: #f4ecd8;
  --text: #5b4636;
  --muted: #a58b6f;
  --link: #b7791f;
  --border: #e0c9a6;
  --sidebar-bg: #f7f2e3;
  --toc-bg: #f4ecd8;
  --code-bg: #f5e9d4;
  --code-fg: #5b4636;
  --highlight: #f7e7c4;
  --topbar-bg: #f4ecd8;
}

[data-theme="dark"] {
  --bg: #2b2b2b;
  --text: #a9b7c6;
  --muted: #6c7077;
  --link: #ffc66d;
  --border: #3c3f41;
  --sidebar-bg: #313335;
  --toc-bg: #313335;
  --code-bg: #3c3f41;
  --code-fg: #a9b7c6;
  --highlight: #323232;
  --topbar-bg: #313335;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* Topbar like GitBook */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 0.5rem 1rem; display: flex; align-items: center; justify-content: space-between; }
.topbar-brand { font-weight: 600; color: inherit; }
.topbar-desc { color: var(--muted); margin-left: 0.5rem; font-size: 0.9rem; }
/* Topbar search */
.topbar-nav { flex: 0 1 460px; }
.topbar-nav form { position: relative; display: block; }
#site-search { width: 100%; max-width: 460px; padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.95rem; outline: none; background: #fff; }
#site-search:focus { box-shadow: 0 0 0 3px rgba(65,131,196,0.15); }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.08); max-height: 60vh; overflow: auto; }
.search-results ul { list-style: none; margin: 0; padding: 0.35rem; }
.search-results li { margin: 0; }
.search-results a { display: block; padding: 0.35rem 0.5rem; color: inherit; border-radius: 6px; }
.search-results a:hover { background: var(--highlight); text-decoration: none; }

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

/* Left navigation */
.sidebar {
  width: 300px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 1rem 1rem 2rem 1rem;
  position: sticky;
  top: 0;
  align-self: flex-start;
  max-height: calc(100vh - 0px);
  overflow: auto;
}

.sidebar-controls { position: sticky; top: 0; background: var(--sidebar-bg); padding-bottom: 0.5rem; }
#sidebar-search {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  outline: none;
  background: #fff;
}
#sidebar-search:focus { box-shadow: 0 0 0 3px rgba(65,131,196,0.15); }

.brand { margin-bottom: 0.75rem; }
.brand-title { font-weight: 700; font-size: 1.05rem; color: inherit; }
.brand-desc { color: var(--muted); font-size: 0.9rem; margin-top: 0.25rem; }

/* Hide SUMMARY heading like GitBook */
.nav .nav-tree h1 { display: none; }

.nav .nav-tree > ul { list-style: none; padding-left: 0.5rem; margin: 0; }
.nav ul { list-style: none; margin: 0.25rem 0 0.5rem 0; padding-left: 0; }
.nav ul ul { padding-left: 1rem; }

.nav li { margin: 0.15rem 0; }

/* Links */
.nav a { color: inherit; display: block; padding: 0.15rem 0.5rem; border-left: 3px solid transparent; border-radius: 0; }
.nav a:hover { color: var(--link); background: var(--highlight); text-decoration: none; }
.nav a.active { color: var(--link); background: var(--highlight); font-weight: 600; border-left-color: var(--link); }

/* Sidebar separator */
.nav hr { border: 0; border-top: 1px solid var(--border); margin: 0.5rem 0; }

/* Collapsible sections */
.nav li.has-children > .tree-toggle {
  cursor: pointer;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  padding: 0.15rem 0.5rem;
  border-left: 3px solid transparent;
}
.nav li.has-children > .tree-toggle:hover {
  color: var(--link);
  background: var(--highlight);
  text-decoration: none;
}
.nav li.has-children.open > .tree-toggle {
  color: var(--link);
  background: var(--highlight);
  font-weight: 600;
  border-left-color: var(--link);
}
.nav li.has-children > .tree-toggle::before {
  content: '▸';
  display: inline-block;
  margin-right: 0.35rem;
  color: var(--muted);
  transition: transform 0.15s ease;
}
.nav li.has-children.open > .tree-toggle::before {
  transform: rotate(90deg);
  color: var(--muted);
}
.nav li.has-children > ul { display: none; }
.nav li.has-children.open > ul { display: block; }

/* Main area + right TOC */
.main { flex: 1 1 auto; }
.main-inner { display: flex; gap: 2rem; max-width: 1100px; margin: 0 auto; padding: 2rem; }

.content { flex: 1 1 auto; min-width: 0; }

.toc { width: 280px; flex: 0 0 280px; border-left: 1px solid var(--border); padding-left: 1rem; position: sticky; top: 0; align-self: flex-start; max-height: calc(100vh - 0px); overflow: auto; background: var(--toc-bg); }
.toc-title { font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 0.75rem 0; }
#page-toc ul { list-style: none; padding-left: 0.5rem; margin: 0; }
#page-toc li { margin: 0.2rem 0; }
#page-toc a { color: inherit; display: block; padding: 0.15rem 0.25rem; border-radius: 6px; }
#page-toc a:hover { background: var(--highlight); text-decoration: none; }
#page-toc a.is-active { color: var(--link); background: var(--highlight); font-weight: 600; }
#page-toc .lvl-2 { padding-left: 0.25rem; }
#page-toc .lvl-3 { padding-left: 1rem; }

/* Page content */
.page-header { margin-bottom: 1rem; }
.page-header h1 { margin: 0 0 0.5rem 0; font-size: 1.9rem; }
.post-meta { color: var(--muted); font-size: 0.92rem; }

.page-content { max-width: 740px; }
.page-content img { max-width: 100%; height: auto; }
.page-content code { background: #f3f4f6; padding: 0.15rem 0.35rem; border-radius: 4px; }
.page-content pre { background: var(--code-bg); color: var(--code-fg); padding: 1rem; overflow: auto; border-radius: 8px; }
.page-content pre code { background: none; padding: 0; }
.page-content .mermaid { background: #fff; color: inherit; border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; overflow: auto; }
.page-content blockquote { border-left: 4px solid var(--border); margin: 0; padding: 0.5rem 1rem; color: #374151; background: #fafafa; }

/* Heading anchors */
.page-content h1, .page-content h2, .page-content h3, .page-content h4 { scroll-margin-top: 4rem; position: relative; }
.heading-anchor { opacity: 0; margin-left: 0.25rem; text-decoration: none; color: var(--muted); font-size: 0.85em; }
.page-content h2:hover .heading-anchor, .page-content h3:hover .heading-anchor, .page-content h4:hover .heading-anchor { opacity: 1; }

.site-footer { margin-top: 2rem; color: var(--muted); font-size: 0.9rem; border-top: 1px solid var(--border); padding-top: 1rem; }

/* Tables */
.page-content table { border-collapse: collapse; border-spacing: 0; }
.page-content th, .page-content td { border: 1px solid var(--border); padding: 0.5rem 0.6rem; }
.page-content th { background: #f8fafc; text-align: left; }

/* Utilities */
.hidden { display: none !important; }

/* Responsive */
@media (max-width: 1200px) {
  .toc { display: none; }
}
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .main { order: 1; }
  .sidebar { order: 2; width: auto; position: relative; max-height: none; }
  .main-inner { padding: 1rem; }
}


/* Note tags and related notes */
.note-tags { margin-top: 1.5rem; display: flex; align-items: flex-start; gap: 0.5rem; flex-wrap: wrap; }
.note-tags-label { color: var(--muted); font-size: 0.9rem; margin-right: 0.25rem; }
.note-tags-list { list-style: none; margin: 0; padding: 0; display: inline-flex; flex-wrap: wrap; gap: 0.4rem; }
.note-tag { display: inline-block; background: transparent; border: 0; padding: 0; }
.note-tag a { display: inline-block; font-size: 0.85rem; color: #1f2937; background: #eef2f7; border: 1px solid var(--border); border-radius: 999px; padding: 0.1rem 0.5rem; }
.note-tag a:hover { background: var(--highlight); text-decoration: none; }

/* Inline tag chips (used on All notes / Home) */
.tag-list-inline { display: inline-flex; gap: 0.3rem; flex-wrap: wrap; margin-left: 0.4rem; vertical-align: middle; }
.tag-chip { display: inline-block; border-radius: 999px; }
.tag-chip a { display: inline-block; font-size: 0.75rem; padding: 0.05rem 0.45rem; border-radius: 999px; border: 1px solid transparent; text-decoration: none; }
.tag-chip a:hover { text-decoration: none; opacity: 0.9; }

/* Cheerful pastel palette */
.tag-chip.c1 a { background: #eaf7ff; border-color: #bde0ff; color: #0b3954; }
.tag-chip.c2 a { background: #eafff5; border-color: #b9f3d0; color: #0b4f2f; }
.tag-chip.c3 a { background: #fff4ea; border-color: #ffd8b5; color: #5d3b09; }
.tag-chip.c4 a { background: #f3ecff; border-color: #d9c9ff; color: #442a7a; }
.tag-chip.c5 a { background: #ffecf2; border-color: #ffc9dc; color: #7a1e45; }
.tag-chip.c6 a { background: #f0fff4; border-color: #c6f6d5; color: #1a4d2e; }
.tag-chip.c7 a { background: #fffbe6; border-color: #ffe58f; color: #614700; }
.tag-chip.c8 a { background: #e6fffb; border-color: #87e8de; color: #00474f; }
.tag-chip.c9 a { background: #f0f5ff; border-color: #adc6ff; color: #102a75; }
.tag-chip.c10 a { background: #fdf2f8; border-color: #f8b4d9; color: #702459; }

.related-notes { margin-top: 2rem; }
.related-notes h2 { font-size: 1.1rem; margin: 0 0 0.5rem 0; }
.related-notes ul { list-style: disc; padding-left: 1.25rem; margin: 0.25rem 0 0 0; }
