/* ============ 主题变量 ============ */
:root {
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --accent-soft: rgba(99,102,241,.15);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: .25s cubic-bezier(.4,0,.2,1);
  --font-sans: "Inter","PingFang SC","Microsoft YaHei",system-ui,sans-serif;
  --font-mono: "JetBrains Mono","Fira Code","Consolas",monospace;
}
[data-theme="dark"] {
  --bg: #0b0d12;
  --bg-elev: #13161f;
  --bg-elev-2: #1a1e29;
  --border: #252a38;
  --border-soft: #1e2230;
  --text: #e6e8ee;
  --text-muted: #8b92a7;
  --text-faint: #5b6278;
  --surface: #161922;
  --hover: #1f2330;
  --shadow: 0 10px 40px rgba(0,0,0,.5);
  --code-bg: #0f1219;
  --inline-code-bg: #1f2330;
}
[data-theme="light"] {
  --bg: #f7f8fa;
  --bg-elev: #ffffff;
  --bg-elev-2: #f1f2f6;
  --border: #e4e6ec;
  --border-soft: #eef0f4;
  --text: #1a1d29;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --surface: #ffffff;
  --hover: #f0f1f5;
  --shadow: 0 10px 40px rgba(0,0,0,.08);
  --code-bg: #f5f6f8;
  --inline-code-bg: #eef0f4;
}

/* ============ 基础重置 ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  transition: background var(--transition), color var(--transition);
  overflow: hidden;
  font-size: 14px;
  line-height: 1.6;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
::-webkit-scrollbar-track { background: transparent; }
::selection { background: var(--accent-soft); }

/* ============ 顶部导航 ============ */
.topbar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 12px var(--accent);
}
.brand h1 { font-size: 18px; font-weight: 700; letter-spacing: -.5px; }
.brand-sub {
  font-size: 12px; color: var(--text-muted);
  padding: 2px 8px; border: 1px solid var(--border);
  border-radius: 999px;
}
.topbar-actions { display: flex; align-items: center; gap: 12px; }

/* 移动端汉堡按钮：默认隐藏 */
.sidebar-toggle { display: none; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  width: 320px;
  height: 36px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-box svg { color: var(--text-faint); flex-shrink: 0; }
.search-box input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 13px;
}
.search-box input::placeholder { color: var(--text-faint); }
.search-box kbd {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text-faint); padding: 1px 6px;
  border: 1px solid var(--border); border-radius: 4px;
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px var(--accent-soft); }
.btn-ghost {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-faint); }

/* 主题切换图标 */
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* ============ 布局 ============ */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr 260px;
  height: calc(100vh - 60px);
}

/* ============ 左侧边栏 ============ */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  display: flex; gap: 8px; padding: 16px;
  border-bottom: 1px solid var(--border-soft);
}
.stat-pill {
  flex: 1; text-align: center;
  padding: 10px 4px; border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
}
.stat-num { display: block; font-size: 18px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text-faint); }

.filter-bar { padding: 12px 16px; border-bottom: 1px solid var(--border-soft); }
.tabs { display: flex; gap: 4px; background: var(--bg-elev-2); border-radius: var(--radius-sm); padding: 3px; }
.tab {
  flex: 1; padding: 6px 8px; font-size: 12px;
  border-radius: 6px; color: var(--text-muted);
  transition: all var(--transition);
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.2); }

.tag-cloud {
  padding: 12px 16px; display: flex; flex-wrap: wrap; gap: 6px;
  border-bottom: 1px solid var(--border-soft);
  max-height: 100px; overflow-y: auto;
}
.tag-chip {
  font-size: 11px; padding: 3px 10px;
  border-radius: 999px; cursor: pointer;
  background: var(--bg-elev-2); color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.tag-chip:hover { color: var(--text); border-color: var(--text-faint); }
.tag-chip.active {
  background: var(--accent-soft); color: var(--accent);
  border-color: var(--accent);
}

.solution-list {
  flex: 1; overflow-y: auto;
  padding: 8px;
}
.solution-item {
  display: block; padding: 12px 14px; margin-bottom: 4px;
  border-radius: var(--radius-sm); cursor: pointer;
  transition: all var(--transition);
  position: relative;
  animation: slideIn .3s ease backwards;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}
.solution-item:hover { background: var(--hover); }
.solution-item.active { background: var(--accent-soft); }
.solution-item.active::before {
  content: ""; position: absolute; left: 0; top: 12px; bottom: 12px;
  width: 3px; background: var(--accent); border-radius: 0 3px 3px 0;
}
.si-title {
  font-size: 13px; font-weight: 600; color: var(--text);
  margin-bottom: 4px; display: flex; align-items: center; gap: 6px;
}
.si-fav { color: #f59e0b; font-size: 12px; }
.si-meta {
  font-size: 11px; color: var(--text-faint);
  display: flex; align-items: center; gap: 8px;
}
.si-tags { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.si-tag {
  font-size: 10px; padding: 1px 7px; border-radius: 4px;
  background: var(--bg-elev-2); color: var(--text-muted);
}
.si-diff { padding: 1px 7px; border-radius: 4px; font-size: 10px; font-weight: 600; }
.cat-badge { background: rgba(99,102,241,.15); color: #818cf8; }
.diff-easy { background: rgba(34,197,94,.15); color: #22c55e; }
.diff-medium { background: rgba(234,179,8,.15); color: #eab308; }
.diff-hard { background: rgba(239,68,68,.15); color: #ef4444; }

.empty-hint {
  flex: 1; display: none;
  flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; color: var(--text-faint);
}
.empty-hint svg { margin-bottom: 12px; opacity: .5; }
.empty-hint p { font-size: 13px; margin-bottom: 4px; }
.empty-hint .hint-sub { font-size: 12px; color: var(--text-faint); margin-bottom: 16px; max-width: 200px; }
.solution-list:empty ~ .empty-hint { display: flex; }

/* ============ 阅读区 ============ */
.reader {
  overflow-y: auto;
  background: var(--bg);
  position: relative;
}
.doc {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 48px 80px;
}

/* 欢迎页 */
.welcome-hero {
  text-align: center; padding: 60px 0 40px;
}
.welcome-hero h2 {
  font-size: 36px; font-weight: 800; letter-spacing: -1px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 12px;
}
.welcome-hero p { color: var(--text-muted); font-size: 15px; max-width: 560px; margin: 0 auto; }
.features {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 16px; margin-top: 32px;
}
.feature {
  padding: 24px; border-radius: var(--radius);
  background: var(--bg-elev); border: 1px solid var(--border);
  transition: all var(--transition);
}
.feature:hover { border-color: var(--accent); transform: translateY(-2px); }
.f-num {
  font-family: var(--font-mono); font-size: 12px;
  color: var(--accent); font-weight: 700;
}
.feature h4 { font-size: 15px; margin: 6px 0 4px; }
.feature p { font-size: 12px; color: var(--text-muted); }

/* Markdown 内容样式 */
.md {
  font-size: 15px; line-height: 1.8;
  color: var(--text);
}
.md > *:first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4 {
  font-weight: 700; line-height: 1.3;
  margin: 1.8em 0 .6em;
  scroll-margin-top: 80px;
}
.md h1 { font-size: 28px; padding-bottom: .4em; border-bottom: 1px solid var(--border); }
.md h2 { font-size: 22px; padding-bottom: .3em; border-bottom: 1px solid var(--border-soft); }
.md h3 { font-size: 18px; }
.md h4 { font-size: 16px; }
.md p { margin: 1em 0; }
.md ul, .md ol { margin: 1em 0; padding-left: 1.6em; }
.md li { margin: .3em 0; }
.md a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-soft); }
.md a:hover { border-bottom-color: var(--accent); }
.md blockquote {
  margin: 1em 0; padding: .8em 1.2em;
  border-left: 4px solid var(--accent);
  background: var(--bg-elev-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted);
}
.md code {
  font-family: var(--font-mono); font-size: .9em;
  background: var(--inline-code-bg);
  padding: 2px 6px; border-radius: 4px;
  color: var(--accent-2);
}
.md pre {
  position: relative;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 16px 16px 52px;
  margin: 1.2em 0;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.6;
}
.md pre code {
  background: none; padding: 0; color: inherit;
  font-size: inherit;
}
/* 行号 */
.line-numbers {
  position: absolute; left: 0; top: 0;
  width: 40px; padding: 16px 8px 16px 0;
  text-align: right; color: var(--text-faint);
  font-family: var(--font-mono); font-size: 13px;
  user-select: none;
  border-right: 1px solid var(--border);
  line-height: 1.6;
}
/* 代码工具栏 */
.code-toolbar {
  position: absolute; top: 8px; right: 8px;
  display: flex; gap: 4px; opacity: 0;
  transition: opacity var(--transition);
}
.md pre:hover .code-toolbar { opacity: 1; }
.code-btn {
  padding: 4px 10px; font-size: 11px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text-muted);
  transition: all var(--transition);
}
.code-btn:hover { color: var(--text); border-color: var(--text-faint); }
.code-btn.copied { color: #22c55e; border-color: #22c55e; }

.md table {
  width: 100%; border-collapse: collapse;
  margin: 1.2em 0; font-size: 14px;
}
.md th, .md td {
  border: 1px solid var(--border);
  padding: 8px 12px; text-align: left;
}
.md th { background: var(--bg-elev-2); font-weight: 600; }
.md tr:nth-child(even) { background: var(--bg-elev-2); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.md img { max-width: 100%; border-radius: var(--radius-sm); }

/* 文章头部信息 */
.doc-header {
  margin-bottom: 32px; padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.doc-header h1 {
  font-size: 30px; font-weight: 800; letter-spacing: -.5px;
  margin-bottom: 12px; line-height: 1.25;
}
.doc-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  font-size: 13px; color: var(--text-muted);
}
.doc-meta .chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
}
.doc-date { color: var(--text-muted); font-size: 12px; }
.doc-actions { display: flex; gap: 8px; margin-top: 16px; }
.doc-actions .btn { height: 32px; font-size: 12px; }

/* 搜索高亮 */
mark { background: rgba(99,102,241,.3); color: inherit; border-radius: 2px; }

/* ============ 右侧目录 ============ */
.toc {
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  padding: 20px 16px;
  overflow-y: auto;
}
.toc-title {
  font-size: 12px; font-weight: 600;
  color: var(--text-faint); text-transform: uppercase;
  letter-spacing: .5px; margin-bottom: 16px;
}
.toc-list { list-style: none; }
.toc-list li { margin: 2px 0; }
.toc-link {
  display: block; padding: 5px 10px;
  font-size: 12px; color: var(--text-muted);
  border-left: 2px solid transparent;
  border-radius: 0 4px 4px 0;
  transition: all var(--transition);
  text-decoration: none;
}
.toc-link:hover { color: var(--text); background: var(--hover); }
.toc-link.active {
  color: var(--accent); border-left-color: var(--accent);
  background: var(--accent-soft);
}
.toc-level-3 { padding-left: 20px; font-size: 11px; }

/* ============ Toast ============ */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elev-2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 13px; z-index: 1000;
  opacity: 0; pointer-events: none;
  transition: all var(--transition);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ 响应式 ============ */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 280px 1fr; }
  .toc { display: none; }
}
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar-toggle { display: inline-flex; height: 36px; padding: 0 10px; }
  .sidebar {
    display: flex;
    position: fixed;
    left: 0; top: 60px; bottom: 0;
    width: 280px;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 60px 0 0 0;
    background: rgba(0,0,0,.5);
    z-index: 25;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
  }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
  .search-box { width: 160px; }
  .features { grid-template-columns: 1fr; }
  .doc { padding: 24px 20px 60px; }
  .ad-banner iframe { width: 100% !important; }
}

/* 桌面端隐藏遮罩 */
.sidebar-backdrop { display: none; }

/* 加载骨架 */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elev-2) 25%, var(--hover) 50%, var(--bg-elev-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============ 评论区 ============ */
.comments {
  margin-top: 56px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}
.comments-title {
  font-size: 1.4rem;
  margin-bottom: 20px;
  color: var(--text);
}
.twikoo {
  width: 100%;
}
.comments-hint {
  padding: 20px;
  background: var(--bg-elev-2);
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
}
.comments-hint code {
  background: var(--bg-elev);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
}
.comments-hint a {
  color: #818cf8;
  text-decoration: none;
}
.comments-hint a:hover {
  text-decoration: underline;
}
