/* ==========================================================================
   Story Framework 中文手册 · 样式表
   两套主题：paper（纸张浅色） / graphite（PS 风格灰白深色）
   设计原则：少装饰、清晰层级、以正文为中心
   ========================================================================== */

:root {
  --font-sans: "Inter", "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC",
    "Noto Sans SC", system-ui, sans-serif;
  --font-mono: "Cascadia Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
  --sidebar-w: 264px;
  --toc-w: 196px;
  --radius: 6px;
  --radius-sm: 4px;
  --line: 1px;
}

/* ------------------------------- 纸张主题 ------------------------------- */
html[data-theme="paper"] {
  --bg: #f2eee5;
  --surface: #faf7f0;
  --surface-2: #f5f0e5;
  --surface-3: #efe9dc;
  --border: #ded5c3;
  --border-strong: #cabfa9;
  --text: #29251f;
  --text-dim: #6b6153;
  --text-faint: #948977;
  --accent: #8a4f2a;
  --accent-soft: rgba(138, 79, 42, 0.07);
  --accent-line: rgba(138, 79, 42, 0.35);
  --ok: #4a6b3f;
  --warn: #9c4a2f;
  --info: #3f5c68;
  --texture-opacity: 0.5;
  --shadow: 0 1px 2px rgba(60, 45, 25, 0.05);

  /* 示意图（内联 SVG）用的兼容色板 */
  --panel: var(--surface);
  --panel-2: var(--surface-2);
  --accent-2: #3f5c68;
  --accent-2-soft: rgba(63, 92, 104, 0.08);
  --green: #4a6b3f;
  --green-soft: rgba(74, 107, 63, 0.08);
  --purple: #6b5a86;
  --purple-soft: rgba(107, 90, 134, 0.08);
  --red: #9c4a2f;
  --red-soft: rgba(156, 74, 47, 0.08);
}

/* ------------------------------ 石墨深色主题 ----------------------------- */
html[data-theme="graphite"] {
  --bg: #2b2b2b;
  --surface: #323232;
  --surface-2: #383838;
  --surface-3: #3f3f3f;
  --border: #444444;
  --border-strong: #565656;
  --text: #d7d7d7;
  --text-dim: #a3a3a3;
  --text-faint: #808080;
  --accent: #63a9d6;
  --accent-soft: rgba(99, 169, 214, 0.1);
  --accent-line: rgba(99, 169, 214, 0.4);
  --ok: #86b87a;
  --warn: #d38b73;
  --info: #7fa8bd;
  --texture-opacity: 0;
  --shadow: none;

  --panel: var(--surface);
  --panel-2: var(--surface-2);
  --accent-2: #7fa8bd;
  --accent-2-soft: rgba(127, 168, 189, 0.12);
  --green: #86b87a;
  --green-soft: rgba(134, 184, 122, 0.12);
  --purple: #b3a1d6;
  --purple-soft: rgba(179, 161, 214, 0.12);
  --red: #d38b73;
  --red-soft: rgba(211, 139, 115, 0.12);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.85;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* 纸张纤维质感：极淡，不影响阅读 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: var(--texture-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)' opacity='0.055'/%3E%3C/svg%3E");
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }

::selection { background: var(--accent-soft); }

/* -------------------------------- 布局 -------------------------------- */
.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 20px 14px 32px;
  background: var(--surface);
  border-right: var(--line) solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
}

.brand { display: flex; gap: 10px; align-items: center; padding: 0 6px; }
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 5px;
  border: var(--line) solid var(--border-strong);
  display: grid; place-items: center;
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.02em;
  flex: none;
}
.brand-text { line-height: 1.35; }
.brand-title { font-weight: 600; font-size: 14px; }
.brand-sub { font-size: 11px; color: var(--text-faint); }

.search-box { position: relative; }
.search-box input {
  width: 100%;
  padding: 7px 30px 7px 28px;
  border-radius: var(--radius-sm);
  border: var(--line) solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
}
.search-box input:focus { border-color: var(--accent-line); }
.search-box input::placeholder { color: var(--text-faint); }
.search-icon { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--text-faint); font-size: 11px; }
.search-hint { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 10px; color: var(--text-faint); border: var(--line) solid var(--border); border-radius: 3px; padding: 0 4px; }

#search-results {
  position: absolute;
  z-index: 40;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: var(--line) solid var(--border-strong);
  border-radius: var(--radius-sm);
  max-height: 300px;
  overflow-y: auto;
  display: none;
}
#search-results.open { display: block; }
#search-results a {
  display: block;
  padding: 7px 10px;
  border-bottom: var(--line) solid var(--border);
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.5;
}
#search-results a:last-child { border-bottom: 0; }
#search-results a:hover { background: var(--surface-2); text-decoration: none; }
#search-results .sr-title { font-weight: 600; }
#search-results .sr-desc { color: var(--text-faint); font-size: 11px; }
#search-results .sr-empty { padding: 10px; color: var(--text-faint); font-size: 12.5px; }

.nav-group { display: flex; flex-direction: column; gap: 1px; }
.nav-label {
  font-size: 10.5px;
  color: var(--text-faint);
  padding: 4px 8px 6px;
  letter-spacing: 0.08em;
}
.nav-link {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 5px 8px;
  border-radius: 3px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
  border-left: 2px solid transparent;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link .n {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  flex: none;
  min-width: 12px;
}
.nav-link.active { color: var(--text); border-left-color: var(--accent); font-weight: 600; }
.nav-link.active .n { color: var(--accent); }

.side-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: var(--line) solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.6;
}
.theme-switch { display: flex; gap: 4px; }
.theme-switch button {
  flex: 1;
  background: transparent;
  border: var(--line) solid var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 11.5px;
  padding: 4px 6px;
  cursor: pointer;
}
.theme-switch button:hover { border-color: var(--border-strong); color: var(--text); }
.theme-switch button[aria-pressed="true"] { border-color: var(--accent-line); color: var(--accent); background: var(--accent-soft); }

/* -------------------------------- 正文 -------------------------------- */
.main { min-width: 0; }
.main-inner { max-width: 1080px; margin: 0 auto; padding: 44px 40px 96px; }

.doc-head { margin-bottom: 34px; }
.eyebrow {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-bottom: 10px;
}
h1 {
  font-size: 30px;
  line-height: 1.35;
  margin: 0 0 10px;
  font-weight: 650;
  letter-spacing: -0.005em;
}
.lede { font-size: 15.5px; color: var(--text-dim); margin: 0; line-height: 1.8; }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 16px; color: var(--text-faint); font-size: 12px; }
.meta-row .chip { font-size: 12px; color: var(--text-faint); }
.meta-row .chip::before { content: "·"; margin-right: 6px; color: var(--border-strong); }
.meta-row .chip:first-child::before { content: ""; margin: 0; }

h2 {
  font-size: 21px;
  margin: 44px 0 12px;
  line-height: 1.5;
  font-weight: 650;
  scroll-margin-top: 76px;
  padding-bottom: 8px;
  border-bottom: var(--line) solid var(--border);
}
h3 { font-size: 16.5px; margin: 26px 0 8px; font-weight: 650; scroll-margin-top: 76px; }
h4 { font-size: 14.5px; margin: 20px 0 6px; color: var(--text-dim); font-weight: 600; }
p { margin: 0 0 13px; }
ul, ol { margin: 0 0 15px; padding-left: 20px; }
li { margin: 4px 0; }
li::marker { color: var(--text-faint); }
strong { font-weight: 650; }
hr { border: 0; border-top: var(--line) solid var(--border); margin: 30px 0; }

code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--surface-2);
  border: var(--line) solid var(--border);
  padding: 0.5px 4px;
  border-radius: 3px;
  color: var(--text);
  white-space: nowrap;
}
a code { color: inherit; }
pre {
  background: var(--surface);
  border: var(--line) solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.7;
  margin: 0 0 16px;
  color: var(--text-dim);
}
pre code { background: none; border: 0; padding: 0; color: inherit; white-space: pre; }

blockquote {
  margin: 0 0 16px;
  padding: 2px 0 2px 14px;
  border-left: 2px solid var(--border-strong);
  color: var(--text-dim);
}

/* ------------------------------- 提示块 ------------------------------- */
.callout {
  border: var(--line) solid var(--border);
  border-left: 2px solid var(--border-strong);
  background: var(--surface);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 14px;
  margin: 0 0 18px;
  font-size: 14.5px;
  line-height: 1.75;
}
.callout > :last-child { margin-bottom: 0; }
.callout .co-title {
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 600;
  margin-bottom: 5px;
}
.callout.info { border-left-color: var(--info); }
.callout.tip { border-left-color: var(--ok); }
.callout.warn { border-left-color: var(--warn); }
.callout.note { border-left-color: var(--accent-line); }
.callout.beginner { border-left-color: var(--border-strong); background: var(--surface-2); }
.callout.beginner .co-title { color: var(--text-dim); }

/* -------------------------------- 卡片 -------------------------------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin: 0 0 20px; }
.card {
  display: block;
  background: var(--surface);
  border: var(--line) solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
}
.card:hover { border-color: var(--border-strong); text-decoration: none; }
.card .c-k { font-size: 10.5px; letter-spacing: 0.08em; color: var(--text-faint); font-family: var(--font-mono); }
.card .c-t { font-weight: 600; margin: 2px 0 3px; font-size: 14.5px; }
.card .c-d { font-size: 12.5px; color: var(--text-dim); line-height: 1.6; }

/* -------------------------------- 表格 -------------------------------- */
.table-wrap { overflow-x: auto; margin: 0 0 20px; border: var(--line) solid var(--border); border-radius: var(--radius-sm); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: var(--line) solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; font-size: 12.5px; color: var(--text-dim); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td code { white-space: nowrap; }
tbody tr:hover { background: var(--surface); }

/* -------------------------------- 图片 -------------------------------- */
figure { margin: 0 0 22px; }
figure img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  border: var(--line) solid var(--border-strong);
  border-radius: 3px;
  background: var(--surface);
  cursor: zoom-in;
}
figure.plain img { border-color: var(--border); }
figure.wide img { width: 100%; }
figcaption {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 7px;
  line-height: 1.6;
  padding-left: 2px;
}
figcaption b { color: var(--text-dim); font-weight: 600; }

.yes { color: var(--ok); font-weight: 600; }
.no { color: var(--warn); font-weight: 600; }

.img-row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 8px; align-items: flex-start; }
.img-row figure { margin-bottom: 8px; flex: 1 1 220px; max-width: 340px; }

/* -------------------------------- 链接 -------------------------------- */
.xref {
  display: inline-block;
  font-size: 14px;
  color: var(--accent);
}

/* -------------------------------- 步骤 -------------------------------- */
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0 0 20px; }
.steps > li {
  counter-increment: step;
  position: relative;
  padding: 0 0 16px 38px;
  margin: 0;
}
.steps > li::before {
  content: counter(step);
  position: absolute; left: 0; top: 2px;
  width: 22px; height: 22px;
  border-radius: 3px;
  border: var(--line) solid var(--border-strong);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11.5px;
  display: grid; place-items: center;
  background: var(--surface);
}
.steps > li > strong:first-child { display: block; margin-bottom: 2px; }
.steps > li:last-child { padding-bottom: 0; }

/* ------------------------------ 右侧目录 ------------------------------ */
.toc {
  position: sticky;
  top: 28px;
  align-self: start;
  width: var(--toc-w);
  max-height: calc(100vh - 56px);
  overflow-y: auto;
  font-size: 12.5px;
  padding-bottom: 24px;
}
.toc-title { font-size: 10.5px; letter-spacing: 0.08em; color: var(--text-faint); margin-bottom: 8px; }
.toc a { display: block; color: var(--text-faint); padding: 3px 0 3px 9px; border-left: var(--line) solid var(--border); line-height: 1.5; }
.toc a:hover { color: var(--text); text-decoration: none; border-left-color: var(--border-strong); }
.toc a.lvl3 { padding-left: 19px; font-size: 12px; }
.toc a.active { color: var(--accent); border-left-color: var(--accent); }

.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) var(--toc-w); gap: 44px; align-items: start; }

/* ------------------------------- 翻页 ------------------------------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 54px; padding-top: 22px; border-top: var(--line) solid var(--border); }
.pager a {
  display: block;
  padding: 11px 13px;
  border: var(--line) solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: var(--surface);
}
.pager a:hover { border-color: var(--border-strong); text-decoration: none; }
.pager .p-dir { font-size: 10.5px; letter-spacing: 0.06em; color: var(--text-faint); }
.pager .p-title { font-weight: 600; margin-top: 2px; font-size: 14px; }
.pager .next { text-align: right; }

.doc-foot { margin-top: 40px; padding-top: 18px; border-top: var(--line) solid var(--border); font-size: 12px; color: var(--text-faint); line-height: 1.9; }
.doc-foot a { color: var(--text-dim); text-decoration: underline; text-underline-offset: 2px; }

.video-note {
  font-size: 13px;
  color: var(--text-faint);
  border-top: var(--line) dashed var(--border-strong);
  padding-top: 10px;
  margin-top: 30px;
}

/* ------------------------------- 首页 ------------------------------- */
.hero {
  border-bottom: var(--line) solid var(--border);
  padding-bottom: 26px;
  margin-bottom: 30px;
}
.hero h1 { font-size: 32px; margin-bottom: 12px; }
.hero .lede { max-width: 60ch; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.btn {
  display: inline-flex; align-items: center;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  border: var(--line) solid var(--border-strong);
  color: var(--text);
  background: var(--surface);
}
.btn:hover { border-color: var(--accent-line); color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fdfbf6; }
.btn.primary:hover { color: #fdfbf6; filter: brightness(0.96); }
html[data-theme="graphite"] .btn.primary {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}

.path { display: grid; gap: 1px; margin: 0 0 24px; border: var(--line) solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--border); }
.path-item {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center;
  padding: 11px 14px; background: var(--surface); color: var(--text);
}
.path-item:hover { background: var(--surface-2); text-decoration: none; }
.path-num { font-family: var(--font-mono); color: var(--text-faint); font-size: 12px; }
.path-t { font-weight: 600; font-size: 14.5px; }
.path-d { font-size: 12.5px; color: var(--text-dim); line-height: 1.55; }
.path-arrow { color: var(--text-faint); }

.tag-grid { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 18px; }
.tag-grid .chip { font-size: 13px; color: var(--text-dim); }
.tag-grid .chip::before { content: "#"; color: var(--text-faint); margin-right: 3px; }

/* ------------------------------- 视频 ------------------------------- */
.video-embed {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  margin: 0 0 8px;
  border: var(--line) solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
}
.video-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-poster {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  padding: 0; margin: 0; border: 0;
  background: #000;
  cursor: pointer;
  overflow: hidden;
}
.video-poster img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0.9; }
.video-poster:hover img { opacity: 1; }
.play-badge {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.7);
  color: #fff;
  font-size: 18px;
  display: grid; place-items: center;
  padding-left: 3px;
}
.video-fallback { font-size: 12px; color: var(--text-faint); margin-bottom: 22px; }

/* ------------------------------- 图片灯箱 ------------------------------ */
#lightbox {
  position: fixed; inset: 0;
  background: rgba(20, 18, 15, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  cursor: zoom-out;
}
#lightbox.open { display: flex; }
#lightbox img { max-width: 100%; max-height: 100%; border-radius: 3px; border: var(--line) solid #555; }

/* ------------------------------- 顶栏 ------------------------------- */
.topbar {
  display: none;
  position: sticky; top: 0; z-index: 50;
  align-items: center; gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: var(--line) solid var(--border);
}
.topbar button {
  background: transparent; border: var(--line) solid var(--border);
  border-radius: 3px; color: var(--text-dim);
  width: 30px; height: 28px; cursor: pointer; font-size: 13px;
}
.topbar .tb-title { font-size: 13px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 59; }
.scrim.open { display: block; }

/* ------------------------------- 响应式 ------------------------------- */
@media (max-width: 1180px) {
  :root { --toc-w: 0px; }
  .content-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .toc { display: none; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .topbar { display: flex; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 272px;
    z-index: 60;
    transform: translateX(-101%);
    transition: transform 0.18s ease;
    height: 100vh;
  }
  .sidebar.open { transform: none; }
  .main-inner { padding: 24px 18px 64px; }
  h1 { font-size: 25px; }
  h2 { font-size: 19px; }
  .hero h1 { font-size: 26px; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { text-align: left; }
  body { font-size: 15.5px; }
}
@media (max-width: 700px) {
  table { min-width: 520px; }
  th { white-space: normal; }
  th, td { padding: 8px 10px; }
  figure svg { min-width: 600px; }
  figure { overflow-x: auto; }
  figure:has(> svg)::after {
    content: "← 可左右滑动查看完整示意图 →";
    display: block;
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 4px;
  }
}

@media print {
  .sidebar, .toc, .topbar, .pager, #lightbox, .search-box, .theme-switch { display: none !important; }
  .layout { display: block; }
  .main-inner { max-width: none; padding: 0; }
  body { background: #fff; color: #000; font-size: 11pt; }
  body::before { display: none; }
  a { color: #000; text-decoration: underline; }
  h2 { break-after: avoid; page-break-after: avoid; }
  figure, table { break-inside: avoid; page-break-inside: avoid; }
}
