/* layout.css — 应用外壳：顶栏、侧栏目录、正文、底部导航、抽屉 */
.app-header {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: var(--s3);
  background: var(--bg-raise);
  border-bottom: 1px solid var(--line);
  padding: 0 var(--s4);
  padding-left: calc(var(--s4) + env(safe-area-inset-left));
  padding-right: calc(var(--s4) + env(safe-area-inset-right));
  height: 52px;
}
.app-header .brand { font-weight: 650; font-size: 15px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-header .spacer { flex: 1; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px;
  background: none; border: 0; border-radius: var(--radius);
  color: var(--ink); cursor: pointer; font-size: 18px;
}
.icon-btn:hover { background: var(--bg-sunk); }

.app-body { display: flex; min-height: calc(100vh - 52px); }

/* 侧栏目录（桌面） */
.toc {
  width: 280px; flex: none;
  border-right: 1px solid var(--line);
  padding: var(--s4) 0 var(--s7);
  position: sticky; top: 52px;
  height: calc(100vh - 52px); overflow-y: auto;
  background: var(--bg);
}
.toc nav { padding: 0 var(--s3); }
.toc h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border: 0; margin: var(--s4) var(--s2) var(--s2); padding: 0; }
.toc a {
  display: flex; align-items: baseline; gap: var(--s2);
  padding: var(--s2) var(--s3); border-radius: var(--radius);
  color: var(--ink); font-size: 14px; line-height: 1.45; min-height: 40px;
}
.toc a .num { color: var(--muted); font-family: var(--font-code); font-size: 12px; flex: none; width: 1.6em; }
.toc a.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.toc a .done { margin-left: auto; color: var(--ok); font-size: 12px; flex: none; }
.toc a:hover { background: var(--bg-sunk); text-decoration: none; }

/* 正文 */
.main { flex: 1; min-width: 0; }
.content {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--s5) var(--s5) calc(var(--s7) * 2);
  padding-left: calc(var(--s5) + env(safe-area-inset-left));
  padding-right: calc(var(--s5) + env(safe-area-inset-right));
}
.content-wide { max-width: 62rem; }

/* 章节页脚导航 */
.pager { display: flex; gap: var(--s3); margin-top: var(--s7); border-top: 1px solid var(--line); padding-top: var(--s5); }
.pager a {
  flex: 1; display: block; padding: var(--s3) var(--s4);
  border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); min-height: 44px;
}
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager .dir { font-size: var(--fs-small); color: var(--muted); display: block; }
.pager .next { text-align: right; }

/* 移动端抽屉 */
.drawer-backdrop {
  display: none; position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.45);
}
.drawer-backdrop.open { display: block; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 61;
  width: min(320px, 85vw);
  background: var(--bg-raise);
  transform: translateX(-105%);
  transition: transform .2s ease-out;
  overflow-y: auto;
  padding: var(--s4) 0 var(--s7);
  padding-left: env(safe-area-inset-left);
  box-shadow: var(--shadow);
}
.drawer.open { transform: translateX(0); }
.drawer .drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 0 var(--s4) var(--s2); }

/* 移动端底部上一节/下一节条 */
.mobile-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--bg-raise); border-top: 1px solid var(--line);
  padding: var(--s2) var(--s3);
  padding-bottom: calc(var(--s2) + env(safe-area-inset-bottom));
  gap: var(--s2);
}
.mobile-nav a, .mobile-nav button {
  flex: 1; min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-raise); color: var(--ink); font-size: 14px; gap: var(--s1);
}
.mobile-nav a:hover { text-decoration: none; }

/* 来源/术语面板：窄屏从底部滑出，桌面从右侧滑出 */
.sheet-backdrop { display: none; position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.45); }
.sheet-backdrop.open { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 71;
  max-height: 75vh; overflow-y: auto;
  background: var(--bg-raise); border-top: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  padding: var(--s4) var(--s5) calc(var(--s5) + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .2s ease-out;
}
.sheet.open { transform: translateY(0); }
@media (min-width: 901px) {
  .sheet {
    left: auto; top: 0; bottom: 0; right: 0;
    width: min(440px, 90vw); height: 100vh; max-height: none;
    border-top: 0; border-left: 1px solid var(--line);
    border-radius: 0;
    padding: var(--s5);
    transform: translateX(105%);
    box-shadow: var(--shadow);
  }
  .sheet.open { transform: translateX(0); }
}
.sheet .sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s3); }
.sheet h3 { margin: 0; }

/* 首页章节列表 */
.chapter-list { list-style: none; padding: 0; }
.chapter-list li { margin: 0; border-bottom: 1px solid var(--line); }
.chapter-list a { display: flex; gap: var(--s4); padding: var(--s4) var(--s2); color: var(--ink); align-items: baseline; }
.chapter-list a:hover { background: var(--bg-sunk); text-decoration: none; }
.chapter-list .num { font-family: var(--font-code); color: var(--muted); flex: none; width: 2em; }
.chapter-list .t { font-weight: 600; }
.chapter-list .d { display: block; font-size: var(--fs-small); color: var(--muted); font-weight: 400; }
.chapter-list .st { margin-left: auto; flex: none; font-size: var(--fs-small); color: var(--ok); }
