body{font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;margin:0;background:#f7f7f7;color:#222;transition:background .2s,color .2s}
.topbar{display:flex;justify-content:space-between;gap:12px;align-items:center;padding:12px 18px;background:#111;color:#fff}
.brand{color:#fff;text-decoration:none;font-weight:700;font-size:18px}
.top-right{display:flex;gap:10px;align-items:center}
.theme-btn{padding:8px 12px;border:1px solid rgba(255,255,255,.3);border-radius:8px;background:#1d1d1d;color:#fff;cursor:pointer}
.search-form{display:flex;gap:8px}
.search-form input{padding:8px 10px;min-width:220px;border:1px solid #ccc;border-radius:8px;background:#fff;color:#222}
.search-form button{padding:8px 12px;border:0;border-radius:8px;background:#2d6cdf;color:#fff}
.container{max-width:1160px;margin:20px auto;padding:0 16px}
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:12px}
.card{background:#fff;padding:14px;border-radius:10px;text-decoration:none;color:inherit;box-shadow:0 1px 3px rgba(0,0,0,.08)}
.card:hover{box-shadow:0 4px 16px rgba(0,0,0,.12)}
.chapters li{margin:6px 0}
.chapters.cols{columns:2;column-gap:28px}
.chapters.cols li{break-inside:avoid}
.content{background:#fff;padding:20px;border-radius:12px;line-height:2;font-size:18px;box-shadow:0 1px 3px rgba(0,0,0,.08)}
.pager{display:flex;justify-content:space-between;align-items:center;gap:12px;margin-top:14px}
.search-results li{margin-bottom:12px;background:#fff;padding:10px;border-radius:8px}
.crumb{margin-bottom:10px;color:#666}

.chapter-layout{display:grid;grid-template-columns:320px 1fr;gap:16px;align-items:start}
.chapter-side{position:sticky;top:10px;align-self:start;background:#fff;border-radius:12px;padding:12px;max-height:calc(100vh - 30px);overflow:auto;box-shadow:0 1px 3px rgba(0,0,0,.08)}
.side-head{position:sticky;top:0;background:#fff;padding-bottom:6px;z-index:2;display:flex;justify-content:space-between;align-items:center;gap:8px}
.chapter-side h3{margin:0}
.side-toggle{border:0;background:#2d6cdf;color:#fff;border-radius:8px;padding:6px 10px;cursor:pointer}
.meta{position:sticky;top:34px;background:#fff;margin:0;padding:6px 0;z-index:1;color:#666;font-size:13px}
.progress-wrap{position:sticky;top:58px;background:#eee;height:8px;border-radius:999px;overflow:hidden;margin-bottom:10px;z-index:1}
.progress{height:100%;background:#2d6cdf}
.chapter-side-list{display:flex;flex-direction:column;gap:6px}
.chapter-side-item{font-size:13px;color:#333;text-decoration:none;padding:6px 8px;border-radius:8px}
.chapter-side-item:hover{background:#f1f5ff}
.chapter-side-item.active{background:#2d6cdf;color:#fff}

body.dark{background:#0f1115;color:#e8ecf3}
body.dark .card, body.dark .content, body.dark .search-results li, body.dark .chapter-side, body.dark .side-head, body.dark .meta{background:#171a21;color:#e8ecf3;box-shadow:none;border:1px solid #2a2f3a}
body.dark .search-form input{background:#11141a;color:#e8ecf3;border-color:#2a2f3a}
body.dark .crumb{color:#aeb7c8}
body.dark a{color:#9fc2ff}
body.dark .chapter-side-item{color:#d6deed}
body.dark .chapter-side-item:hover{background:#232a36}
body.dark .progress-wrap{background:#2a2f3a}
body.dark .theme-btn{background:#2a2f3a;border-color:#3a4252}

@media (max-width: 900px){
  .chapter-layout{grid-template-columns:1fr}
  .chapter-side{position:relative;top:auto;max-height:320px}
  .side-head,.meta,.progress-wrap{position:static}
  .chapters.cols{columns:1}
  .content{font-size:17px;line-height:1.9}
}
@media (max-width: 640px){
  .topbar{flex-wrap:wrap}
  .top-right{width:100%;justify-content:space-between}
  .search-form{width:100%}
  .search-form input{min-width:0;flex:1}
  .content{font-size:16px;line-height:1.85;padding:14px}
}
