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

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-hover: #222633;
  --bg-sidebar: #141620;
  --bg-topbar: #141620ee;
  --border: #2a2e3a;
  --text: #e4e6ed;
  --text-secondary: #8b8fa3;
  --text-muted: #5c6070;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --accent-glow: rgba(108, 92, 231, 0.15);
  --green: #00b894;
  --red: #e17055;
  --sidebar-width: 260px;
  --topbar-height: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
}

/* Light theme */
[data-theme="light"] {
  --bg: #f5f6fa;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f1f5;
  --bg-sidebar: #ffffff;
  --bg-topbar: #ffffffee;
  --border: #e1e4ea;
  --text: #1a1d27;
  --text-secondary: #5c6070;
  --text-muted: #8b8fa3;
  --accent: #6c5ce7;
  --accent-light: #5a4bd1;
  --accent-glow: rgba(108, 92, 231, 0.08);
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

html { font-size: 15px; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Topbar ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: var(--bg-topbar);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 16px; }
.menu-btn {
  display: none;
  background: none; border: none; color: var(--text);
  font-size: 1.4rem; cursor: pointer; padding: 4px 8px;
}
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.logo-icon { font-size: 1.5rem; }
.logo-text { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em; }
.topbar-center { flex: 1; max-width: 480px; margin: 0 32px; }
.search-container { position: relative; width: 100%; }
.search-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 0.9rem; color: var(--text-muted);
}
#searchInput {
  width: 100%; padding: 10px 16px 10px 42px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 0.9rem; outline: none; transition: border 0.2s;
}
#searchInput:focus { border-color: var(--accent); }
#searchInput::placeholder { color: var(--text-muted); }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  max-height: 400px; overflow-y: auto; display: none; box-shadow: var(--shadow);
}
.search-results.active { display: block; }
.search-result-item {
  padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-card-hover); }
.search-result-subject { font-size: 0.75rem; color: var(--accent-light); font-weight: 500; }
.search-result-title { font-size: 0.9rem; color: var(--text); margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.breadcrumb { font-size: 0.85rem; color: var(--text-secondary); }
.breadcrumb a { color: var(--accent-light); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ── Theme Toggle ── */
.theme-toggle {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 10px; cursor: pointer;
  display: flex; align-items: center; gap: 4px;
  transition: all 0.2s; font-size: 1rem;
}
.theme-toggle:hover { border-color: var(--accent); background: var(--bg-card-hover); }
.theme-icon-sun { display: none; }
.theme-icon-moon { display: inline; }
[data-theme="light"] .theme-icon-sun { display: inline; }
[data-theme="light"] .theme-icon-moon { display: none; }

/* ── Sidebar ── */
.sidebar {
  position: fixed; top: var(--topbar-height); left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto; z-index: 90;
  transition: transform 0.25s ease;
}
.sidebar-header {
  padding: 20px 20px 12px;
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted);
}
.sidebar-nav { padding: 0 8px 20px; }
.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.15s;
  text-decoration: none; color: var(--text-secondary); font-size: 0.88rem;
}
.sidebar-item:hover { background: var(--bg-card); color: var(--text); }
.sidebar-item.active { background: var(--accent-glow); color: var(--accent-light); font-weight: 500; }
.sidebar-item-icon { font-size: 1.1rem; width: 24px; text-align: center; }
.sidebar-item-count {
  margin-left: auto; font-size: 0.72rem; font-weight: 600;
  background: var(--bg-card); padding: 2px 8px; border-radius: 20px;
  color: var(--text-muted);
}
.sidebar-item.active .sidebar-item-count { background: rgba(108,92,231,0.2); color: var(--accent-light); }

/* ── Main Content ── */
.content {
  margin-left: var(--sidebar-width);
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
  padding: 32px 40px;
}
.view.hidden { display: none; }

/* ── Dashboard ── */
.dashboard-header { margin-bottom: 36px; }
.dashboard-header h1 {
  font-size: 2rem; font-weight: 800; letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--accent-light), var(--green));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.dashboard-subtitle { color: var(--text-secondary); margin-top: 6px; font-size: 0.95rem; }

.subjects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
}
.subject-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}
.subject-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--card-accent, var(--accent));
  opacity: 0; transition: opacity 0.2s;
}
.subject-card:hover { background: var(--bg-card-hover); border-color: var(--card-accent, var(--accent)); transform: translateY(-2px); }
.subject-card:hover::before { opacity: 1; }
.subject-card-icon { font-size: 2rem; margin-bottom: 12px; }
.subject-card-name { font-size: 1.05rem; font-weight: 700; margin-bottom: 6px; }
.subject-card-desc { font-size: 0.82rem; color: var(--text-secondary); line-height: 1.5; margin-bottom: 16px; }
.subject-card-meta { display: flex; gap: 16px; }
.subject-card-stat {
  font-size: 0.78rem; color: var(--text-muted); display: flex; align-items: center; gap: 5px;
}
.subject-card-stat strong { color: var(--text-secondary); font-weight: 600; }

/* ── Subject View ── */
.subject-header {
  display: flex; align-items: flex-start; gap: 20px;
  margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--border);
}
.subject-header-icon { font-size: 2.5rem; }
.subject-header-info h1 { font-size: 1.6rem; font-weight: 700; }
.subject-header-info p { color: var(--text-secondary); margin-top: 4px; font-size: 0.9rem; }

.subject-tabs {
  display: flex; gap: 4px; margin-bottom: 24px;
  border-bottom: 1px solid var(--border); padding-bottom: 0;
}
.subject-tab {
  padding: 10px 18px; cursor: pointer; font-size: 0.85rem; font-weight: 500;
  color: var(--text-secondary); border-bottom: 2px solid transparent;
  transition: all 0.15s; background: none; border-top: none; border-left: none; border-right: none;
}
.subject-tab:hover { color: var(--text); }
.subject-tab.active { color: var(--accent-light); border-bottom-color: var(--accent); }

.chapter-list { display: flex; flex-direction: column; gap: 6px; }
.chapter-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.15s;
}
.chapter-item:hover { background: var(--bg-card-hover); border-color: var(--accent); }
.chapter-num {
  font-size: 0.75rem; font-weight: 700; color: var(--accent-light);
  background: var(--accent-glow); padding: 4px 10px; border-radius: 6px;
  min-width: 36px; text-align: center;
}
.chapter-title { font-size: 0.92rem; font-weight: 500; flex: 1; }
.chapter-arrow { color: var(--text-muted); font-size: 0.8rem; }

/* ── Chapter View ── */
.chapter-header {
  margin-bottom: 32px; padding-bottom: 20px; border-bottom: 1px solid var(--border);
}
.chapter-header h1 { font-size: 1.5rem; font-weight: 700; line-height: 1.4; }
.chapter-header .chapter-meta {
  display: flex; gap: 16px; margin-top: 10px; flex-wrap: wrap;
}
.chapter-tag {
  font-size: 0.72rem; font-weight: 500; padding: 3px 10px;
  border-radius: 20px; background: var(--accent-glow); color: var(--accent-light);
}
.chapter-back {
  display: inline-flex; align-items: center; gap: 6px;
  margin-bottom: 16px; padding: 8px 14px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-secondary);
  cursor: pointer; font-size: 0.85rem; transition: all 0.15s;
  text-decoration: none;
}
.chapter-back:hover { background: var(--bg-card-hover); color: var(--text); }

/* ── Markdown Content ── */
.markdown-content { line-height: 1.75; font-size: 0.95rem; }
.markdown-content h1 { font-size: 1.6rem; font-weight: 800; margin: 32px 0 16px; letter-spacing: -0.02em; }
.markdown-content h2 { font-size: 1.3rem; font-weight: 700; margin: 28px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.markdown-content h3 { font-size: 1.1rem; font-weight: 600; margin: 22px 0 10px; }
.markdown-content h4 { font-size: 1rem; font-weight: 600; margin: 18px 0 8px; }
.markdown-content p { margin: 10px 0; color: var(--text); }
.markdown-content ul, .markdown-content ol { margin: 10px 0 10px 24px; }
.markdown-content li { margin: 4px 0; }
.markdown-content strong { color: #fff; font-weight: 600; }
.markdown-content em { color: var(--accent-light); }
.markdown-content blockquote {
  margin: 16px 0; padding: 14px 18px;
  border-left: 3px solid var(--accent);
  background: var(--accent-glow); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary); font-style: italic;
}
.markdown-content table {
  width: 100%; border-collapse: collapse; margin: 16px 0;
  font-size: 0.88rem;
}
.markdown-content th, .markdown-content td {
  padding: 10px 14px; border: 1px solid var(--border); text-align: left;
}
.markdown-content th {
  background: var(--bg-card); font-weight: 600; color: var(--accent-light);
}
.markdown-content tr:hover { background: var(--bg-card); }
.markdown-content code {
  background: var(--bg-card); padding: 2px 7px; border-radius: 4px;
  font-size: 0.88em; color: var(--accent-light); font-family: 'JetBrains Mono', monospace;
}
.markdown-content pre {
  background: var(--bg-card); padding: 18px; border-radius: var(--radius-sm);
  overflow-x: auto; margin: 16px 0; border: 1px solid var(--border);
}
.markdown-content pre code { background: none; padding: 0; }
.markdown-content hr {
  border: none; border-top: 1px solid var(--border); margin: 28px 0;
}
.markdown-content a { color: var(--accent-light); text-decoration: none; }
.markdown-content a:hover { text-decoration: underline; }
.markdown-content img {
  max-width: 100%; border-radius: var(--radius-sm); margin: 12px 0;
}

/* ── Empty State ── */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-secondary);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state h3 { font-size: 1.1rem; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 0.9rem; }

/* ── Loading ── */
.loading {
  display: flex; align-items: center; justify-content: center;
  padding: 60px; color: var(--text-secondary);
}
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite; margin-right: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Callouts (Obsidian style) ── */
.callout {
  margin: 16px 0; padding: 0; border-radius: var(--radius-sm);
  border: 1px solid var(--border); overflow: hidden;
  background: var(--bg-card);
}
.callout-title {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; font-weight: 600; font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
  background: rgba(108, 92, 231, 0.06);
}
.callout-icon { font-size: 1rem; }
.callout-type { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); }
.callout-content { padding: 14px 16px; font-size: 0.92rem; line-height: 1.65; }
.callout-content p { margin: 6px 0; }
.callout-content strong { color: #fff; }
.callout-body { margin-top: 8px; }
.callout-body ul, .callout-body ol { margin: 8px 0 8px 20px; }
.callout-body li { margin: 4px 0; }
.callout-body table { margin: 8px 0; font-size: 0.85rem; }

.callout-note .callout-title { background: rgba(52, 152, 219, 0.1); }
.callout-note { border-left: 3px solid #3498db; }
.callout-tip .callout-title { background: rgba(0, 184, 148, 0.1); }
.callout-tip { border-left: 3px solid #00b894; }
.callout-info .callout-title { background: rgba(52, 152, 219, 0.1); }
.callout-info { border-left: 3px solid #3498db; }
.callout-important .callout-title { background: rgba(253, 203, 110, 0.1); }
.callout-important { border-left: 3px solid #fdcb6e; }
.callout-warning .callout-title { background: rgba(225, 112, 85, 0.1); }
.callout-warning { border-left: 3px solid #e17055; }
.callout-caution .callout-title { background: rgba(214, 48, 49, 0.1); }
.callout-caution { border-left: 3px solid #d63031; }
.callout-quote .callout-title { background: rgba(108, 92, 231, 0.1); }
.callout-quote { border-left: 3px solid #6c5ce7; font-style: italic; }
.callout-example .callout-title { background: rgba(0, 184, 148, 0.08); }
.callout-example { border-left: 3px solid #00b894; }
.callout-question .callout-title { background: rgba(162, 155, 254, 0.1); }
.callout-question { border-left: 3px solid #a29bfe; }
.callout-success .callout-title { background: rgba(0, 184, 148, 0.1); }
.callout-success { border-left: 3px solid #00b894; }
.callout-failure .callout-title { background: rgba(214, 48, 49, 0.1); }
.callout-failure { border-left: 3px solid #d63031; }
.callout-bug .callout-title { background: rgba(225, 112, 85, 0.1); }
.callout-bug { border-left: 3px solid #e17055; }
.callout-danger .callout-title { background: rgba(214, 48, 49, 0.12); }
.callout-danger { border-left: 3px solid #d63031; }
.callout-help .callout-title { background: rgba(52, 152, 219, 0.1); }
.callout-help { border-left: 3px solid #3498db; }
.callout-check .callout-title { background: rgba(0, 184, 148, 0.1); }
.callout-check { border-left: 3px solid #00b894; }
.callout-fact .callout-title { background: rgba(162, 155, 254, 0.1); }
.callout-fact { border-left: 3px solid #a29bfe; }
.callout-abstract .callout-title { background: rgba(52, 152, 219, 0.08); }
.callout-abstract { border-left: 3px solid #3498db; }
.callout-todo .callout-title { background: rgba(108, 92, 231, 0.1); }
.callout-todo { border-left: 3px solid #6c5ce7; }

/* ── Images (Obsidian style) ── */
.markdown-content img {
  max-width: 100%; border-radius: var(--radius-sm); margin: 16px 0;
  display: block; box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.markdown-content img[src*=".svg"] {
  background: #fff; padding: 8px; border-radius: var(--radius-sm);
  max-height: 600px; object-fit: contain;
}
.markdown-content img[style*="max-width:1054"],
.markdown-content img[style*="max-width:1059"],
.markdown-content img[style*="max-width:1416"] {
  margin: 20px auto; display: block;
}

/* ── Internal Links (Obsidian style) ── */
.internal-link {
  color: var(--accent-light) !important;
  text-decoration: none !important;
  border-bottom: 1px dashed var(--accent-light);
  cursor: pointer; transition: all 0.15s;
}
.internal-link:hover {
  color: #fff !important;
  border-bottom-color: #fff;
  background: var(--accent-glow);
  padding: 1px 4px; border-radius: 3px;
}

/* ── Task Lists (checkboxes) ── */
.markdown-content input[type="checkbox"] {
  margin-right: 8px; accent-color: var(--accent);
  transform: scale(1.15); vertical-align: middle;
}

/* ── Light Theme Overrides ── */
[data-theme="light"] .markdown-content strong { color: #1a1d27; }
[data-theme="light"] .markdown-content em { color: var(--accent-light); }
[data-theme="light"] .markdown-content img { box-shadow: 0 1px 4px rgba(0,0,0,0.1); }
[data-theme="light"] .markdown-content img[src*=".svg"] { background: #f5f6fa; }
[data-theme="light"] .markdown-content pre { background: #f0f1f5; border-color: #e1e4ea; }
[data-theme="light"] .markdown-content code { background: #f0f1f5; }
[data-theme="light"] .markdown-content th { background: #f5f6fa; }
[data-theme="light"] .internal-link:hover { color: var(--accent-light) !important; border-bottom-color: var(--accent-light); }
[data-theme="light"] .callout-content strong { color: #1a1d27; }
[data-theme="light"] .dashboard-header h1 {
  background: linear-gradient(135deg, #6c5ce7, #00b894);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

/* ── Mermaid Diagrams ── */
.mermaid {
  margin: 20px 0; padding: 16px; text-align: center;
  background: var(--bg-card); border-radius: var(--radius-sm);
  border: 1px solid var(--border); overflow-x: auto;
}
.mermaid svg { max-width: 100%; height: auto; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.5); }
  .content { margin-left: 0; padding: 24px 20px; }
  .menu-btn { display: block; }
  .topbar-center { margin: 0 16px; }
  .logo-text { display: none; }
  .subjects-grid { grid-template-columns: 1fr; }
}
