/* style.css — Vim 修炼场 全站样式(纯静态,双主题,零依赖)
 * 规范:PLAN.md §7。变量用 rgb 三元组写法,主题切换改 data-theme 即可。
 * 演示播放器(.vdp-*)的编辑区永远是深色终端观感,不随主题变。
 */

/* ===== 主题变量 ===== */
:root,
[data-theme='light'] {
  color-scheme: light;
  --bg-base: 238 235 227;      /* #eee3e3 羊皮纸 */
  --bg-card: 249 246 239;      /* #f9f6ef */
  --bg-elev: 228 224 212;      /* #e4e0d4 */
  --border-subtle: 216 210 195;
  --border-strong: 176 168 148;
  --fg: 43 39 33;              /* 深墨 */
  --fg-muted: 122 114 101;
  --accent: 62 108 79;         /* #3e6c4f 深绿 */
  --accent-weak: 62 108 79;    /* 用于半透明底 */
  --warn: 164 92 42;
  --chip-bg: 216 228 205;
  --chip-fg: 30 74 46;
  --shadow: 0 1px 3px rgba(43, 39, 33, 0.08), 0 4px 14px rgba(43, 39, 33, 0.06);
  /* 键帽:浅色主题下要用「比页面亮的底 + 深描边」才够醒目(用户反馈) */
  --kbd-bg: 255 253 246;
  --kbd-border: 125 115 96;
  /* 图示高亮盒(模式地图 NORMAL 等):浅色下必须实底,16% 透明绿太淡看不清(用户反馈) */
  --fig-hot: 196 223 205;
}

[data-theme='dark'] {
  color-scheme: dark;
  --bg-base: 13 16 18;         /* #0d1012 终端黑 */
  --bg-card: 20 24 27;
  --bg-elev: 28 33 37;
  --border-subtle: 44 51 56;
  --border-strong: 66 76 83;
  --fg: 224 231 234;
  --fg-muted: 138 152 160;
  --accent: 88 199 138;        /* #58c68a 终端绿 */
  --accent-weak: 88 199 138;
  --warn: 233 152 78;
  --chip-bg: 32 48 38;
  --chip-fg: 140 214 168;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 6px 18px rgba(0, 0, 0, 0.35);
  /* 深色主题键帽保持原样(用户确认看得清) */
  --kbd-bg: 20 24 27;
  --kbd-border: 66 76 83;
  /* 图示高亮盒:深色维持原先「16% 绿叠加深底」的观感,换算成等价实底 */
  --fig-hot: 32 53 46;
}

/* ===== 基础 ===== */
* {
  box-sizing: border-box;
  -webkit-user-select: text;
  user-select: text;
}
html {
  scroll-behavior: smooth;
  -webkit-user-select: text;
  user-select: text;
}
body {
  margin: 0;
  background: rgb(var(--bg-base));
  color: rgb(var(--fg));
  font: 17px/1.8 -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  -webkit-font-smoothing: antialiased;
  /* 用户反馈:全文必须可选中、可复制 */
  -webkit-user-select: text;
  user-select: text;
  transition: background-color 0.25s ease, color 0.25s ease;
}
a { color: rgb(var(--accent)); text-decoration: none; }
a:hover { text-decoration: underline; }
/* 选中高亮用实色,不走 CSS 变量:rgba(var(--x), a) 在 Safari 里是非法语法,高亮会消失 */
::selection { background: #7dba90; color: #142018; }
[data-theme='dark'] ::selection { background: #2f6b4a; color: #e8f5ec; }

code, kbd, pre, .vdp-editor, .vdp-status, .kcap {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, 'Cascadia Code', monospace;
}

/* ===== 顶栏 ===== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 22px;
  background: rgba(var(--bg-base), 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgb(var(--border-subtle));
}
.topbar .brand {
  font-weight: 700; letter-spacing: 0.02em; color: rgb(var(--fg));
  display: flex; align-items: center; gap: 8px;
}
.topbar .brand:hover { text-decoration: none; }
.brand-logo {
  width: 22px; height: 22px; border-radius: 6px;
  background: rgb(var(--accent)); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; font-family: ui-monospace, Menlo, monospace;
}
.topbar .spacer { flex: 1; }
.theme-toggle {
  border: 1px solid rgb(var(--border-strong)); background: rgb(var(--bg-card));
  color: rgb(var(--fg)); border-radius: 8px; padding: 4px 12px; cursor: pointer;
  font-size: 14px; line-height: 1.4;
}
.theme-toggle:hover { border-color: rgb(var(--accent)); }

/* ===== 布局 ===== */
.wrap { max-width: 940px; margin: 0 auto; padding: 28px 22px 80px; }

/* ===== 首页 ===== */
.hero { padding: 46px 0 26px; }
.hero h1 { font-size: 36px; margin: 0 0 10px; line-height: 1.3; }
.hero .sub { color: rgb(var(--fg-muted)); font-size: 18px; max-width: 660px; }
.hero .badges { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  font-size: 12.5px; padding: 3px 12px; border-radius: 999px;
  border: 1px solid rgb(var(--border-strong)); color: rgb(var(--fg-muted));
  background: rgb(var(--bg-card));
}

.progress-panel {
  display: flex; align-items: center; gap: 14px;
  background: rgb(var(--bg-card)); border: 1px solid rgb(var(--border-subtle));
  border-radius: 12px; padding: 12px 18px; margin: 18px 0 34px; box-shadow: var(--shadow);
}
.progress-track { flex: 1; height: 8px; border-radius: 999px; background: rgb(var(--bg-elev)); overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: 999px; background: rgb(var(--accent)); transition: width 0.4s ease; }
.progress-text { font-size: 13.5px; color: rgb(var(--fg-muted)); white-space: nowrap; }

.module { margin-top: 38px; }
.module > h2 { font-size: 19px; margin: 0 0 4px; }
.module > .module-sub { color: rgb(var(--fg-muted)); font-size: 14px; margin: 0 0 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(252px, 1fr)); gap: 14px; }
.card {
  display: block; background: rgb(var(--bg-card)); border: 1px solid rgb(var(--border-subtle));
  border-radius: 12px; padding: 16px 18px; color: rgb(var(--fg));
  box-shadow: var(--shadow); position: relative;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
a.card:hover { transform: translateY(-2px); border-color: rgb(var(--accent)); text-decoration: none; }
.card .ch-no {
  font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: rgb(var(--fg-muted));
  letter-spacing: 0.08em;
}
.card .ch-title { font-weight: 700; margin: 2px 0 6px; font-size: 17.5px; }
.card .ch-desc { font-size: 14px; color: rgb(var(--fg-muted)); line-height: 1.65; }
.card .ch-meta { margin-top: 10px; display: flex; gap: 8px; align-items: center; font-size: 12px; color: rgb(var(--fg-muted)); }
.card.is-read::after {
  content: '✓ 已读'; position: absolute; top: 12px; right: 12px;
  font-size: 11.5px; color: rgb(var(--accent)); border: 1px solid rgb(var(--accent));
  border-radius: 999px; padding: 1px 8px;
}
.card.is-todo { opacity: 0.55; }

.site-footer { margin-top: 60px; padding-top: 18px; border-top: 1px solid rgb(var(--border-subtle)); color: rgb(var(--fg-muted)); font-size: 13px; }

/* ===== 章节页 ===== */
article.chapter > header.ch-header { padding: 30px 0 6px; }
.ch-kicker {
  font-family: ui-monospace, Menlo, monospace; font-size: 13px; letter-spacing: 0.12em;
  color: rgb(var(--accent)); font-weight: 700;
}
.ch-header h1 { font-size: 30px; margin: 6px 0 8px; line-height: 1.35; }
.ch-meta-line { color: rgb(var(--fg-muted)); font-size: 14px; }

/* 小节标题:用户反馈「章节间距太窄、标题要更大更显眼」→ 大字号 + 加粗 + 拉大段距 */
article.chapter h2 {
  font-size: 25px; font-weight: 800;
  margin: 70px 0 16px; padding: 2px 0 2px 14px;
  border-left: 5px solid rgb(var(--accent)); line-height: 1.45;
}
article.chapter h3 { font-size: 19px; margin: 34px 0 12px; }
/* 目录锚点跳转时,标题别被吸顶的顶栏遮住 */
article.chapter h2, article.chapter h3 { scroll-margin-top: 84px; }
article.chapter p { margin: 12px 0; }
article.chapter ul, article.chapter ol { padding-left: 26px; }
article.chapter li { margin: 5px 0; }
strong { color: rgb(var(--fg)); }

/* 按键与行内代码 */
kbd {
  display: inline-block; min-width: 1.7em; text-align: center;
  padding: 1px 8px; margin: 0 1.5px;
  font-size: 0.86em; line-height: 1.55;
  background: rgb(var(--kbd-bg));
  border: 1px solid rgb(var(--kbd-border)); border-bottom-width: 3px;
  border-radius: 6px;
}
kbd.escape { border-color: rgb(var(--warn)); color: rgb(var(--warn)); }
code {
  background: rgba(var(--accent-weak), 0.14); color: rgb(var(--chip-fg));
  border-radius: 5px; padding: 1.5px 6px; font-size: 0.86em;
}
pre.code-block {
  background: rgb(var(--bg-elev)); border: 1px solid rgb(var(--border-subtle));
  border-radius: 10px; padding: 14px 16px; overflow-x: auto; line-height: 1.7;
  font-size: 14.5px;
}
pre.code-block code { background: none; padding: 0; color: rgb(var(--fg)); font-size: inherit; }

/* 按键表 */
table.ktable { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 15.5px; }
table.ktable th, table.ktable td { border: 1px solid rgb(var(--border-subtle)); padding: 8px 13px; text-align: left; vertical-align: top; }
table.ktable th { background: rgba(var(--accent-weak), 0.12); font-weight: 700; }
table.ktable tr:nth-child(even) td { background: rgba(var(--bg-elev), 0.5); }

/* 提示框 */
.callout { border-radius: 10px; padding: 13px 17px; margin: 16px 0; border: 1px solid; font-size: 15.5px; }
.callout.tip { border-color: rgba(var(--accent-weak), 0.5); background: rgba(var(--accent-weak), 0.09); }
.callout.warn { border-color: rgba(var(--warn), 0.55); background: rgba(var(--warn), 0.08); }
.callout .co-title { font-weight: 700; margin-right: 6px; }

/* 图示 */
figure.fig { margin: 22px 0; text-align: center; }
figure.fig .fig-canvas {
  background: rgb(var(--bg-card)); border: 1px solid rgb(var(--border-subtle));
  border-radius: 12px; padding: 14px; box-shadow: var(--shadow);
}
figure.fig svg { width: 100%; height: auto; max-width: 720px; display: block; margin: 0 auto; }
figure.fig figcaption { font-size: 14px; color: rgb(var(--fg-muted)); margin-top: 10px; }
.fig-box { fill: rgb(var(--bg-elev)); stroke: rgb(var(--border-strong)); stroke-width: 1.5; }
.fig-box-hot { fill: rgb(var(--fig-hot)); stroke: rgb(var(--accent)); stroke-width: 2; }
.fig-name { font: 700 16px ui-monospace, Menlo, monospace; fill: rgb(var(--fg)); }
.fig-sub { font: 13px -apple-system, 'PingFang SC', sans-serif; fill: rgb(var(--fg-muted)); }
.fig-key { font: 600 13.5px ui-monospace, Menlo, monospace; fill: rgb(var(--accent)); }
.fig-arrow { stroke: rgb(var(--border-strong)); stroke-width: 1.6; fill: none; marker-end: url(#fig-arrowhead); }

/* 语法公式条(动词+数量+名词) */
.grammar-strip { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 18px 0; }
.gs-box {
  border-radius: 10px; padding: 8px 16px; text-align: center; border: 1.5px solid;
}
.gs-box .gs-key { font: 700 20px ui-monospace, Menlo, monospace; display: block; }
.gs-box .gs-name { font-size: 12px; opacity: 0.85; }
.gs-verb { border-color: #d17265; background: rgba(209, 114, 101, 0.12); color: #c85a4d; }
.gs-count { border-color: #c9a35e; background: rgba(201, 163, 94, 0.13); color: #a8813c; }
.gs-noun { border-color: #5f97c9; background: rgba(95, 151, 201, 0.12); color: #4a7fae; }
[data-theme='dark'] .gs-verb { color: #eb8f81; }
[data-theme='dark'] .gs-count { color: #d9b269; }
[data-theme='dark'] .gs-noun { color: #7ab3e6; }
.gs-eq { font-size: 20px; color: rgb(var(--fg-muted)); }
.gs-result { font-size: 14.5px; color: rgb(var(--fg)); }

/* 模式徽章 */
.mode-badge {
  display: inline-block; font: 700 12px ui-monospace, Menlo, monospace;
  padding: 2px 10px; border-radius: 6px; letter-spacing: 0.05em;
}
.mb-normal { color: #3fb950; background: rgba(63, 185, 80, 0.13); }
.mb-insert { color: #ffa657; background: rgba(255, 166, 87, 0.14); }
.mb-visual { color: #6cb6ff; background: rgba(108, 182, 255, 0.14); }
.mb-cmd { color: #d2a8ff; background: rgba(210, 168, 255, 0.14); }

/* 练习 / 陷阱 / IDE 差异 / 速记 */
section.drills details {
  background: rgb(var(--bg-card)); border: 1px solid rgb(var(--border-subtle));
  border-radius: 10px; padding: 4px 16px; margin: 10px 0;
}
section.drills summary { cursor: pointer; font-weight: 600; padding: 10px 0; }
section.drills details .answer { border-top: 1px dashed rgb(var(--border-subtle)); padding-top: 8px; margin-bottom: 10px; }

section.pitfalls .callout { background: rgba(var(--warn), 0.07); }

section.ide-notes .ide-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 14px 0; }
.ide-col { background: rgb(var(--bg-card)); border: 1px solid rgb(var(--border-subtle)); border-radius: 12px; padding: 14px 18px; }
.ide-col h4 { margin: 0 0 8px; font-size: 16px; }
.ide-col ul { padding-left: 20px; margin: 0; font-size: 15px; }

section.recap table.ktable td:first-child { white-space: nowrap; }

/* 章末:已读按钮 + 上下章 */
.ch-footer { margin-top: 54px; padding-top: 20px; border-top: 1px solid rgb(var(--border-subtle)); }
.read-toggle {
  display: block; width: 100%; padding: 11px; border-radius: 10px; cursor: pointer;
  font-size: 15px; font-weight: 600;
  background: rgb(var(--bg-card)); color: rgb(var(--fg));
  border: 1.5px solid rgb(var(--border-strong));
}
.read-toggle:hover { border-color: rgb(var(--accent)); }
.read-toggle.is-on { background: rgba(var(--accent-weak), 0.14); border-color: rgb(var(--accent)); color: rgb(var(--accent)); }
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; }
.pager a, .pager span.disabled {
  flex: 1; text-align: center; padding: 10px 8px; border-radius: 10px;
  border: 1px solid rgb(var(--border-subtle)); background: rgb(var(--bg-card)); font-size: 14px;
}
.pager span.disabled { color: rgb(var(--fg-muted)); opacity: 0.55; }

/* ===== 演示播放器 vim-player ===== */
.demo-slot { margin: 22px 0; min-height: 60px; }
.vdp {
  border: 1px solid rgb(var(--border-strong)); border-radius: 12px; overflow: hidden;
  background: rgb(var(--bg-card)); box-shadow: var(--shadow);
}
.vdp:focus-visible { outline: 2px solid rgb(var(--accent)); outline-offset: 2px; }
.vdp-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid rgb(var(--border-subtle));
}
.vdp-title { font-weight: 700; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vdp-count { font: 12.5px ui-monospace, Menlo, monospace; color: rgb(var(--fg-muted)); }
.vdp-ctrls { display: flex; gap: 6px; }
.vdp-btn {
  border: 1px solid rgb(var(--border-subtle)); background: rgb(var(--bg-elev));
  color: rgb(var(--fg)); border-radius: 7px; padding: 2px 10px; cursor: pointer;
  font-size: 13.5px; line-height: 1.5; min-width: 34px;
}
.vdp-btn:hover { border-color: rgb(var(--accent)); color: rgb(var(--accent)); }

/* 编辑区:永远深色 */
.vdp-editor {
  background: #0d1117; padding: 10px 0 12px; overflow-x: auto;
  font-size: 14.5px; line-height: 1.75; color: #e6edf3;
  cursor: text; /* 明示演示代码可选中复制 */
}
.vdp-row { display: flex; padding-right: 16px; }
.vdp-row.vdp-flash { animation: vdp-flash 1s ease-out; }
@keyframes vdp-flash {
  0% { background: rgba(255, 196, 66, 0.22); }
  100% { background: transparent; }
}
.vdp-ln {
  flex: none; width: 3.2ch; text-align: right; padding-right: 14px;
  color: #484f58; /* 行号同样放开可选中(用户要求去掉一切选中限制) */
}
.vdp-tx { white-space: pre; }
/* 语法高亮(github-dark 气质) */
.tk-kw { color: #ff7b72; }
.tk-str { color: #a5d6ff; }
.tk-num { color: #79c0ff; }
.tk-com { color: #8b949e; }
.tk-fn { color: #d2a8ff; }
/* 光标与选区 */
.vcur {
  background: #e6edf3; color: #0d1117;
  animation: vdp-blink 1.1s steps(1) infinite;
}
.vcur-beam { background: rgba(230, 237, 243, 0.18); animation: none; border-left: 2px solid #e6edf3; }
@keyframes vdp-blink { 0%, 60% { opacity: 1; } 61%, 100% { opacity: 0.25; } }
.vsel { background: rgba(88, 166, 255, 0.30); border-radius: 2px; }

/* 状态栏 */
.vdp-status {
  display: flex; align-items: center; gap: 14px;
  background: #161b22; border-top: 1px solid #21262d;
  padding: 5px 16px; font-size: 12.5px; color: #8b949e; min-height: 29px;
}
.vdp-mode { font-weight: 700; }
.m-normal { color: #3fb950; }
.m-insert { color: #ffa657; }
.m-visual { color: #6cb6ff; }
.m-replace { color: #ff7b72; }
.vdp-cmdline { color: #e6edf3; font-weight: 600; }
.vdp-pending { color: #e6edf3; }
.vdp-lang { margin-left: auto; text-transform: uppercase; letter-spacing: 0.08em; }

/* 按键流 + 解说 */
.vdp-keys { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 14px 2px; min-height: 36px; }
.kcap {
  font-size: 12.5px; padding: 2px 10px; border-radius: 6px;
  border: 1px solid rgb(var(--kbd-border)); border-bottom-width: 2.5px;
  background: rgb(var(--kbd-bg)); color: rgb(var(--fg-muted));
}
.kcap.hit { color: rgb(var(--fg)); }
.kcap.on { background: rgb(var(--accent)); border-color: rgb(var(--accent)); color: #fff; }
.vdp-note { padding: 6px 16px 13px; font-size: 15px; min-height: 2.4em; }
.vdp-note::before { content: '▸ '; color: rgb(var(--accent)); font-weight: 700; }
.vdp-error { padding: 14px; color: rgb(var(--warn)); font-size: 14px; }

/* ===== 侧边目录(用户反馈:左侧 + 贴近正文 + 贴片卡片观感) ===== */
.toc {
  position: fixed; width: 200px; top: 110px;
  right: calc(50% + 490px); /* 锚定居中正文栏:目录右缘 = 正文左边界 - 20px 间隙 */
  font-size: 13px; line-height: 1.5; max-height: 70vh; overflow-y: auto;
  background: rgb(var(--bg-card)); border: 1px solid rgb(var(--border-subtle));
  border-radius: 12px; padding: 12px 6px 12px 10px; box-shadow: var(--shadow);
}
.toc .toc-title { font-weight: 700; color: rgb(var(--fg-muted)); letter-spacing: 0.06em; margin: 0 4px 8px; }
.toc a {
  display: block; color: rgb(var(--fg-muted)); padding: 3px 8px 3px 10px;
  border-left: 2px solid rgb(var(--border-subtle)); border-radius: 0 6px 6px 0;
}
.toc a:hover {
  color: rgb(var(--accent)); border-color: rgb(var(--accent));
  background: rgba(var(--accent-weak), 0.08); text-decoration: none;
}
/* 目录贴正文栏(940px 居中)左侧;视口 <1420px 放不下则隐藏 */
@media (max-width: 1419px) { .toc { display: none; } }

/* ===== 响应式 ===== */
@media (max-width: 800px) {
  section.ide-notes .ide-grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 27px; }
  article.chapter h1 { font-size: 25px; }
}

/* ===== 打印 ===== */
@media print {
  .topbar, .toc, .vdp-ctrls, .read-toggle, .pager { display: none !important; }
  body { background: #fff; }
  .vdp { box-shadow: none; }
}
