@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --sidebar-width: 280px;
  --right-width: 260px;
  --header-height: 60px;
  --tab-height: 44px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

[data-theme="dark"] {
  --bg-primary: #0A0C10;     /* Deep sleek background */
  --bg-secondary: #121419;   /* Sidebar panels */
  --bg-tertiary: #1A1D24;    /* Hover and accents */
  --bg-hover: rgba(255,255,255,0.05);
  --bg-glass: rgba(10, 12, 16, 0.75);
  --text-primary: #F3F4F6;
  --text-secondary: #9CA3AF;
  --text-muted: #6B7280;
  --accent: #6366F1;         /* Indigo accent */
  --accent-hover: #818CF8;
  --accent-dim: rgba(99, 102, 241, 0.15);
  --border: #262932;
  --border-glass: rgba(255,255,255,0.08);
  --link: #818CF8;
  --link-hover: #A5B4FC;
  --callout-bg: rgba(255,255,255,0.03);
  --callout-tip: #34D399;
  --callout-warning: #FBBF24;
  --callout-danger: #F87171;
  --callout-info: #60A5FA;
  --highlight-bg: rgba(245, 158, 11, 0.2);
  --highlight-text: #FDE68A;
  --graph-link: #374151;
  --graph-node: #4B5563;
  --graph-node-stroke: #1F2937;
}

[data-theme="light"] {
  --bg-primary: #FFFFFF;
  --bg-secondary: #F8FAFC;
  --bg-tertiary: #F1F5F9;
  --bg-hover: rgba(0,0,0,0.04);
  --bg-glass: rgba(255, 255, 255, 0.8);
  --text-primary: #111827;
  --text-secondary: #4B5563;
  --text-muted: #9CA3AF;
  --accent: #4F46E5;
  --accent-hover: #4338CA;
  --accent-dim: rgba(79, 70, 229, 0.1);
  --border: #E5E7EB;
  --border-glass: rgba(0,0,0,0.06);
  --link: #4F46E5;
  --link-hover: #4338CA;
  --callout-bg: #F8FAFC;
  --callout-tip: #22C55E;
  --callout-warning: #F59E0B;
  --callout-danger: #EF4444;
  --callout-info: #3B82F6;
  --highlight-bg: rgba(245, 158, 11, 0.2);
  --highlight-text: #B45309;
  --graph-link: #CBD5E1;
  --graph-node: #94A3B8;
  --graph-node-stroke: #E2E8F0;
}

* { margin:0; padding:0; box-sizing:border-box; }
html { font-size:15px; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", sans-serif;
  background: var(--bg-primary); 
  color: var(--text-primary);
  line-height: 1.7; 
  overflow: hidden; 
  height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* HEADER */
.header {
  height: var(--header-height);
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-glass);
  display: flex; align-items: center; padding: 0 20px; gap: 16px;
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  box-shadow: var(--shadow-sm);
}
.header .logo { 
  font-weight: 700; font-size: 1.05rem; color: var(--text-primary); 
  white-space: nowrap; cursor: pointer; letter-spacing: 0.5px;
  display: flex; align-items: center; gap: 8px;
}
.header .logo svg { color: var(--accent); }
.header .nav-btns { display: flex; gap: 8px; }
.header .nav-btns button {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  color: var(--text-secondary); height: 32px; width: 32px;
  cursor: pointer; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.header .nav-btns button:hover:not(:disabled) { 
  background: var(--accent); color: #fff; border-color: var(--accent); 
  transform: translateY(-1px);
}
.header .nav-btns button:disabled { opacity: 0.3; cursor: not-allowed; }
.header .spacer { flex: 1; }
.source-link {
  display: flex; align-items: center; justify-content: center;
  height: 36px; width: 36px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg-tertiary);
  color: var(--text-secondary); text-decoration: none;
  transition: var(--transition);
}
.source-link:hover {
  background: var(--bg-hover); color: var(--accent);
}
.theme-toggle {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer;
  height: 36px; width: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.theme-toggle:hover { 
  background: var(--bg-hover); color: var(--accent); 
  transform: rotate(15deg);
}
.menu-toggle {
  display: none; background: none; border: none; color: var(--text-secondary);
  cursor: pointer; font-size: 1.4rem; padding: 4px;
}

/* TAB BAR */
.tab-bar {
  height: var(--tab-height); background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-end; overflow-x: auto; overflow-y: hidden;
  position: fixed; top: var(--header-height); left: var(--sidebar-width); right: 0; z-index: 99;
  padding: 0 12px; gap: 4px;
}
.tab-bar::-webkit-scrollbar { height: 0; }
.tab {
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px; font-size: 0.85rem; font-weight: 500; color: var(--text-muted);
  height: calc(var(--tab-height) - 6px);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  cursor: pointer; white-space: nowrap; min-width: 0; max-width: 220px;
  background: transparent; transition: var(--transition);
  position: relative; flex-shrink: 0; border: 1px solid transparent; border-bottom: none;
}
.tab:hover { background: var(--bg-hover); color: var(--text-secondary); }
.tab.active { 
  background: var(--bg-secondary); color: var(--text-primary); 
  border-color: var(--border); 
}
.tab.active::after {
  content:''; position: absolute; bottom: -1px; left: 0; right: 0;
  height: 2px; background: var(--accent); border-radius: 2px 2px 0 0;
}
.tab-label { overflow: hidden; text-overflow: ellipsis; }
.tab-close {
  display: flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  font-size: 12px; line-height: 1; color: var(--text-muted);
  background: none; border: none; cursor: pointer; flex-shrink: 0;
  opacity: 0; transition: var(--transition);
}
.tab:hover .tab-close, .tab.active .tab-close { opacity: 1; }
.tab-close:hover { background: var(--callout-danger); color: #fff; }
.tab-icon { font-size: 0.8rem; flex-shrink: 0; display: flex; align-items: center; }

/* LAYOUT */
.app {
  display: flex; position: fixed;
  top: calc(var(--header-height) + var(--tab-height));
  left: 0; right: 0; bottom: 0;
}

/* LEFT SIDEBAR */
.sidebar-left {
  width: var(--sidebar-width); min-width: var(--sidebar-width);
  background: var(--bg-secondary); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 1px 0 10px rgba(0,0,0,0.02);
}
.search-box { padding: 16px; border-bottom: 1px solid var(--border); }
.search-box input {
  width: 100%; background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 8px 12px 8px 36px; color: var(--text-primary);
  font-size: 0.9rem; outline: none; transition: var(--transition);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='7.5' cy='7.5' r='5.5'/%3E%3Cpath d='M15 15l-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 12px center;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.search-box input::placeholder { color: var(--text-muted); }
.note-list { flex: 1; overflow-y: auto; padding: 12px 8px; }
.note-list::-webkit-scrollbar { width: 4px; }
.note-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.note-list-item {
  padding: 8px 12px; cursor: pointer; font-size: 0.9rem; font-weight: 500;
  color: var(--text-secondary); border-radius: var(--radius-md); transition: var(--transition);
  margin-bottom: 2px; display: flex; align-items: center;
}
.note-list-item:hover { background: var(--bg-hover); color: var(--text-primary); transform: translateX(2px); }
.note-list-item.active { background: var(--accent-dim); color: var(--accent); }
.note-list-item .note-num { color: var(--text-muted); margin-right: 8px; font-size: 0.75rem; background: var(--bg-tertiary); padding: 2px 6px; border-radius: 10px; }
.search-results { padding: 12px; overflow-y: auto; flex: 1; }
.search-result-item { padding: 12px; cursor: pointer; border-radius: var(--radius-md); margin-bottom: 8px; background: var(--bg-primary); border: 1px solid var(--border); transition: var(--transition); }
.search-result-item:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.search-result-item .sr-title { color: var(--accent); font-weight: 600; margin-bottom: 4px; font-size: 0.9rem; }
.search-result-item .sr-preview { color: var(--text-muted); font-size: 0.8rem; line-height: 1.5; }
.search-result-item .sr-preview mark { background: var(--highlight-bg); color: var(--highlight-text); padding: 0 2px; border-radius: 2px; }

/* MAIN PANELS */
.main-area { flex: 1; position: relative; overflow: hidden; background: var(--bg-primary); }
.panel { position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: none; opacity: 0; transition: opacity 0.3s ease; }
.panel.active { display: block; opacity: 1; }

.panel-graph { background: radial-gradient(circle at center, var(--bg-tertiary) 0%, var(--bg-primary) 100%); }
.panel-graph svg { width: 100%; height: 100%; cursor: grab; }
.panel-graph svg:active { cursor: grabbing; }

.panel-article { overflow-y: auto; padding: 48px 64px; scroll-behavior: smooth; }
.panel-article::-webkit-scrollbar { width: 8px; }
.panel-article::-webkit-scrollbar-track { background: transparent; }
.panel-article::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* RIGHT SIDEBAR */
.sidebar-right {
  width: var(--right-width); min-width: var(--right-width);
  background: var(--bg-secondary); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 24px 0;
}
.sidebar-right::-webkit-scrollbar { width: 4px; }
.sidebar-right::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.right-section { padding: 0 20px; margin-bottom: 32px; }
.right-section-title { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); letter-spacing: 1px; margin-bottom: 12px; }
.toc-item { display: block; padding: 4px 8px; margin-bottom: 2px; font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); cursor: pointer; transition: var(--transition); border-radius: var(--radius-sm); border-left: 2px solid transparent; }
.toc-item:hover { color: var(--text-primary); background: var(--bg-hover); }
.toc-item.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-dim); }
.toc-item.toc-h2 { margin-left: 0; }
.toc-item.toc-h3 { margin-left: 12px; font-size: 0.8rem; }
.toc-item.toc-h4 { margin-left: 24px; font-size: 0.75rem; }
.backlink-item { display: block; padding: 8px 12px; font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); cursor: pointer; border-radius: var(--radius-md); margin-bottom: 6px; background: var(--bg-primary); border: 1px solid var(--border); transition: var(--transition); }
.backlink-item:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow-sm); }

/* ARTICLE */
.article {
  max-width: 860px; margin: 0 auto;
}
.article-meta { margin-bottom: 32px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.article-meta .tags { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.article-meta .tag { background: var(--bg-tertiary); border: 1px solid var(--border); color: var(--text-secondary); padding: 4px 12px; border-radius: 20px; font-size: 0.8rem; font-weight: 500; transition: var(--transition); }
.article-meta .tag:hover { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

.article h1 { font-size: 2.2rem; font-weight: 800; margin: 0 0 16px; line-height: 1.25; color: var(--text-primary); letter-spacing: -0.5px; }
.article h2 { font-size: 1.5rem; font-weight: 700; margin: 40px 0 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); color: var(--text-primary); letter-spacing: -0.3px; }
.article h3 { font-size: 1.2rem; font-weight: 600; margin: 32px 0 12px; color: var(--text-primary); }
.article h4 { font-size: 1.05rem; font-weight: 600; margin: 24px 0 8px; color: var(--text-primary); }
.article p { margin: 0 0 16px; color: var(--text-secondary); }
.article a { color: var(--link); text-decoration: none; font-weight: 500; transition: var(--transition); }
.article a:hover { color: var(--link-hover); text-decoration: underline; text-underline-offset: 4px; }
.article a.wikilink { color: var(--accent); background: var(--accent-dim); padding: 2px 8px; border-radius: var(--radius-sm); font-weight: 600; border: 1px solid transparent; }
.article a.wikilink:hover { background: var(--accent); color: #fff; text-decoration: none; box-shadow: 0 0 12px var(--accent-dim); }
.article strong { font-weight: 700; color: var(--text-primary); }
.article mark { background: var(--highlight-bg); color: var(--highlight-text); padding: 2px 6px; border-radius: 4px; }
.article blockquote { border-left: 4px solid var(--accent); padding: 12px 20px; margin: 20px 0; background: var(--bg-tertiary); border-radius: 0 var(--radius-md) var(--radius-md) 0; color: var(--text-secondary); font-style: italic; }
.article ul, .article ol { padding-left: 28px; margin: 16px 0; color: var(--text-secondary); }
.article li { margin: 6px 0; }
.article li::marker { color: var(--text-muted); }
.article hr { border: none; border-top: 1px solid var(--border); margin: 32px 0; }
.article table { width: 100%; border-collapse: separate; border-spacing: 0; margin: 24px 0; font-size: 0.95rem; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.article th, .article td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); color: var(--text-secondary); }
.article th { background: var(--bg-tertiary); font-weight: 600; color: var(--text-primary); border-bottom: 2px solid var(--border); }
.article tr:last-child td { border-bottom: none; }
.article code { font-family: "JetBrains Mono", Consolas, Monaco, monospace; background: var(--bg-tertiary); color: var(--text-primary); padding: 3px 6px; border-radius: 4px; font-size: 0.85em; border: 1px solid var(--border); }
.article pre { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; margin: 20px 0; overflow-x: auto; font-size: 0.9rem; line-height: 1.6; box-shadow: inset 0 2px 4px rgba(0,0,0,0.02); }
.article pre code { background: none; padding: 0; border: none; color: inherit; font-size: 0.9em; }

/* CALLOUTS */
.callout { border-radius: var(--radius-lg); padding: 16px 20px; margin: 20px 0; border: 1px solid; border-left-width: 4px; background: var(--callout-bg); box-shadow: var(--shadow-sm); }
.callout-title { font-weight: 700; font-size: 1rem; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.callout-content { font-size: 0.95rem; color: var(--text-secondary); }
.callout-content p:last-child { margin-bottom: 0; }
.callout-tip, .callout-hint { border-color: var(--callout-tip); }
.callout-tip .callout-title, .callout-hint .callout-title { color: var(--callout-tip); }
.callout-warning, .callout-caution { border-color: var(--callout-warning); }
.callout-warning .callout-title, .callout-caution .callout-title { color: var(--callout-warning); }
.callout-danger { border-color: var(--callout-danger); }
.callout-danger .callout-title { color: var(--callout-danger); }
.callout-info { border-color: var(--callout-info); }
.callout-info .callout-title { color: var(--callout-info); }
.callout-abstract, .callout-summary { border-color: var(--accent); }
.callout-abstract .callout-title, .callout-summary .callout-title { color: var(--accent); }

/* MERMAID */
.mermaid-container { margin: 24px 0; padding: 24px; background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow-x: auto; text-align: center; box-shadow: var(--shadow-sm); }

/* GRAPH */
.graph-node circle { cursor: pointer; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1)); }
.graph-node text { fill: var(--text-secondary); font-size: 12px; font-weight: 500; pointer-events: none; text-anchor: middle; transition: all 0.3s; }
.graph-link { stroke: var(--graph-link); stroke-width: 1.5; transition: all 0.3s; }
.graph-node.highlighted circle { r: 14; filter: drop-shadow(0 0 8px var(--accent-dim)); }
.graph-node.highlighted text { fill: var(--text-primary); font-weight: 700; font-size: 13px; }
.graph-node.dimmed circle { opacity: 0.15; }
.graph-node.dimmed text { opacity: 0.15; }
.graph-link.dimmed { opacity: 0.05; }
.graph-link.highlighted { stroke: var(--accent); stroke-width: 2.5; filter: drop-shadow(0 0 4px var(--accent-dim)); }

/* LOADING */
.loading-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); gap: 20px; font-weight: 500; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s cubic-bezier(0.4, 0, 0.2, 1) infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* RELATED NOTES */
.related-notes { margin-top: 48px; padding-top: 32px; border-top: 1px solid var(--border); }
.related-notes-title { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 16px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.related-notes-list { display: flex; flex-wrap: wrap; gap: 10px; }
.related-note-chip { background: var(--bg-primary); border: 1px solid var(--border); color: var(--text-secondary); padding: 8px 16px; border-radius: 24px; font-size: 0.85rem; font-weight: 500; cursor: pointer; transition: var(--transition); box-shadow: var(--shadow-sm); text-decoration: none; }
.related-note-chip:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-md); }

/* Star Toast */
.star-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 16px;
  box-shadow: var(--shadow-md);
  font-size: .88rem; color: var(--text-primary);
  z-index: 9999; opacity: 0;
  transition: opacity .3s, transform .3s;
  white-space: nowrap;
}
.star-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.star-toast.hiding  { opacity: 0; transform: translateX(-50%) translateY(10px); }
.star-toast-btn {
  padding: 5px 14px; border-radius: 6px;
  background: var(--accent); color: #fff;
  text-decoration: none; font-size: .82rem; font-weight: 600;
  transition: filter .2s;
}
.star-toast-btn:hover { filter: brightness(1.15); }
.star-toast-close {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 1.1rem; line-height: 1;
  padding: 0 2px; transition: color .2s;
}
.star-toast-close:hover { color: var(--text-primary); }

.note-attribution {
  margin-top: 32px; padding-top: 20px;
  border-top: 1px dashed var(--border);
  font-size: .78rem; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
}
.note-attribution a {
  color: var(--text-muted); text-decoration: none;
  transition: color .2s;
}
.note-attribution a:hover { color: var(--accent); }

/* RESPONSIVE */
@media(max-width: 1024px) { 
  .sidebar-right { display: none; } 
  .article { max-width: 100%; }
}
@media(max-width: 768px) {
  .menu-toggle { display: block; }
  .sidebar-left { position: fixed; top: var(--header-height); left: 0; bottom: 0; z-index: 40; transform: translateX(-100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); box-shadow: none; }
  .sidebar-left.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.1); }
  .sidebar-overlay { position: fixed; top: var(--header-height); left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(2px); z-index: 39; display: none; opacity: 0; transition: opacity 0.3s; }
  .sidebar-overlay.visible { display: block; opacity: 1; }
  .tab-bar { left: 0; }
  .panel-article { padding: 24px 20px 32px; }
}
