/* =========================================
   Wiki — Dark Theme
   ========================================= */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:          #0a0a0f;
  --bg-sidebar:  #111118;
  --bg-hover:    #1a1a24;
  --bg-active:   #1e2030;
  --bg-code:     #1a1a24;
  --bg-topbar:   #0d0d14;
  --border:      #1e1e2e;
  --border-soft: #16161f;

  --text:        #e0e0e0;
  --text-muted:  #8b8ba0;
  --text-faint:  #4a4a60;

  --accent:      #60a5fa;
  --accent-soft: rgba(96, 165, 250, 0.12);
  --accent-glow: rgba(96, 165, 250, 0.06);

  --green:       #4ade80;
  --purple:      #a78bfa;
  --amber:       #fbbf24;

  --topbar-h:    52px;
  --sidebar-w:   260px;
  --right-w:     220px;
  --content-max: 720px;

  --radius-sm:   4px;
  --radius:      6px;
  --radius-lg:   10px;

  --font:        'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:   'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;

  --transition:  150ms ease;
}

/* ---- Base ---- */

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
  overflow-x: hidden;
}

::selection {
  background: var(--accent-soft);
  color: var(--text);
}

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

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---- Scrollbar ---- */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* =========================================
   Top Bar
   ========================================= */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  z-index: 100;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  width: var(--sidebar-w);
}

.topbar-center {
  flex: 1;
  min-width: 0;
}

.topbar-right {
  position: relative;
  flex-shrink: 0;
}

/* Hamburger */
.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  line-height: 0;
  transition: color var(--transition), background var(--transition);
}

.hamburger:hover {
  color: var(--text);
  background: var(--bg-hover);
}

/* Site title */
.site-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0.01em;
  text-decoration: none;
}

.site-title:hover { color: var(--text); text-decoration: none; }
.site-icon { color: var(--accent); flex-shrink: 0; }

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
}

.breadcrumb-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.breadcrumb-item a {
  color: var(--text-muted);
}

.breadcrumb-item a:hover {
  color: var(--accent);
  text-decoration: none;
}

.breadcrumb-sep {
  color: var(--text-faint);
  user-select: none;
}

.breadcrumb-current {
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Search */
.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-faint);
  pointer-events: none;
}

.search-input {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 6px 60px 6px 34px;
  width: 220px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-input::placeholder { color: var(--text-faint); }

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.search-kbd {
  position: absolute;
  right: 8px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-faint);
  font-size: 0.65rem;
  font-family: var(--font);
  padding: 2px 5px;
  pointer-events: none;
  white-space: nowrap;
}

.search-input:focus ~ .search-kbd { display: none; }

/* Search results dropdown */
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 320px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 40px rgba(0,0,0,0.5);
  overflow: hidden;
  z-index: 200;
}

.search-results[hidden] { display: none; }

.search-result-item {
  display: block;
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border-soft);
  transition: background var(--transition);
  text-decoration: none;
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover, .search-result-item.focused { background: var(--bg-active); }

.search-result-title {
  font-weight: 500;
  margin-bottom: 2px;
}

.search-result-excerpt {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-result-path {
  font-size: 0.7rem;
  color: var(--text-faint);
  margin-top: 3px;
}

.search-no-results {
  padding: 20px 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

mark {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 2px;
  padding: 0 1px;
}

/* =========================================
   Layout
   ========================================= */

.layout {
  display: flex;
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
}

/* =========================================
   Sidebar
   ========================================= */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  left: 0;
  overflow-y: auto;
  z-index: 50;
  transition: transform var(--transition);
}

.sidebar-inner {
  padding: 16px 0 32px;
}

/* Mobile overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 40;
  backdrop-filter: blur(2px);
}

/* Nav tree */
.nav-tree { user-select: none; }

.nav-section { margin-bottom: 2px; }

.nav-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 0;
  transition: color var(--transition), background var(--transition);
}

.nav-section-header:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.nav-section-icon { color: var(--text-faint); flex-shrink: 0; }
.nav-section-arrow {
  margin-left: auto;
  color: var(--text-faint);
  transition: transform var(--transition);
  flex-shrink: 0;
}

.nav-section.open .nav-section-arrow { transform: rotate(90deg); }

.nav-section-items {
  overflow: hidden;
  transition: max-height 0.2s ease;
}

.nav-section.closed .nav-section-items { max-height: 0 !important; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px 6px 32px;
  font-size: 0.83rem;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 0;
  transition: color var(--transition), background var(--transition);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item-icon { color: var(--text-faint); flex-shrink: 0; }

.nav-item:hover {
  color: var(--text);
  background: var(--bg-hover);
  text-decoration: none;
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-glow);
  border-right: 2px solid var(--accent);
}

.nav-item.active .nav-item-icon { color: var(--accent); }

/* Direct link (no folder) */
.nav-direct {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  font-size: 0.83rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
  text-decoration: none;
}

.nav-direct:hover {
  color: var(--text);
  background: var(--bg-hover);
  text-decoration: none;
}

.nav-direct.active {
  color: var(--accent);
  background: var(--accent-glow);
  border-right: 2px solid var(--accent);
}

/* =========================================
   Content Area
   ========================================= */

.content-area {
  flex: 1;
  margin-left: var(--sidebar-w);
  margin-right: var(--right-w);
  min-width: 0;
  padding: 48px 40px;
}

.article {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* Loading spinner */
.article-loading {
  display: flex;
  justify-content: center;
  padding: 80px 0;
}

.article-loading[hidden] { display: none; }
.article-body[hidden] { display: none; }

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================
   Article Typography
   ========================================= */

.article-body h1 {
  font-size: 1.85rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.02em;
}

.article-body h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 40px;
  margin-bottom: 14px;
  letter-spacing: -0.01em;
}

.article-body h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 28px;
  margin-bottom: 10px;
}

.article-body h4, .article-body h5, .article-body h6 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 20px;
  margin-bottom: 8px;
}

.article-body p {
  margin-bottom: 16px;
  color: var(--text);
}

.article-body ul, .article-body ol {
  margin: 0 0 16px 24px;
}

.article-body li {
  margin-bottom: 5px;
  color: var(--text);
}

.article-body li > ul, .article-body li > ol {
  margin-top: 5px;
  margin-bottom: 0;
}

.article-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(96,165,250,0.4);
  transition: text-decoration-color var(--transition);
}

.article-body a:hover {
  text-decoration-color: var(--accent);
}

/* Wiki links — dashed underline to distinguish */
.article-body a.wikilink {
  color: var(--accent);
  text-decoration: underline dashed;
  text-underline-offset: 4px;
  text-decoration-color: rgba(96,165,250,0.5);
}

.article-body a.wikilink:hover {
  text-decoration-style: solid;
  text-decoration-color: var(--accent);
}

/* Blockquote */
.article-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 20px 0;
  padding: 12px 20px;
  background: var(--accent-glow);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.article-body blockquote p {
  margin: 0;
  color: var(--text-muted);
  font-style: italic;
}

/* Code inline */
.article-body code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: var(--bg-code);
  color: var(--amber);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* Code block */
.article-body pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow-x: auto;
  margin: 20px 0;
  font-family: var(--font-mono);
  font-size: 0.83rem;
  line-height: 1.6;
  position: relative;
}

.article-body pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
  font-size: inherit;
}

/* Syntax highlight basics */
.article-body pre .keyword { color: var(--purple); }
.article-body pre .string  { color: var(--green); }
.article-body pre .comment { color: var(--text-faint); font-style: italic; }
.article-body pre .number  { color: var(--amber); }

/* Table */
.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 0.88rem;
}

.article-body th {
  background: var(--bg-sidebar);
  color: var(--text-muted);
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.article-body td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
}

.article-body tr:hover td { background: var(--bg-hover); }

/* HR */
.article-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

/* Strong, em */
.article-body strong { font-weight: 600; color: var(--text); }
.article-body em     { color: var(--text-muted); }

/* Image */
.article-body img {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin: 16px 0;
}

/* =========================================
   Right Panel
   ========================================= */

.right-panel {
  width: var(--right-w);
  flex-shrink: 0;
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  overflow-y: auto;
  padding: 28px 0;
  border-left: 1px solid var(--border);
}

.right-panel-inner {
  padding: 0 16px;
}

.panel-heading {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

/* Backlinks */
.backlinks-section { margin-bottom: 32px; }

.backlinks-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.backlink-item a {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
  text-decoration: none;
}

.backlink-item a:hover {
  color: var(--accent);
  background: var(--bg-hover);
}

/* TOC */
.toc-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.toc-link {
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.toc-link:hover {
  color: var(--text);
  background: var(--bg-hover);
  text-decoration: none;
}

.toc-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
}

.toc-link[data-level="3"] { padding-left: 20px; font-size: 0.74rem; }
.toc-link[data-level="4"] { padding-left: 32px; font-size: 0.71rem; }

/* =========================================
   Empty / Error states
   ========================================= */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state svg { margin: 0 auto 16px; display: block; opacity: 0.3; }
.empty-state h2  { font-size: 1rem; font-weight: 500; margin-bottom: 8px; }
.empty-state p   { font-size: 0.85rem; opacity: 0.7; }

/* =========================================
   Responsive — Mobile
   ========================================= */

@media (max-width: 1100px) {
  :root { --right-w: 180px; }
}

@media (max-width: 900px) {
  .right-panel { display: none; }
  .content-area { margin-right: 0; }
}

@media (max-width: 720px) {
  :root {
    --topbar-h: 48px;
    --sidebar-w: 280px;
  }

  .hamburger { display: flex; }
  .topbar-left { width: auto; }
  .search-input { width: 180px; }
  .search-kbd { display: none; }

  .sidebar {
    transform: translateX(-100%);
    z-index: 60;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }

  .sidebar-overlay.active {
    display: block;
  }

  .content-area {
    margin-left: 0;
    padding: 32px 20px;
  }

  .article-body h1 { font-size: 1.5rem; }
}

@media (max-width: 480px) {
  .topbar-center { display: none; }
  .search-input { width: 140px; }
  .content-area { padding: 24px 16px; }
}
