/* 工程概论学习站 */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1a1d23;
  --muted: #5c6370;
  --border: #e2e5eb;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --star: #d97706;
  --sidebar-w: 280px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "Cascadia Code", "Consolas", monospace;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d27;
  --text: #e8eaed;
  --muted: #9aa0ab;
  --border: #2d3340;
  --accent: #60a5fa;
  --accent-soft: #1e293b;
  --star: #fbbf24;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
}

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  z-index: 20;
}

.brand {
  padding: 1.25rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.search-wrap {
  padding: 0.75rem 1rem;
}

.search-wrap input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.search-wrap input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.75rem;
  margin-bottom: 2px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.88rem;
  line-height: 1.4;
}

.nav-item:hover {
  background: var(--accent-soft);
}

.nav-item.active {
  background: var(--accent);
  color: #fff;
}

.nav-item .meta {
  display: block;
  font-size: 0.75rem;
  opacity: 0.85;
  margin-top: 0.15rem;
}

.nav-item.active .meta {
  opacity: 0.9;
}

.nav-item.hidden {
  display: none;
}

.sidebar-foot {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.sidebar-foot button {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}

/* Main */
.main {
  flex: 1;
  min-width: 0;
  padding: 2rem 2.5rem 4rem;
  max-width: 920px;
}

.content :is(h1, h2, h3, h4) {
  scroll-margin-top: 1rem;
  line-height: 1.35;
}

.content h1 { font-size: 1.75rem; margin-top: 0; }
.content h2 {
  font-size: 1.25rem;
  margin-top: 2rem;
  padding-bottom: 0.35rem;
  border-bottom: 2px solid var(--border);
}
.content h3 { font-size: 1.05rem; margin-top: 1.5rem; }

.content p { margin: 0.75rem 0; }

.content blockquote {
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  color: var(--muted);
  font-size: 0.92rem;
}

.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}

.content th,
.content td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.65rem;
  text-align: left;
}

.content th {
  background: var(--accent-soft);
  font-weight: 600;
}

.content code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--accent-soft);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.content pre {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}

.content pre code {
  background: none;
  padding: 0;
}

.content ul, .content ol {
  padding-left: 1.35rem;
}

.content li { margin: 0.35rem 0; }

.content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

.content .mermaid {
  margin: 1rem 0;
  text-align: center;
}

.content strong:has(+ *) {
  color: inherit;
}

/* Highlight importance stars in rendered text */
.content {
  word-wrap: break-word;
}

.nav-section {
  padding: 0.65rem 1rem 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-section:not(:first-child) {
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
}

.tag-calc,
.tag-hw,
.tag-note {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  margin-left: 0.35rem;
}

.tag-calc {
  background: #fef3c7;
  color: #92400e;
}

.tag-hw {
  background: #dbeafe;
  color: #1d4ed8;
}

.tag-note {
  background: #ecfdf5;
  color: #047857;
}

[data-theme="dark"] .tag-calc {
  background: #422006;
  color: #fcd34d;
}

[data-theme="dark"] .tag-hw {
  background: #1e3a5f;
  color: #93c5fd;
}

[data-theme="dark"] .tag-note {
  background: #064e3b;
  color: #6ee7b7;
}

.content img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0.75rem 0 1rem;
}

.content .hw-question {
  margin-top: 1.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
}

.loading, .error {
  color: var(--muted);
}

.menu-toggle {
  display: none;
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 30;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.toc-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.toc-bar a {
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  background: var(--accent-soft);
}

.toc-bar a:hover {
  text-decoration: underline;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .menu-toggle {
    display: block;
  }

  .main {
    padding: 1.25rem 1rem 5rem;
  }
}
