/* ============================================================
   耕读小筑 —— 沿用 mycool 博客「诗页」风格（暖纸 + 思源宋体）
   布局：顶栏 + 左侧书架/章节树 + 右侧内容
   ============================================================ */

:root {
  --bg: oklch(0.978 0.012 95);
  --text: oklch(0.38 0.018 70);
  --ink-soft: oklch(0.52 0.016 70);
  --muted: oklch(0.64 0.013 70);
  --line: oklch(0.93 0.010 92);
  --brand: oklch(0.58 0.055 250);
  --brand-soft: oklch(0.95 0.022 250);
  --code-bg: oklch(0.30 0.012 85);
  --code-fg: oklch(0.96 0.005 95);
  --code-inline-bg: oklch(0.94 0.008 92);
  --th-bg: oklch(0.96 0.010 95);
  --serif: "Noto Serif SC", "Songti SC", "STSong", Georgia, serif;
  --sans: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --measure: 44em;
  --sidebar-w: 16rem;
  --outline-w: 13rem;
}

*, *::before, *::after { box-sizing: border-box; transition: background-color .25s ease, border-color .25s ease, color .25s ease; }
html { -webkit-font-smoothing: antialiased; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); line-height: 1.75; font-size: 16px; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--brand-soft); color: var(--text); }
.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 15px 22px; background: color-mix(in oklch, var(--bg) 86%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar .brand { font-family: var(--serif); font-weight: 700; font-size: 18px; color: var(--text); }
.topbar .brand .brand-icon { display: inline-block; width: 22px; height: 22px; margin-right: 7px; vertical-align: -5px; background-color: currentColor; -webkit-mask: url("/logo.svg") center / contain no-repeat; mask: url("/logo.svg") center / contain no-repeat; }
.topbar .brand:hover { text-decoration: none; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.cur-book { color: var(--muted); font-size: 13px; }
.menu-btn { display: none; border: 1px solid var(--line); background: transparent; color: var(--ink-soft); padding: 6px 12px; border-radius: 8px; font: inherit; font-size: 13px; cursor: pointer; }

/* ---------- 布局 ---------- */
.layout { display: flex; align-items: flex-start; }
.sidebar { position: sticky; top: 58px; width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); max-height: calc(100vh - 58px); overflow-y: auto; padding: 22px 16px 40px; border-right: 1px solid var(--line); }
.content { flex: 1 1 auto; min-width: 0; padding: 4vh 36px 16vh; }
.scrim { display: none; }

/* 右侧本页大纲（悬浮） */
.outline { position: sticky; top: 58px; align-self: flex-start; width: var(--outline-w); flex: 0 0 var(--outline-w); max-height: calc(100vh - 58px); overflow-y: auto; padding: 26px 14px 40px; }
.outline-title { font-size: 11px; letter-spacing: 2px; color: var(--muted); margin-bottom: 12px; font-weight: 600; }
#outline-nav a { display: block; font-size: 13px; line-height: 1.55; color: var(--muted); padding: 4px 0 4px 12px; margin-left: -1px; border-left: 1px solid var(--line); transition: .15s; }
#outline-nav a.lvl-h3 { padding-left: 24px; font-size: 12.5px; }
#outline-nav a:hover { color: var(--brand); text-decoration: none; }
#outline-nav a.active { color: var(--brand); font-weight: 600; border-left-color: var(--brand); }

/* ---------- 书架（首页） ---------- */
.bookshelf { width: 100%; max-width: var(--measure); margin: 0 auto; }
/* 首页不显示右侧大纲；把那一列的宽度留出来，让书架与课文页落在同一视觉中线 */
@media (min-width: 1181px) { .content.gutter { padding-right: calc(36px + var(--outline-w)); } }
.bookshelf .lead { font-family: var(--serif); font-size: clamp(20px, 3vw, 28px); font-weight: 700; line-height: 1.5; margin: 2vh 0 6vh; text-align: center; color: var(--text); }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 18px; }
.book-card { display: block; color: inherit; text-decoration: none; padding: 22px 24px; border-radius: 14px; background: transparent; border: 1px solid var(--line); transition: .18s; }
.book-card:hover { text-decoration: none; background: color-mix(in oklch, var(--bg) 82%, var(--brand) 6%); border-color: color-mix(in oklch, var(--brand) 30%, transparent); transform: translateY(-2px); box-shadow: 0 8px 22px rgba(20,30,28,.06); }
.book-card h2 { font-family: var(--serif); font-weight: 700; font-size: 22px; margin: 0 0 8px; color: var(--text); }
.book-card .sub { color: var(--ink-soft); font-size: 14px; line-height: 1.7; }
.book-card .tag { display: inline-block; margin-top: 12px; font-size: 12px; padding: 3px 11px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }

/* ---------- 侧栏：书架切换 + 章节树 ---------- */
.shelf { display: flex; flex-direction: column; gap: 4px; margin-bottom: 18px; }
.shelf .shelf-item { font-family: var(--serif); font-weight: 700; font-size: 15px; padding: 7px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; }
.shelf .shelf-item:hover { color: var(--brand); background: var(--brand-soft); text-decoration: none; }
.shelf .shelf-item.active { color: var(--brand); background: var(--brand-soft); }

.tree .stage { margin-bottom: 14px; }
.tree .stage-title { font-size: 12px; font-weight: 700; letter-spacing: 1px; color: var(--muted); padding: 4px 12px; margin: 0; }
.tree .lesson-link { display: block; font-size: 13.5px; line-height: 1.5; color: var(--ink-soft); padding: 5px 12px 5px 16px; border-left: 2px solid var(--line); margin-left: 6px; }
.tree .lesson-link:hover { color: var(--brand); text-decoration: none; border-left-color: color-mix(in oklch, var(--brand) 40%, transparent); }
.tree .lesson-link.active { color: var(--brand); font-weight: 600; border-left-color: var(--brand); background: color-mix(in oklch, var(--brand-soft) 60%, transparent); }

/* ---------- 课文 ---------- */
.lesson { width: 100%; max-width: var(--measure); margin: 0 auto; }
.lesson-head { margin-bottom: 30px; }
.crumb { font-size: 12.5px; color: var(--muted); letter-spacing: .3px; margin-bottom: 10px; }
.crumb a { color: var(--muted); }
.lesson h1 { font-family: var(--serif); font-weight: 700; font-size: clamp(25px, 3.2vw, 32px); line-height: 1.35; margin: 0; }
.lesson-body { font-family: var(--serif); font-size: 17px; line-height: 1.95; color: var(--text); }
.lesson-body > *:first-child { margin-top: 0; }
.lesson-body p { margin: 1.1em 0; }
.lesson-body h2 { font-family: var(--serif); font-size: 22px; line-height: 1.4; margin: 1.8em 0 .6em; padding-bottom: .3em; border-bottom: 1px solid var(--line); }
.lesson-body h3 { font-family: var(--serif); font-size: 19px; margin: 1.5em 0 .5em; }
.lesson-body ul, .lesson-body ol { margin: 1.1em 0; padding-left: 1.6em; }
.lesson-body li { margin: .45em 0; }
.lesson-body blockquote { margin: 1.4em 0; padding: 6px 0 6px 18px; border-left: 3px solid var(--line); color: var(--ink-soft); font-style: italic; }
.lesson-body pre { background: var(--code-bg); color: var(--code-fg); padding: 16px; border-radius: 8px; overflow: auto; font-size: 14px; }
.lesson-body code { background: var(--code-inline-bg); padding: 2px 6px; border-radius: 5px; font-size: .9em; }
.lesson-body pre code { background: transparent; padding: 0; color: inherit; }
.lesson-body img { max-width: 100%; border-radius: 8px; margin: 20px 0; }
.lesson-body hr { border: none; border-top: 1px solid var(--line); margin: 2.4em 0; }
.lesson-body table { border-collapse: collapse; width: 100%; margin: 1.5em 0; font-size: 15px; }
.lesson-body th, .lesson-body td { border: 1px solid var(--line); padding: 9px 12px; text-align: left; }
.lesson-body th { background: var(--th-bg); }
.lesson-body .tip { background: var(--brand-soft); border-radius: 10px; padding: 14px 18px; margin: 1.4em 0; color: var(--text); font-style: normal; border-left: 3px solid var(--brand); }

/* 答案折叠 */
.answer { margin: .4em 0 .2em; }
.answer > summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; font-family: var(--sans); font-size: 13.5px; font-weight: 600; color: var(--brand); background: var(--brand-soft); padding: 5px 13px; border-radius: 999px; width: fit-content; }
.answer > summary::-webkit-details-marker { display: none; }
.answer > summary::before { content: "▸"; transition: transform .15s; }
.answer[open] > summary::before { transform: rotate(90deg); }
.answer > .answer-body { margin: 10px 0 10px 2px; padding: 10px 16px; border-radius: 8px; background: color-mix(in oklch, var(--brand-soft) 50%, var(--bg)); color: var(--ink-soft); font-style: normal; }
.answer > .answer-body p { margin: .4em 0; }

/* 上一篇 / 下一篇 */
.lesson-nav { display: flex; justify-content: space-between; gap: 16px; margin-top: 8vh; padding-top: 24px; border-top: 1px solid var(--line); }
.ln-item { display: flex; flex-direction: column; gap: 5px; text-decoration: none; color: inherit; min-width: 0; }
.ln-item.next { text-align: right; margin-left: auto; }
.ln-item .ln-label { font-size: 12px; letter-spacing: 1px; color: var(--muted); }
.ln-item .ln-title { font-family: var(--serif); font-size: 15px; line-height: 1.5; color: var(--ink-soft); }
.ln-item:hover .ln-title { color: var(--brand); text-decoration: none; }
.ln-item.disabled { visibility: hidden; }

/* ---------- 响应式 ---------- */
@media (max-width: 1180px) {
  .outline { display: none !important; }
}
@media (max-width: 860px) {
  .menu-btn { display: inline-block; }
  .sidebar { position: fixed; top: 58px; left: 0; z-index: 45; background: var(--bg); transform: translateX(-100%); transition: transform .25s ease; box-shadow: 0 0 40px rgba(0,0,0,.12); }
  .sidebar.open { transform: translateX(0); }
  .scrim.show { display: block; position: fixed; inset: 58px 0 0 0; background: rgba(0,0,0,.25); z-index: 44; }
  .content { padding: 4vh 20px 14vh; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  html { scroll-behavior: auto; }
}
