:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #f1f4f9;
  --text: #172033;
  --muted: #667085;
  --line: #e4e7ec;
  --brand: #2563eb;
  --brand-2: #1d4ed8;
  --code-bg: #111827;
  --code-text: #e5e7eb;
  --shadow: 0 18px 60px rgba(15, 23, 42, .08);
}

:root.dark {
  color-scheme: dark;
  --bg: #0b1020;
  --panel: #111827;
  --panel-2: #182235;
  --text: #edf2ff;
  --muted: #9aa8bf;
  --line: #263244;
  --brand: #60a5fa;
  --brand-2: #93c5fd;
  --code-bg: #050816;
  --code-text: #dbeafe;
  --shadow: 0 18px 60px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 320px minmax(0, 1fr) 240px; gap: 0; }
.sidebar, .toc-panel { position: sticky; top: 0; height: 100vh; overflow: auto; background: var(--panel); border-right: 1px solid var(--line); }
.toc-panel { border-right: 0; border-left: 1px solid var(--line); padding: 24px 18px; }
.brand { display: flex; gap: 12px; align-items: center; padding: 22px; border-bottom: 1px solid var(--line); }
.logo { width: 42px; height: 42px; display: grid; place-items: center; color: #fff; font-weight: 800; border-radius: 14px; background: linear-gradient(135deg, var(--brand), #7c3aed); }
.brand span { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; }
.search-box { display: block; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.search-box span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.search-box input { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; background: var(--panel-2); color: var(--text); outline: none; }
.search-box input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
.lesson-nav { padding: 10px 12px 24px; }
.nav-section { margin: 14px 10px 8px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.lesson-link { display: flex; gap: 10px; align-items: flex-start; width: 100%; border: 0; color: var(--text); background: transparent; text-align: left; border-radius: 12px; padding: 10px 10px; cursor: pointer; }
.lesson-link:hover { background: var(--panel-2); }
.lesson-link.active { background: rgba(37, 99, 235, .12); color: var(--brand-2); font-weight: 700; }
.lesson-link .day { flex: 0 0 auto; font-size: 12px; color: var(--muted); min-width: 48px; }
.lesson-link .name { line-height: 1.35; }

.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; height: 64px; display: flex; align-items: center; gap: 16px; padding: 0 28px; background: rgba(246, 247, 251, .82); backdrop-filter: blur(16px); border-bottom: 1px solid var(--line); }
:root.dark .topbar { background: rgba(11, 16, 32, .82); }
.ghost-btn, .primary-btn { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; cursor: pointer; font-weight: 700; background: var(--panel); color: var(--text); }
.primary-btn { border-color: var(--brand); background: var(--brand); color: white; }
.ghost-btn:hover, .primary-btn:hover { transform: translateY(-1px); }
.progress { flex: 1; min-width: 140px; color: var(--muted); font-size: 13px; }
.progress div { margin-top: 8px; height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), #7c3aed); border-radius: inherit; transition: width .25s ease; }

.reader { width: min(920px, calc(100% - 48px)); margin: 34px auto 80px; background: var(--panel); border: 1px solid var(--line); border-radius: 26px; box-shadow: var(--shadow); overflow: hidden; }
.reader-head { display: flex; justify-content: space-between; gap: 24px; padding: 34px 38px 24px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, rgba(37, 99, 235, .07), transparent); }
.reader-head h1 { margin: 6px 0 0; font-size: clamp(26px, 4vw, 42px); line-height: 1.15; letter-spacing: -.03em; }
.eyebrow { margin: 0; color: var(--brand); font-weight: 800; font-size: 13px; }
.reader-actions { display: flex; align-items: flex-start; gap: 10px; white-space: nowrap; }
.content { padding: 18px 38px 46px; font-size: 17px; line-height: 1.85; }
.content h1, .content h2, .content h3, .content h4 { scroll-margin-top: 86px; line-height: 1.28; letter-spacing: -.02em; }
.content h1 { display: none; }
.content h2 { margin-top: 36px; padding-top: 10px; font-size: 28px; border-top: 1px solid var(--line); }
.content h3 { margin-top: 28px; font-size: 22px; }
.content p { margin: 14px 0; }
.content ul, .content ol { padding-left: 1.4em; }
.content li { margin: 6px 0; }
.content blockquote { margin: 22px 0; padding: 14px 18px; border-left: 4px solid var(--brand); background: var(--panel-2); border-radius: 0 14px 14px 0; color: var(--muted); }
.content code { padding: .16em .38em; border-radius: 7px; background: var(--panel-2); color: #b45309; font-size: .92em; }
:root.dark .content code { color: #fbbf24; }
.code-block { margin: 22px 0; border-radius: 18px; overflow: hidden; background: var(--code-bg); box-shadow: 0 14px 34px rgba(0,0,0,.12); }
.code-block figcaption { display: flex; justify-content: space-between; align-items: center; min-height: 38px; padding: 8px 12px; color: #9ca3af; background: rgba(255,255,255,.06); font-size: 13px; }
.copy-code { border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); color: #e5e7eb; border-radius: 9px; padding: 5px 9px; cursor: pointer; }
.code-block pre { margin: 0; padding: 18px; overflow: auto; }
.code-block code { padding: 0; background: transparent; color: var(--code-text); font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 14px; line-height: 1.7; }
.table-wrap { overflow: auto; margin: 22px 0; border: 1px solid var(--line); border-radius: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 11px 13px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: var(--panel-2); }
.anchor { opacity: 0; margin-right: 8px; font-size: .8em; }
h2:hover .anchor, h3:hover .anchor, h4:hover .anchor { opacity: 1; }

.toc-panel strong { display: block; margin-bottom: 12px; }
.toc-panel a, .mobile-toc a { display: block; padding: 7px 0; color: var(--muted); font-size: 14px; line-height: 1.35; }
.toc-panel a:hover, .toc-panel a.active { color: var(--brand); text-decoration: none; }
.toc-panel .level-3 { padding-left: 14px; font-size: 13px; }
.mobile-toc { display: none; padding: 14px 22px; border-bottom: 1px solid var(--line); background: var(--panel-2); }

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 300px minmax(0, 1fr); }
  .toc-panel { display: none; }
  .mobile-toc { display: block; }
}
@media (max-width: 780px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 20; inset: 0 auto 0 0; width: min(86vw, 340px); transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .reader { width: calc(100% - 24px); margin-top: 18px; border-radius: 18px; }
  .reader-head { display: block; padding: 24px 22px 18px; }
  .reader-actions { margin-top: 18px; }
  .content { padding: 14px 22px 36px; font-size: 16px; }
  .topbar { padding: 0 12px; }
}
