:root {
  --bg: #111827;
  --bg-alt: #1f2937;
  --text: #e5e7eb;
  --accent: #f97316;
  --border: #374151;
  --hover: #4b5563;
  --sidebar-width: 320px;
  --font-body: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="light"] {
  --bg: #f9fafb;
  --bg-alt: #ffffff;
  --text: #111827;
  --accent: #f97316;
  --border: #e5e7eb;
  --hover: #f3f4f6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
}

#app {
  display: flex;
  height: 100vh;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header h1 {
  font-size: 1.2rem;
  margin: 0;
}

#themeToggle {
  border: none;
  background: var(--hover);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}

/* Search */
.search-box {
  margin: 12px 0;
}

#searchInput {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

/* TOC */
#toc {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
}

.toc-section {
  margin-bottom: 12px;
}

.toc-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  padding: 6px 4px;
  border-radius: 4px;
}

.toc-section-header:hover {
  background: var(--hover);
}

.toc-section-title {
  font-weight: 600;
}

.toc-items {
  margin-top: 4px;
  padding-left: 10px;
}

.toc-item {
  padding: 6px 4px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.95rem;
}

.toc-item:hover {
  background: var(--hover);
}

.toc-item.active {
  background: var(--accent);
  color: #111827;
}

/* Main content */
#main {
  flex: 1;
  padding: 24px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#contentHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

#chapterTitle {
  margin: 0;
}

.nav-buttons button {
  border: none;
  background: var(--hover);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  margin-left: 6px;
  cursor: pointer;
}

.nav-buttons button:disabled {
  opacity: 0.4;
  cursor: default;
}

#content {
  flex: 1;
  overflow-y: auto;
  line-height: 1.6;
}

#content h1, #content h2, #content h3 {
  margin-top: 1.2em;
}

/* Responsive */
@media (max-width: 768px) {
  #app {
    flex-direction: column;
  }
  #sidebar {
    width: 100%;
    height: 40vh;
  }
  #main {
    height: 60vh;
  }
}
