/* ==========================================================================
   PRD Reader — v3 视觉系统
   对齐 assets/prd-style.css：纯白 + editorial red #b3261e + Inter 正文
   ========================================================================== */

/* -------- Design Tokens -------- */
:root {
  --ink:        #111418;
  --ink-soft:   #2b3138;
  --ink-mute:   #5b6570;
  --ink-faint:  #8b95a1;
  --rule:       #e5e7ea;
  --rule-soft:  #f1f3f5;
  --paper:      #ffffff;
  --paper-alt:  #fafbfc;
  --accent:     #b3261e;
  --accent-soft:#fdecea;
  --code-bg:    #f6f7f9;

  --font-sans:  "Inter", "Noto Sans SC", "PingFang SC", system-ui, sans-serif;
  --font-serif: "Source Serif 4", "Noto Serif SC", Georgia, serif;
  --font-mono:  "JetBrains Mono", "SF Mono", Consolas, monospace;

  --sidebar-w:  300px;
  --sidebar-collapsed: 72px;
  --content-max: 800px;
  --pad-side: 48px;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

html[data-theme="dark"] {
  --ink:        #e8eaed;
  --ink-soft:   #c7cbd0;
  --ink-mute:   #8a929b;
  --ink-faint:  #5b6570;
  --rule:       rgba(232,234,237,0.10);
  --rule-soft:  rgba(232,234,237,0.05);
  --paper:      #0e1116;
  --paper-alt:  #151920;
  --accent:     #e06c5d;
  --accent-soft: rgba(224,108,93,0.14);
  --code-bg:    #1a1f27;
}

/* -------- Reset -------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html {
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
  transition: background 200ms ease, color 200ms ease;
}

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

button { font-family: inherit; cursor: pointer; border: 0; background: transparent; color: inherit; }

input, button { font: inherit; }

hr { border: 0; border-top: 1px solid var(--rule); margin: 28px 0; }

/* ==========================================================================
   Sidebar
   ========================================================================== */

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  padding: 28px 24px 20px;
  background: var(--paper-alt);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  z-index: 20;
  transition: width 250ms var(--ease), padding 250ms var(--ease), transform 250ms var(--ease);
}

.sidebar-toggle {
  position: absolute;
  top: 22px;
  right: -13px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 42;
  color: var(--ink-mute);
  transition: background 180ms, border-color 180ms, color 180ms, transform 250ms var(--ease);
  box-shadow: 0 2px 6px -2px rgba(17,20,24,0.08);
}
.sidebar-toggle:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.sidebar-toggle svg {
  width: 14px; height: 14px;
  transition: transform 250ms var(--ease);
}
body[data-sidebar="collapsed"] .sidebar-toggle svg { transform: rotate(180deg); }

/* --- Brand --- */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
  padding: 0;
}
.brand-dot {
  flex: 0 0 9px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  animation: brand-breathe 5s ease-in-out infinite;
}
@keyframes brand-breathe {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.2); opacity: 0.82; }
}
.brand-text { min-width: 0; line-height: 1.25; }
.brand-line-1 {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-line-2 {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
  margin-top: 2px;
}

/* --- Search --- */
.search-wrap {
  position: relative;
  margin-bottom: 18px;
}
#search {
  width: 100%;
  padding: 9px 36px 9px 12px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  font-size: 13px;
  color: var(--ink);
  outline: none;
  transition: border-color 180ms, box-shadow 180ms;
}
#search::placeholder { color: var(--ink-faint); }
#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
/* 禁用浏览器原生蓝色粗体 X —— 用自定义 SVG 小灰叉替代（见 app.js 注入按钮） */
#search::-webkit-search-cancel-button,
#search::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}
#search::-ms-clear { display: none; width: 0; height: 0; }
.search-wrap .search-kbd {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-mute);
  background: var(--paper-alt);
  border: 1px solid var(--rule);
  border-radius: 3px;
  pointer-events: none;
}
/* 自定义 clear 按钮：小号浅灰叉，hover 变深；有输入时显示，替代 kbd "/" */
.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  border: none;
  color: var(--ink-faint);
  cursor: pointer;
  border-radius: 3px;
  padding: 0;
  transition: color 150ms, background 150ms;
}
.search-clear:hover { color: var(--ink-soft); background: var(--rule-soft); }
.search-clear:focus { outline: none; color: var(--ink); background: var(--accent-soft); }
.search-wrap.has-value .search-kbd { display: none; }
.search-wrap:not(.has-value) .search-clear { display: none; }

/* --- TOC --- */
.toc {
  flex: 1;
  overflow-y: auto;
  margin: 0 -8px;
  padding: 4px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}
.toc::-webkit-scrollbar { width: 6px; }
.toc::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 3px; }

.toc-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 7px 10px 7px 8px;
  border-left: 2px solid transparent;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.4;
  transition: padding-left 180ms var(--ease), border-color 180ms, color 180ms, background 180ms;
  border-radius: 0 2px 2px 0;
}
.toc-item:hover {
  padding-left: 14px;
  border-left-color: var(--accent-soft);
  color: var(--ink);
  background: var(--rule-soft);
}
.toc-item.active {
  padding-left: 14px;
  border-left-color: var(--accent);
  color: var(--ink);
  font-weight: 600;
  background: var(--accent-soft);
}
.toc-num {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  padding-top: 2px;
  min-width: 22px;
}
.toc-item.active .toc-num { color: var(--accent); }
.toc-title-text { flex: 1; }
.toc-lock {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 10px;
  padding-top: 3px;
}
.toc-item.gated .toc-title-text { color: var(--ink-mute); }
.search-nomatch {
  padding: 18px 10px;
  color: var(--ink-faint);
  font-size: 13px;
  text-align: center;
}
/* 搜索结果 item（带 snippet 上下文） */
.search-hit-item {
  display: block;
  padding: 9px 10px 10px 10px;
  border-left: 2px solid transparent;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.45;
  border-radius: 0 2px 2px 0;
  margin-bottom: 2px;
  transition: padding-left 180ms var(--ease), border-color 180ms, background 180ms;
}
.search-hit-item:hover {
  padding-left: 14px;
  border-left-color: var(--accent-soft);
  background: var(--rule-soft);
}
.search-hit-item .shit-head {
  display: flex; gap: 10px; align-items: flex-start;
  color: var(--ink);
  font-weight: 500;
}
.search-hit-item.gated .shit-head .toc-title-text { color: var(--ink-mute); }
.search-hit-item .shit-snippet {
  margin-top: 4px;
  margin-left: 32px;
  font-size: 12px;
  color: var(--ink-mute);
  line-height: 1.55;
  /* 限制两行 */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-hit {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0 2px;
  border-radius: 2px;
}

/* --- Sidebar footer --- */
.sidebar-footer {
  border-top: 1px solid var(--rule);
  padding-top: 14px;
  margin-top: 8px;
}
#theme-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  width: 100%;
  border-radius: 4px;
  color: var(--ink-soft);
  font-size: 13px;
  transition: background 180ms, color 180ms;
}
#theme-toggle:hover { background: var(--rule-soft); color: var(--ink); }
#theme-toggle svg {
  width: 16px; height: 16px;
  transition: opacity 250ms, transform 400ms var(--ease);
}
#theme-toggle:hover svg { transform: rotate(15deg); }
.icon-sun, .icon-moon { flex: 0 0 auto; }
html[data-theme="light"] .icon-moon { display: none; }
html[data-theme="dark"]  .icon-sun  { display: none; }
.meta-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 0 10px;
  font-size: 11px;
  color: var(--ink-faint);
  font-family: var(--font-mono);
}
.meta-line .sep { opacity: 0.5; }

/* -------- Sidebar collapsed state (Rail 模式) --------
   参考 Stripe Docs / Linear Docs / GitBook：
     · 72px 窄轨道，垂直排列章节数字胶囊
     · 当前章节红色胶囊高亮（白字）
     · 付费章节数字右上角红点标识
     · hover 数字 → 右侧浮出章节标题 tooltip
     · 搜索从 input 变圆形放大镜按钮 → 点击触发展开 + 聚焦
   ------------------------------------------------------- */
body[data-sidebar="collapsed"] .sidebar {
  width: var(--sidebar-collapsed);
  padding: 24px 8px 16px;
}

/* 丝滑切换：hide-on-collapse 元素用 opacity + max-height + margin 三位一体过渡，
   和 .sidebar 的 width transition 同步进行而不是硬 display 跳变。 */
.brand-text,
.search-wrap,
#theme-toggle .label,
.meta-line {
  opacity: 1;
  max-height: 80px;
  visibility: visible;
  transition: opacity 160ms var(--ease) 60ms,
              max-height 240ms var(--ease),
              margin 240ms var(--ease),
              visibility 0ms 0ms;
}
body[data-sidebar="collapsed"] .brand-text,
body[data-sidebar="collapsed"] .search-wrap,
body[data-sidebar="collapsed"] #theme-toggle .label,
body[data-sidebar="collapsed"] .meta-line {
  opacity: 0;
  max-height: 0;
  margin-top: 0;
  margin-bottom: 0;
  visibility: hidden;
  overflow: hidden;
  pointer-events: none;
  transition: opacity 120ms var(--ease),
              max-height 220ms var(--ease),
              margin 220ms var(--ease),
              visibility 0ms 220ms;
}

body[data-sidebar="collapsed"] .brand { justify-content: center; margin: 0 0 14px; }
body[data-sidebar="collapsed"] #theme-toggle { justify-content: center; padding: 8px; }
body[data-sidebar="collapsed"] .sidebar-footer { border-top: 0; padding-top: 8px; }

/* Rail 搜索图标：展开态淡出收起，rail 态淡入 */
.search-expand-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: 0 auto 10px;
  padding: 0;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--rule);
  color: var(--ink-mute);
  cursor: pointer;
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
  transition: opacity 140ms var(--ease), transform 200ms var(--ease), background 180ms, border-color 180ms, color 180ms;
}
body[data-sidebar="collapsed"] .search-expand-btn {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
  transition-delay: 100ms;
}
.search-expand-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.search-expand-btn svg { width: 16px; height: 16px; }

/* TOC 在 rail 模式下保留显示，但换一套布局 */
body[data-sidebar="collapsed"] .toc {
  display: block;
  margin: 0 -4px;
  padding: 0 4px;
}
body[data-sidebar="collapsed"] .toc-item {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 48px;
  height: 30px;
  margin: 2px auto;
  padding: 0;
  gap: 0;
  border-left: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-soft);
  transition: background 150ms, color 150ms;
}
body[data-sidebar="collapsed"] .toc-item:hover {
  padding-left: 0;
  border-left: 0;
  background: var(--rule-soft);
  color: var(--ink);
}
body[data-sidebar="collapsed"] .toc-item.active {
  padding-left: 0;
  border-left: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}
body[data-sidebar="collapsed"] .toc-num {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 0;
  min-width: auto;
  color: inherit;
}
body[data-sidebar="collapsed"] .toc-item.active .toc-num { color: #fff; }
body[data-sidebar="collapsed"] .toc-item.gated .toc-num { color: var(--ink-faint); }

/* rail 模式下章节标题 span 完全隐藏 —— 标题改由 body 级 #rail-tooltip 呈现 */
body[data-sidebar="collapsed"] .toc-title-text { display: none; }

/* body 级 tooltip：position: fixed 逃出 sidebar overflow 裁剪 */
.rail-tooltip {
  position: fixed;
  z-index: 80;
  top: 0;
  left: 0;
  padding: 6px 11px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  border-radius: 4px;
  box-shadow: 0 10px 24px -6px rgba(0,0,0,0.35);
  pointer-events: none;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 140ms, transform 140ms;
}
.rail-tooltip.is-visible {
  opacity: 1;
  transform: translateX(0);
}
.rail-tooltip::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 50%;
  transform: translateY(-50%);
  width: 7px;
  height: 7px;
  background: var(--ink);
  clip-path: polygon(100% 0, 100% 100%, 0 50%);
}
html[data-theme="dark"] .rail-tooltip {
  background: var(--paper-alt);
  color: var(--ink);
  border: 1px solid var(--rule);
}
html[data-theme="dark"] .rail-tooltip::before {
  background: var(--paper-alt);
}

/* 付费章节：数字右上角 2px 红点，替代展开态的 ◆ 图标 */
body[data-sidebar="collapsed"] .toc-lock {
  position: absolute;
  top: 5px;
  right: 6px;
  width: 5px;
  height: 5px;
  padding: 0;
  background: var(--accent);
  border-radius: 50%;
  font-size: 0;
  color: transparent;
}
body[data-sidebar="collapsed"] .toc-item.active .toc-lock { background: #fff; }

/* rail 搜索模式下不要渲染 search-hit-item（用户在 rail 看不清），
   点搜索图标会展开，所以不用特殊处理 */

/* 移动端不启用 rail */
@media (max-width: 768px) {
  body[data-sidebar="collapsed"] .search-expand-btn { display: none; }
}

/* ==========================================================================
   Main content
   ========================================================================== */

.content {
  margin-left: var(--sidebar-w);
  padding: 56px var(--pad-side) 120px;
  min-height: 100vh;
  transition: margin-left 250ms var(--ease);
}
body[data-sidebar="collapsed"] .content { margin-left: var(--sidebar-collapsed); }

.doc-header {
  max-width: var(--content-max);
  margin: 0 auto 48px;
}
.eyebrow {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 16px;
  letter-spacing: 0.02em;
}
.doc-title {
  font-family: var(--font-serif);
  font-size: 44px;
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0 0 12px;
  color: var(--ink);
}
.doc-subtitle {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 18px;
  color: var(--ink-mute);
  margin-bottom: 24px;
  line-height: 1.4;
}
.doc-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 6px 24px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--ink-mute);
  padding: 14px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.doc-meta > div { display: flex; gap: 8px; }
.doc-meta .k {
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 10px;
  padding-top: 2px;
  min-width: 54px;
}
.doc-meta .v { color: var(--ink-soft); }
.doc-rule { display: none; }

/* -------- Sections -------- */
#sections {
  max-width: var(--content-max);
  margin: 0 auto;
}

#sections section {
  margin: 56px 0;
  position: relative;
}

#sections .section-num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

#sections h2 {
  font-family: var(--font-sans);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--ink);
  margin: 0 0 20px;
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
#sections h2::before {
  content: "";
  display: inline-block;
  flex: 0 0 10px;
  width: 10px;
  height: 10px;
  background: var(--accent);
  transform: translateY(-3px);
}
.lock-chip {
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 2px;
  vertical-align: 3px;
}

#sections h3 {
  font-family: var(--font-sans);
  font-size: 18px;
  font-weight: 600;
  margin: 32px 0 12px;
  color: var(--ink);
}
#sections h4 {
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  margin: 24px 0 10px;
  color: var(--ink-soft);
}

#sections p {
  margin: 0 0 14px;
  color: var(--ink-soft);
}
#sections p.first-paragraph::first-letter,
#sections section > p:first-of-type::first-letter {
  font-family: var(--font-serif);
  font-size: 2.2em;
  line-height: 1;
  float: left;
  padding: 4px 8px 0 0;
  color: var(--accent);
  font-weight: 600;
}

#sections ul, #sections ol {
  margin: 0 0 16px;
  padding-left: 24px;
  color: var(--ink-soft);
}
#sections li { margin-bottom: 6px; }

#sections blockquote {
  margin: 20px 0;
  padding: 8px 0 8px 20px;
  border-left: 2px solid var(--ink);
  color: var(--ink-soft);
  background: transparent;
  font-style: italic;
}

#sections code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 1px 6px;
  border: 1px solid var(--rule);
  border-radius: 2px;
}
#sections pre {
  background: var(--code-bg);
  border: 1px solid var(--rule);
  padding: 18px 20px;
  border-radius: 4px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
  margin: 20px 0;
}
#sections pre code {
  background: transparent;
  border: 0;
  padding: 0;
}

#sections table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 13px;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}
#sections thead th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  border-bottom: 0.5px solid var(--ink);
  color: var(--ink);
}
#sections tbody td {
  padding: 9px 12px;
  border-top: 1px solid var(--rule);
  color: var(--ink-soft);
  vertical-align: top;
}
#sections tbody tr:nth-child(even) { background: var(--rule-soft); }

#sections ins {
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
  padding: 0 3px;
  border-radius: 2px;
}

#sections a.anchor {
  margin-left: 8px;
  color: var(--ink-faint);
  font-weight: 400;
  font-size: 0.7em;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 200ms, transform 200ms, color 200ms;
}
#sections h2:hover .anchor,
#sections h3:hover .anchor {
  opacity: 0.7;
  transform: translateX(0);
}
#sections a.anchor:hover { color: var(--accent); opacity: 1; }

/* ==========================================================================
   Gated Section — CourseHero 风格透明渐变遮罩
   上 25% 真实可读预览 → 中 40% 渐进 blur 字还能看见轮廓
   → 下 35% 彻底渐隐到 paper，CTA 卡悬浮
   ========================================================================== */

.gated-section {
  position: relative;
  min-height: 640px;
  padding-bottom: 140px;
  overflow: hidden;
}

/* 付费内容容器 —— v4.1 回归 CourseHero 风格透明遮罩：
   · 上段 (0-40%)：.gated-preview 里的真实 ~200 字，清晰可读
   · 中段 (40-70%)：blur + mask 渐糊
   · 下段 (70-100%)：彻底渐隐到 paper，.shape-stack 灰条做视觉填充
   · 浮卡 .gated-cta 覆盖底部
   关键：DOM 里下段本来就没字（Worker 只裁上段 200 字发下来），F12 撕开遮罩也没东西可看。 */
.gated-content {
  position: relative;
  max-height: 520px;
  overflow: hidden;
  margin: 14px 0 4px;
}

/* 真实预览文字容器（视觉上半段） */
.gated-preview {
  color: var(--ink-soft);
}
.gated-preview p { margin: 0 0 14px; line-height: 1.7; }
.gated-preview h3,
.gated-preview h4 {
  font-family: var(--font-sans);
  font-weight: 600;
  margin: 22px 0 10px;
  color: var(--ink);
}
.gated-preview h3 { font-size: 17px; }
.gated-preview h4 { font-size: 14px; color: var(--ink-soft); }
.gated-preview ul,
.gated-preview ol { margin: 0 0 14px; padding-left: 22px; }
.gated-preview li { margin-bottom: 4px; }
.gated-preview table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 14px 0;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}
.gated-preview th,
.gated-preview td {
  padding: 8px 10px;
  text-align: left;
  border-top: 1px solid var(--rule);
}
/* 保险丝：预览里的 blockquote 不再吃 section 里正文的 italic */
.gated-preview blockquote {
  margin: 16px 0;
  padding: 8px 0 8px 20px;
  border-left: 2px solid var(--ink);
  color: var(--ink-soft);
  font-style: normal;
}

/* 弱 blur 层（3px）从 30% 渐入到 70%，给中段一种"有字但糊"的诱导感 */
.gated-content::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    transparent 28%,
    rgba(0,0,0,0.6) 48%,
    rgba(0,0,0,0.95) 70%,
    #000 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    transparent 28%,
    rgba(0,0,0,0.6) 48%,
    rgba(0,0,0,0.95) 70%,
    #000 100%
  );
  z-index: 1;
}

/* 强 blur 层（8px）只从 55% 命中，底部彻底糊成视觉噪声 */
.gated-content::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    transparent 55%,
    rgba(0,0,0,0.6) 72%,
    #000 90%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    transparent 55%,
    rgba(0,0,0,0.6) 72%,
    #000 90%
  );
  z-index: 2;
}

/* 灰色段落/表格/代码块占位条 —— 拼在 preview 之后，补齐下半段视觉高度 */
.shape-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 14px;
  opacity: 0.5;
}
.shape-block {
  width: 100%;
  background: var(--rule);
  border-radius: 2px;
}
.shape-block.table {
  background: repeating-linear-gradient(
    to bottom,
    var(--rule-soft) 0, var(--rule-soft) 34px,
    var(--rule) 34px, var(--rule) 35px
  );
}
.shape-block.pre {
  background: var(--code-bg);
  border-left: 2px solid var(--rule);
}
.shape-stack > .shape-block:nth-child(even) { width: 88%; }
.shape-stack > .shape-block:nth-child(3n)   { width: 94%; }
.shape-stack > .shape-block:nth-child(5n)   { width: 82%; }

html[data-theme="dark"] .shape-stack { opacity: 0.4; }

/* 底部渐隐 veil：把 shape-stack 尾部收敛到 paper */
.gated-veil {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 42%;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(255,255,255,0.5) 30%,
    rgba(255,255,255,0.9) 60%,
    var(--paper) 85%
  );
  pointer-events: none;
  transition: opacity 500ms ease;
  z-index: 3;
}
html[data-theme="dark"] .gated-veil {
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(14,17,22,0.55) 30%,
    rgba(14,17,22,0.9) 60%,
    var(--paper) 85%
  );
}

.gated-content p,
.gated-content h3,
.gated-content h4,
.gated-content li,
.gated-content td,
.gated-content blockquote {
  color: var(--ink-soft);
}
.gated-content p { margin: 0 0 14px; }
.gated-content h3 {
  font-family: var(--font-sans);
  font-size: 17px;
  font-weight: 600;
  margin: 22px 0 10px;
  color: var(--ink);
}
.gated-content h4 {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  margin: 16px 0 8px;
  color: var(--ink-soft);
}
.gated-content ul,
.gated-content ol { margin: 0 0 14px; padding-left: 22px; }
.gated-content li { margin-bottom: 4px; }
.gated-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 13px;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}
.gated-content th,
.gated-content td {
  padding: 8px 10px;
  text-align: left;
  border-top: 1px solid var(--rule);
}

/* 章节目录预览卡 */
.gated-outline {
  margin: 20px 0;
  padding: 14px 18px;
  background: var(--paper-alt);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--accent);
  border-radius: 2px;
}
.gated-outline-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}
.gated-outline ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--ink-mute);
  columns: 2;
  column-gap: 22px;
}
.gated-outline li { margin-bottom: 4px; break-inside: avoid; }

.gated-cta {
  position: absolute;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  max-width: 440px;
  width: calc(100% - 32px);
  padding: 28px 32px 26px;
  text-align: center;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-top: 2px solid var(--accent);
  box-shadow: 0 24px 48px -24px rgba(17,20,24,0.18);
  z-index: 4;
  transition: opacity 400ms ease, transform 400ms ease;
}
.gated-cta .chip {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 12px;
  margin-bottom: 14px;
  border-radius: 2px;
}
.gated-cta h3 {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--ink);
}
.gated-cta p {
  font-size: 13px;
  color: var(--ink-mute);
  margin: 0 0 20px;
}
.cta-unlock {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 11px 22px;
  background: var(--accent);
  color: #fff;
  border-radius: 3px;
  font-size: 14px;
  font-weight: 600;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms;
}
.cta-unlock .btn-sub {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.8;
  letter-spacing: 0.02em;
}
.cta-unlock:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 32px -12px rgba(179,38,30,0.45), 0 0 0 1px var(--accent-soft);
}
.cta-unlock:active { transform: translateY(0); }

body.unlocked .gated-cta,
body.unlocked .gated-veil,
body.unlocked .lock-chip {
  opacity: 0;
  pointer-events: none;
}
body.unlocked .gated-content {
  max-height: none;
}
body.unlocked .gated-content::after,
body.unlocked .gated-content::before { display: none; }
body.unlocked .gated-content,
body.unlocked .shape-stack { display: none; }

/* 演示模式条（仅线上 demo 解锁；正常付款走正文渲染路径不经过） */
.demo-banner {
  margin: 4px 0 22px;
  padding: 10px 14px;
  background: var(--accent-soft);
  border-left: 2px solid var(--accent);
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--accent);
  font-weight: 500;
}
.demo-more {
  margin-top: 24px;
  color: var(--ink-faint);
  font-size: 13px;
  text-align: center;
  padding-top: 18px;
  border-top: 1px dashed var(--rule);
}
body.unlocked .gated-cta { transform: translateX(-50%) translateY(12px); }

/* ==========================================================================
   Unlock bar (floating bottom)
   ========================================================================== */

.unlock-bar {
  position: fixed;
  left: var(--sidebar-w);
  right: 0;
  bottom: 0;
  z-index: 30;
  padding: 16px 32px calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--paper);
  border-top: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 -8px 24px -12px rgba(17,20,24,0.1);
  transition: left 250ms var(--ease);
}
body[data-sidebar="collapsed"] .unlock-bar { left: var(--sidebar-collapsed); }

.unlock-text {
  font-size: 13px;
  color: var(--ink-mute);
}
.unlock-text strong {
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
  margin-right: 4px;
}
.unlock-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* -------- Buttons -------- */
.btn-ghost {
  padding: 8px 14px;
  font-size: 13px;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 3px;
  transition: border-color 180ms, color 180ms, background 180ms;
}
.btn-ghost:hover {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--rule-soft);
}

.btn-primary {
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  border-radius: 3px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms;
  line-height: 1.3;
}
.btn-primary .btn-sub {
  font-size: 10.5px;
  font-weight: 400;
  opacity: 0.82;
  letter-spacing: 0.02em;
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px -8px rgba(179,38,30,0.4);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn-primary.btn-large {
  padding: 14px 22px;
  font-size: 15px;
  width: 100%;
}

/* ==========================================================================
   Doc footer
   ========================================================================== */

.doc-footer {
  max-width: var(--content-max);
  margin: 80px auto 0;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
}
.doc-footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  color: var(--ink-faint);
}
.doc-footer-inner a { color: var(--ink-mute); text-decoration: underline; text-underline-offset: 2px; }
.doc-footer-inner a:hover { color: var(--accent); }

/* ==========================================================================
   Modal
   ========================================================================== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17,20,24,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 0;
}

.modal-body {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 460px;
  padding: 36px 36px 28px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-top: 3px solid var(--accent);
  border-radius: 4px;
  box-shadow: 0 32px 64px -16px rgba(17,20,24,0.35);
}

.modal-grabber { display: none; }

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  color: var(--ink-mute);
  transition: background 180ms, color 180ms;
}
.modal-close:hover { background: var(--rule-soft); color: var(--ink); }

.modal-eyebrow {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.03em;
  margin-bottom: 10px;
}
.modal-body h2 {
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 600;
  margin: 0 0 10px;
  color: var(--ink);
  line-height: 1.2;
}
.modal-lede {
  font-size: 13px;
  color: var(--ink-mute);
  line-height: 1.55;
  margin: 0 0 18px;
}
.modal-list {
  list-style: none;
  padding: 0;
  margin: 0 0 22px;
  font-size: 13px;
  color: var(--ink-soft);
}
.modal-list li {
  display: flex;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--rule-soft);
}
.modal-list li:last-child { border-bottom: 0; }
.mk-yes {
  color: var(--accent);
  font-weight: 700;
  flex: 0 0 auto;
}

.price {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  margin: 18px 0 18px;
  padding: 16px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-serif);
  color: var(--ink);
}
.price .currency { font-size: 14px; color: var(--ink-mute); align-self: flex-start; padding-top: 8px; }
.price .amount { font-size: 46px; font-weight: 600; letter-spacing: -0.02em; }
.price .period { font-size: 12px; color: var(--ink-faint); letter-spacing: 0.05em; text-transform: uppercase; margin-left: 6px; }

.modal-foot {
  margin-top: 12px;
  text-align: center;
  font-size: 11px;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
}

/* ==========================================================================
   Mobile header & drawer
   ========================================================================== */

.mobile-header,
.mobile-backdrop { display: none; }

#mobile-menu-toggle { display: none; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 920px) {
  :root { --sidebar-w: 260px; --pad-side: 32px; }
}

@media (max-width: 768px) {
  :root { --pad-side: 20px; }

  body {
    font-size: 16px;
    line-height: 1.7;
  }

  /* Hide desktop sidebar toggle */
  .sidebar-toggle { display: none; }

  /* Mobile header (sticky top) */
  .mobile-header {
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 25;
    padding: 10px 16px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    background: var(--paper);
    border-bottom: 1px solid var(--rule);
    min-height: 56px;
  }
  .menu-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: var(--ink);
    cursor: pointer;
  }
  .menu-btn:hover { background: var(--rule-soft); }
  .menu-btn svg { width: 22px; height: 22px; }
  .menu-btn .icon-close { display: none; }
  #mobile-menu-toggle:checked ~ .mobile-header .menu-btn .icon-burger { display: none; }
  #mobile-menu-toggle:checked ~ .mobile-header .menu-btn .icon-close { display: block; }

  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
  }
  .mobile-brand-text { line-height: 1.2; min-width: 0; }
  .mobile-brand-co {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mobile-brand-name {
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 600;
    color: var(--ink);
  }
  .mobile-spacer { width: 44px; flex: 0 0 44px; }

  /* Sidebar → drawer */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 280ms var(--ease);
    z-index: 60;
    padding-top: calc(28px + env(safe-area-inset-top, 0px));
  }
  #mobile-menu-toggle:checked ~ .sidebar { transform: translateX(0); }

  /* Backdrop */
  .mobile-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(17,20,24,0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 280ms ease;
    z-index: 55;
  }
  #mobile-menu-toggle:checked ~ .mobile-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  /* Override collapsed state on mobile */
  body[data-sidebar="collapsed"] .sidebar {
    width: var(--sidebar-w);
    padding: calc(28px + env(safe-area-inset-top, 0px)) 24px 20px;
  }
  /* Mobile 下强制展开态：把桌面 rail 的 opacity/max-height 折叠都撤销 */
  body[data-sidebar="collapsed"] .brand-text,
  body[data-sidebar="collapsed"] .search-wrap,
  body[data-sidebar="collapsed"] .toc,
  body[data-sidebar="collapsed"] #theme-toggle .label,
  body[data-sidebar="collapsed"] .meta-line {
    opacity: 1;
    max-height: none;
    margin: revert;
    visibility: visible;
    overflow: visible;
    pointer-events: auto;
  }
  body[data-sidebar="collapsed"] .search-expand-btn { display: none; }

  /* Content resets */
  .content,
  body[data-sidebar="collapsed"] .content {
    margin-left: 0;
    padding: 32px 20px 160px;
  }

  .doc-title { font-size: 32px; }
  .doc-subtitle { font-size: 16px; }

  #sections section { margin: 40px 0; }
  #sections h2 { font-size: 22px; }
  #sections pre { font-size: 12px; padding: 14px 14px; }
  #sections table { font-size: 12px; }

  /* TOC tap targets */
  .toc-item { min-height: 44px; padding: 10px 10px 10px 8px; }

  /* Unlock bar */
  .unlock-bar,
  body[data-sidebar="collapsed"] .unlock-bar {
    left: 0; right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .unlock-text { font-size: 12px; text-align: center; }
  .unlock-actions { display: grid; grid-template-columns: auto 1fr; gap: 10px; }
  .unlock-actions .btn-ghost,
  .unlock-actions .btn-primary { min-height: 44px; }

  /* Gated CTA */
  .gated-cta { bottom: 24px; padding: 22px 22px 20px; }
  .cta-unlock { min-height: 44px; width: 100%; }

  /* Modal → bottom sheet */
  .modal {
    align-items: flex-end;
    padding: 0;
  }
  .modal-body {
    max-width: 100%;
    width: 100%;
    border-radius: 14px 14px 0 0;
    padding: 22px 22px calc(22px + env(safe-area-inset-bottom, 0px));
    border-top-width: 1px;
    animation: sheet-up 300ms var(--ease);
  }
  .modal-grabber {
    display: block;
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--rule);
    z-index: 3;
  }
  .modal-close { top: 12px; right: 12px; }
  .modal-body h2 { font-size: 22px; margin-top: 8px; }

  @keyframes sheet-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }
}

@media (max-width: 420px) {
  .doc-title { font-size: 28px; }
  .price .amount { font-size: 38px; }
}

/* ==========================================================================
   Print
   ========================================================================== */

@media print {
  .sidebar, .unlock-bar, .mobile-header, .mobile-backdrop, .modal { display: none !important; }
  .content { margin-left: 0; padding: 0; }
  body.unlocked .gated-cta, .gated-cta { display: none; }
}
