:root[data-theme="dark"] {
  --bg: #14161a;
  --bg-elevated: #1b1e24;
  --bg-hover: #23272f;
  --border: #2b2f38;
  --text: #e7e9ee;
  --text-dim: #9aa2af;
  --text-faint: #6b7280;
  --accent: #6ea8fe;
  --accent-dim: #3f6dbd;
  --tag-bg: #263049;
  --tag-text: #9fc0ff;
  --code-bg: #1e2128;
  --shadow: rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.65;
}

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

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

/* Sidebar */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  padding-bottom: 2rem;
}

.sidebar-header {
  padding: 1.25rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}

.site-title {
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-folder summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  border-radius: 6px;
  padding-right: 0.6rem;
}
.nav-folder summary::-webkit-details-marker { display: none; }
.nav-folder summary::marker { content: ""; }

.nav-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  margin-right: 0.3rem;
  flex-shrink: 0;
  color: var(--text-faint);
  font-size: 0.7rem;
  transition: transform 0.15s ease;
}
.nav-folder details[open] > summary .nav-arrow {
  transform: rotate(90deg);
}

.nav-link {
  display: block;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}
.nav-link.nav-folder-link {
  color: var(--text);
  font-weight: 600;
  flex: 1;
  padding-left: 0;
}
.nav-link.active {
  background: var(--accent-dim);
  color: #fff;
}

/* Content column */
.content-col {
  flex: 1;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  background: rgba(20, 22, 26, 0.9);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}

.icon-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
}

.search-wrap {
  position: relative;
  max-width: 480px;
  width: 100%;
}

#search-input {
  width: 100%;
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.95rem;
}
#search-input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 24px var(--shadow);
  max-height: 60vh;
  overflow-y: auto;
  z-index: 20;
}
.search-results.hidden { display: none; }

.search-result {
  display: block;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result.active-result {
  background: var(--bg-hover);
  text-decoration: none;
}
.search-result-title { font-weight: 600; font-size: 0.95rem; }
.search-result-cat { color: var(--text-faint); font-size: 0.78rem; margin-bottom: 0.15rem; }
.search-result-snippet { color: var(--text-dim); font-size: 0.85rem; margin-top: 0.15rem; }
.search-empty { padding: 0.9rem; color: var(--text-faint); font-size: 0.9rem; }
mark {
  background: var(--accent-dim);
  color: #fff;
  border-radius: 3px;
  padding: 0 2px;
}

.content {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 2rem 4rem;
}

.breadcrumbs {
  font-size: 0.85rem;
  color: var(--text-faint);
  margin-bottom: 1.25rem;
}
.breadcrumbs a { color: var(--text-dim); }
.crumb-sep { margin: 0 0.4rem; }

.prose h1 { font-size: 1.9rem; margin-bottom: 0.5rem; }
.prose h2 { font-size: 1.35rem; margin-top: 2rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
.prose h3 { font-size: 1.1rem; margin-top: 1.5rem; }
.prose p { margin: 0.9rem 0; }
.prose img { max-width: 100%; border-radius: 8px; }
.prose ul, .prose ol { padding-left: 1.4rem; }
.prose li { margin: 0.3rem 0; }
.prose code {
  background: var(--code-bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.88em;
}
.prose pre {
  background: var(--code-bg);
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
}
.prose pre code { background: none; padding: 0; }
.prose blockquote {
  border-left: 3px solid var(--accent-dim);
  margin: 1rem 0;
  padding: 0.2rem 1rem;
  color: var(--text-dim);
}
.prose hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }
.prose a { text-decoration: underline; text-decoration-color: var(--accent-dim); }

.card-list {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.6rem;
}
.card-list li {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.card-list a {
  display: block;
  padding: 0.75rem 1rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.card-list a:hover { background: var(--bg-hover); }

.meta-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}
.meta-row { display: flex; gap: 0.6rem; padding: 0.2rem 0; }
.meta-label { color: var(--text-faint); min-width: 90px; flex-shrink: 0; }
.meta-value { color: var(--text-dim); }
.tag {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.78rem;
  margin-right: 0.3rem;
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: -300px;
    top: 0;
    z-index: 30;
    width: 280px;
    transition: left 0.2s ease;
    box-shadow: 0 0 40px var(--shadow);
  }
  .sidebar.open { left: 0; }
  .icon-btn { display: inline-block; }
  .content { padding: 1.25rem 1.25rem 3rem; }
}
