/* 系统架构设计师备考站 · 手机优先样式 */
:root {
  --bg: #fbfaf7;
  --panel: #ffffff;
  --ink: #1b1f24;
  --ink-2: #3d454e;
  --muted: #6f7782;
  --line: #e6e1d6;
  --line-2: #d8d2c4;
  --accent: #1f4e79;
  --accent-2: #2f6ea5;
  --accent-soft: #edf3f9;
  --code-bg: #f4f1ea;
  --mark: #ffe79a;
  --pri-bg: #fdeee0;
  --pri-ink: #a2541b;
  --radius: 10px;
  --maxw: 760px;
  --fs: 17px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b;
    --panel: #1b1f24;
    --ink: #e8e6e1;
    --ink-2: #c3c7cc;
    --muted: #8f98a3;
    --line: #2b3138;
    --line-2: #3a424b;
    --accent: #7db6e6;
    --accent-2: #9cc9ef;
    --accent-soft: #1d2833;
    --code-bg: #1e242a;
    --mark: #7a5c00;
    --pri-bg: #3a2a1c;
    --pri-ink: #e0a86e;
  }
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 64px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: var(--fs);
  line-height: 1.78;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", system-ui, sans-serif;
  word-wrap: break-word;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 12px;
  background: rgba(251, 250, 247, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
}
@media (prefers-color-scheme: dark) {
  .topbar { background: rgba(20, 23, 27, 0.92); }
}
.topbar .brand {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}
.topbar .brand small {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0;
  line-height: 1.2;
}
.iconbtn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.iconbtn:hover { text-decoration: none; border-color: var(--accent); color: var(--accent); }
.iconbtn .ic { font-size: 15px; }
.printbtn { display: none; }
@media (min-width: 520px) { .printbtn { display: inline-flex; } }

/* ---------- 布局 ---------- */
.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 14px;
}
.layout {
  display: block;
  padding: 16px 0 40px;
}
main { min-width: 0; }

/* ---------- 侧栏（手机抽屉 / 桌面常驻） ---------- */
.side {
  display: none;
  font-size: 14px;
  line-height: 1.5;
}
.scrim {
  display: none;
  position: fixed;
  inset: 52px 0 0 0;
  background: rgba(0, 0, 0, 0.42);
  z-index: 35;
}
body.nav-open { overflow: hidden; }
body.nav-open .scrim { display: block; }
body.nav-open .side {
  display: block;
  position: fixed;
  top: 52px;
  bottom: 0;
  left: 0;
  z-index: 40;
  width: min(86vw, 340px);
  overflow-y: auto;
  padding: 14px 14px 40px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: 8px 0 24px rgba(0, 0, 0, 0.14);
}
.side h4 {
  margin: 18px 0 8px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.side h4:first-child { margin-top: 2px; }
.side ul { list-style: none; margin: 0; padding: 0; }
.side li { margin: 1px 0; }
.side a {
  display: block;
  padding: 7px 8px;
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 13.5px;
}
.side a:hover { background: var(--accent-soft); text-decoration: none; color: var(--accent); }
.side a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side .num {
  display: inline-block;
  min-width: 34px;
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.side .toc-sub { padding-left: 18px; font-size: 12.5px; color: var(--muted); }

/* ---------- 正文 ---------- */
.article {
  max-width: var(--maxw);
  margin: 0 auto;
}
.article h1 {
  font-size: 1.52em;
  line-height: 1.35;
  margin: 0.2em 0 0.5em;
  letter-spacing: -0.01em;
}
.article h2 {
  font-size: 1.24em;
  line-height: 1.4;
  margin: 2em 0 0.7em;
  padding-top: 0.85em;
  border-top: 1px solid var(--line);
}
.article h3 {
  font-size: 1.06em;
  line-height: 1.45;
  margin: 1.7em 0 0.55em;
  color: var(--ink);
}
.article h4 {
  font-size: 1em;
  margin: 1.4em 0 0.4em;
}
.article p { margin: 0.85em 0; }
.article ul, .article ol { margin: 0.7em 0; padding-left: 1.35em; }
.article li { margin: 0.28em 0; }
.article li > ul, .article li > ol { margin: 0.2em 0; }
.article hr {
  border: 0;
  border-top: 1px dashed var(--line-2);
  margin: 1.8em 0;
}
.article strong { font-weight: 650; }

.article code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: var(--code-bg);
  padding: 0.12em 0.35em;
  border-radius: 4px;
}
.article pre.code {
  margin: 1em 0;
  padding: 12px 14px;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 13px;
  line-height: 1.6;
  tab-size: 2;
}
.article pre.code code {
  background: none;
  padding: 0;
  font-size: 1em;
  white-space: pre;
}
/* 可横向滚动的代码块，用右侧阴影提示还有内容 */
.article pre.code.scrollable {
  box-shadow: inset -16px 0 14px -12px rgba(0, 0, 0, 0.35);
}

.article blockquote {
  margin: 1em 0;
  padding: 10px 14px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent-2);
  border-radius: 0 8px 8px 0;
  color: var(--ink-2);
  font-size: 0.96em;
}
.article blockquote p { margin: 0.4em 0; }
.article blockquote p:first-child { margin-top: 0; }
.article blockquote p:last-child { margin-bottom: 0; }

.article .anchor {
  margin-left: 6px;
  color: var(--line-2);
  font-weight: 400;
  font-size: 0.75em;
  opacity: 0;
  transition: opacity 0.15s;
}
.article h2:hover .anchor, .article h3:hover .anchor { opacity: 1; }

/* 表格：横向滚动 */
.tw {
  margin: 1.1em 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.tw table {
  border-collapse: collapse;
  width: 100%;
  min-width: 520px;
  font-size: 14px;
  line-height: 1.6;
}
.tw th, .tw td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
}
.tw th:last-child, .tw td:last-child { border-right: 0; }
.tw tr:last-child td { border-bottom: 0; }
.tw th {
  background: var(--accent-soft);
  font-weight: 600;
  white-space: nowrap;
}
.tw.scrollable { position: relative; }
.tw.scrollable::after {
  content: "← 左右滑动查看完整表格 →";
  display: block;
  position: sticky;
  left: 0;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px dashed var(--line);
  background: var(--panel);
}

/* ---------- 本页目录（折叠） ---------- */
.page-toc {
  margin: 1.1em 0 1.6em;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 14px;
}
.page-toc summary {
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  color: var(--ink-2);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.page-toc summary::-webkit-details-marker { display: none; }
.page-toc summary::after { content: "展开"; font-size: 12px; color: var(--muted); font-weight: 400; }
.page-toc[open] summary::after { content: "收起"; }
.page-toc[open] summary { border-bottom: 1px solid var(--line); }
.page-toc ol {
  margin: 6px 0;
  padding: 0 16px 8px 30px;
  color: var(--ink-2);
}
.page-toc li { margin: 3px 0; }
.page-toc .lv3 { margin-left: 14px; font-size: 13px; color: var(--muted); }

/* ---------- 翻页 ---------- */
.pager {
  display: flex;
  gap: 10px;
  margin: 34px 0 10px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.pager a {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink-2);
  line-height: 1.45;
}
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager .dir { display: block; font-size: 11px; color: var(--muted); }
.pager .next { text-align: right; }

/* ---------- 首页 ---------- */
.hero {
  padding: 26px 0 8px;
}
.hero h1 {
  font-size: 1.7em;
  line-height: 1.35;
  margin: 0 0 8px;
  letter-spacing: -0.015em;
}
.hero .lead {
  margin: 0 0 6px;
  color: var(--ink-2);
  font-size: 0.98em;
}
.hero .meta {
  color: var(--muted);
  font-size: 12.5px;
}
.searchbox {
  display: flex;
  gap: 8px;
  margin: 18px 0 6px;
}
.searchbox input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  font-size: 15px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: 8px;
}
.searchbox input:focus { outline: none; border-color: var(--accent); }
.searchbox button {
  height: 44px;
  padding: 0 16px;
  font-size: 14px;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.searchbox button:hover { background: var(--accent-2); }

.quickgrid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 18px 0 6px;
}
.qcard {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
}
.qcard:hover { text-decoration: none; border-color: var(--accent); }
.qcard b { display: block; font-size: 15px; margin-bottom: 2px; }
.qcard span { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

.section { margin-top: 34px; }
.section > h2 {
  font-size: 1.16em;
  margin: 0 0 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.section > .hint {
  margin: 8px 0 14px;
  font-size: 12.5px;
  color: var(--muted);
}

.route {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 4px;
}
.route a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13.5px;
  border: 1px solid transparent;
}
.route a:hover { text-decoration: none; border-color: var(--accent); }
.route .arrow { color: var(--muted); font-size: 12px; }
@media (max-width: 719px) {
  .route .arrow { display: none; }
  .route a { width: 100%; }
}

.chapgroup { margin-top: 18px; }
.chapgroup > .gtitle {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  margin: 0 0 6px;
}
.chapgroup > .gtitle .stars { color: #b8860b; letter-spacing: 1px; }
@media (prefers-color-scheme: dark) {
  .chapgroup > .gtitle .stars { color: #d8b25a; }
}

.clist { list-style: none; margin: 0; padding: 0; }
.clist li { border-bottom: 1px solid var(--line); }
.clist a {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 10px 2px;
  color: var(--ink);
}
.clist a:hover { text-decoration: none; color: var(--accent); }
.clist .no {
  flex: 0 0 42px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.clist .nm { flex: 1; min-width: 0; font-size: 15px; line-height: 1.5; }
.clist .tag {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}

.paperlist { list-style: none; margin: 0; padding: 0; }
.paperlist li { border-bottom: 1px solid var(--line); }
.paperlist a {
  display: block;
  padding: 12px 2px;
  color: var(--ink);
}
.paperlist a:hover { text-decoration: none; color: var(--accent); }
.paperlist .t { font-size: 15px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.paperlist .t .badge {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.paperlist .d { display: block; margin-top: 3px; font-size: 12.5px; color: var(--muted); line-height: 1.55; }
.paperlist .t .badge.pri { background: var(--pri-bg); color: var(--pri-ink); }

.foot {
  margin-top: 44px;
  padding: 18px 0 30px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.7;
}
.foot p { margin: 4px 0; }

/* ---------- 搜索页 ---------- */
.search-page .searchbox { margin-top: 4px; }
.search-meta { margin: 14px 0 4px; font-size: 12.5px; color: var(--muted); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 6px; }
.filters button {
  padding: 5px 11px;
  font-size: 12.5px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--panel);
  color: var(--ink-2);
  cursor: pointer;
}
.filters button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.results { list-style: none; margin: 12px 0 0; padding: 0; }
.results li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.results .r-title { font-size: 15px; font-weight: 600; line-height: 1.5; }
.results .r-title a { color: var(--accent); }
.results .r-path { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.results .r-snip { margin-top: 5px; font-size: 13.5px; color: var(--ink-2); line-height: 1.65; }
.results mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.empty { padding: 30px 0; color: var(--muted); font-size: 14px; }

/* ---------- 宽屏 ---------- */
@media (min-width: 1024px) {
  .layout {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    gap: 40px;
    align-items: start;
  }
  .side {
    display: block;
    position: sticky;
    top: 68px;
    max-height: calc(100vh - 88px);
    overflow-y: auto;
    padding: 4px 12px 30px 0;
    border-right: 1px solid var(--line);
  }
  .scrim { display: none !important; }
  #navBtn { display: none; }
  .article { margin: 0; }
  .article h1 { font-size: 1.85em; }
  .hero h1 { font-size: 2.1em; }
  .quickgrid { grid-template-columns: repeat(3, 1fr); }
  .clist a { padding: 9px 4px; }
  .article { max-width: 780px; }
  .page-toc { display: none; }
  body { --fs: 17.5px; }
}

/* ---------- 打印（A4） ---------- */
@page { size: A4; margin: 16mm 14mm; }

@media print {
  :root {
    --bg: #fff;
    --panel: #fff;
    --ink: #000;
    --ink-2: #111;
    --muted: #444;
    --line: #bbb;
    --line-2: #999;
    --accent: #000;
    --accent-soft: #f2f2f2;
    --code-bg: #f7f7f7;
  }
  html { scroll-padding-top: 0; }
  body {
    background: #fff;
    color: #000;
    font-size: 10.5pt;
    line-height: 1.55;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .topbar, .side, .scrim, .pager, .page-toc, .searchbox, .no-print, .foot .noprint { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .layout { display: block; padding: 0; }
  .article, .hero { max-width: none; }
  .article h1 { font-size: 17pt; margin: 0 0 8pt; }
  .article h2 { font-size: 13pt; margin: 14pt 0 5pt; padding-top: 8pt; page-break-after: avoid; }
  .article h3 { font-size: 11pt; margin: 10pt 0 3pt; page-break-after: avoid; }
  .article p, .article li { orphans: 3; widows: 3; }
  .article a { color: #000; text-decoration: none; }
  .article .anchor { display: none; }
  .article pre.code, .tw, .article blockquote, .article table, .article tr, .article td, .article th {
    page-break-inside: avoid;
  }
  .article pre.code { border: 1px solid #ccc; font-size: 8.8pt; white-space: pre-wrap; }
  .tw { overflow: visible; border: 0; }
  .tw table { min-width: 0; font-size: 8.8pt; width: 100%; }
  .tw th, .tw td { padding: 3pt 4pt; border: 1px solid #999; }
  .tw th { background: #eee; white-space: normal; }
  .tw.scrollable::after { display: none; }
  .article blockquote { border-left: 2pt solid #666; background: #f7f7f7; }
  .pagebreak { page-break-before: always; }
}

/* 顶部阅读/打印入口只用于屏幕 */
@media print { .screen-only { display: none !important; } }
