/* Vibe Coder 手册 - 小红书小工具 */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #5a5a7a;
  --text-tertiary: #8e8ea0;
  --border: #e8e8f0;
  --accent: #4f46e5;
  --accent-light: #eef2ff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --code-bg: #1e1e2e;
  --code-text: #cdd6f4;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
  --header-h: 56px;
  --toc-w: 280px;
  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ── Header ── */
.header {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  background: rgba(255,255,255,0.88);
}
.header-logo {
  font-size: 1.1rem; font-weight: 700;
  color: var(--accent); white-space: nowrap;
  letter-spacing: -0.02em;
}
.header-logo span { color: var(--text); }
.header-spacer { flex: 1; }

.btn {
  border: none; background: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  color: var(--text-secondary); transition: all .15s;
  font-size: 1.1rem;
}
.btn:hover { background: var(--accent-light); color: var(--accent); }
.btn:active { transform: scale(0.95); }

.btn-icon { width: 20px; height: 20px; }

/* ── Layout ── */
.layout { display: flex; min-height: calc(100dvh - var(--header-h)); }

/* ── Sidebar / TOC ── */
.sidebar {
  width: var(--toc-w); flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 0;
  position: sticky; top: var(--header-h);
  height: calc(100dvh - var(--header-h));
}
.sidebar-title {
  font-size: .8rem; font-weight: 600;
  color: var(--text-tertiary); text-transform: uppercase;
  letter-spacing: 0.06em; padding: 0 20px 12px;
}
.toc-list { list-style: none; }
.toc-item { }
.toc-link {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 20px; font-size: .875rem;
  color: var(--text-secondary); text-decoration: none;
  transition: all .15s; border-left: 3px solid transparent;
  line-height: 1.4;
}
.toc-link:hover { background: var(--accent-light); color: var(--accent); }
.toc-link.active {
  color: var(--accent); background: var(--accent-light);
  border-left-color: var(--accent); font-weight: 600;
}
.toc-num {
  font-size: .7rem; font-weight: 700; color: var(--text-tertiary);
  min-width: 20px; text-align: center;
}
.toc-link.active .toc-num { color: var(--accent); }

/* ── Main Content ── */
.main { flex: 1; padding: 32px 24px 64px; max-width: 760px; margin: 0 auto; width: 100%; }

/* ── Chapter ── */
.chapter { margin-bottom: 48px; scroll-margin-top: calc(var(--header-h) + 16px); }
.chapter:last-child { margin-bottom: 0; }

.chapter-header { margin-bottom: 24px; }
.chapter-number {
  display: inline-block; font-size: .75rem; font-weight: 700;
  color: var(--accent); background: var(--accent-light);
  padding: 3px 10px; border-radius: 20px; margin-bottom: 8px;
  letter-spacing: 0.04em;
}
.chapter-title {
  font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em;
  line-height: 1.3; color: var(--text);
}
.chapter-subtitle {
  font-size: .9rem; color: var(--text-tertiary); margin-top: 4px;
}

/* ── Section ── */
.section { margin-bottom: 28px; scroll-margin-top: calc(var(--header-h) + 16px); }
.section:last-child { margin-bottom: 0; }

.section-title {
  font-size: 1.15rem; font-weight: 700; margin-bottom: 12px;
  color: var(--text); letter-spacing: -0.01em;
}
.section-title .num { color: var(--accent); margin-right: 6px; }

/* ── Typography ── */
p { margin-bottom: 12px; color: var(--text-secondary); font-size: .925rem; }
p:last-child { margin-bottom: 0; }

strong { color: var(--text); font-weight: 600; }

.block-label {
  display: flex; align-items: center; gap: 6px;
  font-size: .8rem; font-weight: 600; color: var(--accent);
  margin-bottom: 8px;
}
.block-label::before {
  content: ""; display: block; width: 4px; height: 4px;
  border-radius: 50%; background: var(--accent);
}

/* ── Cards ── */
.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 20px; border: 1px solid var(--border);
  margin-bottom: 16px;
}
.card-title {
  font-size: .9rem; font-weight: 700; margin-bottom: 8px;
  color: var(--text);
}
.card p { font-size: .85rem; margin-bottom: 0; }

/* ── Highlight Box ── */
.highlight-box {
  background: var(--accent-light); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 16px;
  border-left: 4px solid var(--accent);
}
.highlight-box p { color: var(--text); font-size: .875rem; }
.highlight-box .label {
  font-size: .75rem; font-weight: 700; color: var(--accent);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.05em;
}

.danger-box {
  background: #fef2f2; border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 16px;
  border-left: 4px solid var(--danger);
}
.danger-box p { color: #7f1d1d; font-size: .875rem; }
.danger-box .label {
  font-size: .75rem; font-weight: 700; color: var(--danger);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.05em;
}

/* ── Tables ── */
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  margin-bottom: 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.table-wrap table {
  width: 100%; border-collapse: collapse; font-size: .8rem;
  white-space: nowrap;
  min-width: 420px;
}
.table-wrap th {
  background: var(--accent-light); color: var(--accent);
  font-weight: 700; text-align: left; padding: 10px 14px;
  font-size: .75rem; letter-spacing: 0.03em;
  border-bottom: 2px solid var(--border);
}
.table-wrap td {
  padding: 9px 14px; color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
.table-wrap tr:last-child td { border-bottom: none; }
.table-wrap tr:hover td { background: #fafbff; }
.table-wrap td:first-child { font-weight: 600; color: var(--text); }

/* ── Code Blocks ── */
.code-block {
  background: var(--code-bg); border-radius: var(--radius-sm);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  margin-bottom: 16px; padding: 16px;
}
.code-block pre {
  font-family: var(--font-mono); font-size: .8rem;
  line-height: 1.6; color: var(--code-text); white-space: pre;
}
.code-block code { color: var(--code-text); }

/* Syntax colors */
.code-block .kw { color: #cba6f7; }  /* keyword */
.code-block .str { color: #a6e3a1; }  /* string */
.code-block .num { color: #fab387; }  /* number */
.code-block .cmt { color: #6c7086; }  /* comment */
.code-block .fn { color: #89b4fa; }   /* function */
.code-block .prop { color: #89dceb; } /* property */
.code-block .op { color: #94e2d5; }   /* operator */

.inline-code {
  background: var(--accent-light); color: var(--accent);
  font-family: var(--font-mono); font-size: .82rem;
  padding: 2px 7px; border-radius: 4px;
}

/* ── Search ── */
.search-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4); z-index: 200;
  display: none; align-items: flex-start; justify-content: center;
  padding-top: 80px;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.search-overlay.open { display: flex; }

.search-panel {
  background: var(--surface); border-radius: var(--radius);
  width: 90%; max-width: 520px; max-height: 60vh;
  box-shadow: var(--shadow-lg); overflow: hidden;
  display: flex; flex-direction: column;
}
.search-input-wrap {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.search-input {
  flex: 1; border: none; outline: none;
  font-size: 1rem; font-family: var(--font);
  color: var(--text); background: transparent;
}
.search-input::placeholder { color: var(--text-tertiary); }
.search-results {
  overflow-y: auto; flex: 1; padding: 8px 0;
}
.search-result {
  display: block; padding: 10px 16px;
  text-decoration: none; color: var(--text-secondary);
  font-size: .85rem; border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--accent-light); }
.search-result .result-chapter {
  font-size: .72rem; color: var(--accent); font-weight: 600;
  margin-bottom: 2px;
}
.search-result .result-text { color: var(--text); }
.search-empty {
  padding: 32px 16px; text-align: center;
  color: var(--text-tertiary); font-size: .875rem;
}

/* ── Prompt Templates ── */
.prompt-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.prompt-card .scene {
  font-size: .75rem; font-weight: 700; color: var(--accent);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.04em;
}
.prompt-card .prompt-text {
  font-size: .85rem; color: var(--text);
  line-height: 1.6;
  background: #f8f9fb; border-radius: var(--radius-sm);
  padding: 10px 14px;
}

/* ── Mobile TOC Drawer ── */
.toc-backdrop {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3); z-index: 150;
  display: none;
}
.toc-backdrop.open { display: block; }

.mobile-toc {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--toc-w); max-width: 85vw;
  background: var(--surface); z-index: 151;
  transform: translateX(-100%); transition: transform .25s ease;
  overflow-y: auto; padding: 16px 0;
  box-shadow: var(--shadow-lg);
}
.mobile-toc.open { transform: translateX(0); }

/* ── Glossary filter ── */
.glossary-filter {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.glossary-filter .tag {
  padding: 4px 12px; border-radius: 20px;
  font-size: .75rem; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); color: var(--text-secondary);
  background: var(--surface); transition: all .15s;
}
.glossary-filter .tag:hover { border-color: var(--accent); color: var(--accent); }
.glossary-filter .tag.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
}

.glossary-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.glossary-item:last-child { border-bottom: none; }
.glossary-term {
  font-weight: 700; color: var(--text); font-size: .9rem;
}
.glossary-chapter {
  font-size: .7rem; color: var(--accent); font-weight: 600;
  display: inline-block; margin-left: 8px;
}
.glossary-desc { font-size: .85rem; color: var(--text-secondary); margin-top: 4px; }
.glossary-item.hidden { display: none; }

/* ── Scroll to Top ── */
.scroll-top {
  position: fixed; bottom: calc(var(--safe-bottom) + 16px);
  right: 16px; width: 40px; height: 40px;
  border-radius: 50%; background: var(--accent); color: #fff;
  border: none; cursor: pointer; display: none;
  align-items: center; justify-content: center;
  box-shadow: var(--shadow); z-index: 99;
  font-size: 1.2rem; transition: all .2s;
}
.scroll-top.show { display: flex; }
.scroll-top:active { transform: scale(0.9); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { padding: 20px 16px 48px; }
  .chapter-title { font-size: 1.3rem; }
  .section-title { font-size: 1.05rem; }
  .header-logo { font-size: 1rem; }
}

@media (min-width: 769px) {
  .toc-backdrop, .mobile-toc { display: none !important; }
}

/* Printing */
@media print {
  .header, .sidebar, .scroll-top, .toc-backdrop, .mobile-toc { display: none !important; }
  .main { padding: 0; max-width: 100%; }
  body { font-size: 12pt; }
}
