/* ============================================================
   SQL 练习场 — 界面样式
   设计基调：纸面、细线、单一墨绿强调色；不用阴影堆叠，不用渐变徽标
   ============================================================ */

:root {
  color-scheme: light;
  --paper: #faf8f3;
  --surface: #fffdf8;
  --ink: #191a17;
  --ink-2: #3e3f3a;
  --muted: #6e6f68;
  --faint: #96978e;
  --rule: #e3ded2;
  --rule-2: #efebe1;
  --accent: #2f5a4c;
  --accent-ink: #23453a;
  --accent-tint: #eaf0eb;
  --ok: #2f6a4e;
  --ok-tint: #eef4ef;
  --warn: #8a5a1f;
  --warn-tint: #f8f0e2;
  --err: #8c3a32;
  --err-tint: #f7eae6;
  --sans: "PingFang SC", "HarmonyOS Sans SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --ease: cubic-bezier(.2, 0, 0, 1);
  --t1: 120ms;
  --t2: 200ms;
  --t3: 280ms;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 80px;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.no-scroll { overflow: hidden; }

::selection { background: #d9e4dc; color: var(--ink); }

button { font-family: inherit; }
button, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 64px;
  padding: 0 32px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

.wordmark { display: flex; align-items: baseline; gap: 7px; white-space: nowrap; }
.wordmark .m {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: .18em;
  color: var(--accent);
  transform: translateY(-1px);
}
.wordmark .n { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }

.bar-note {
  font-size: 11.5px;
  color: var(--faint);
  padding-left: 16px;
  border-left: 1px solid var(--rule);
  white-space: nowrap;
}

.topbar-spacer { flex: 1; }

.meter { display: flex; align-items: center; gap: 10px; }
.meter-num { font-family: var(--mono); font-size: 11px; color: var(--faint); white-space: nowrap; }
.meter-num b { font-size: 12px; font-weight: 500; color: var(--ink); }
.meter-num i { font-style: normal; margin-left: 4px; }
.meter-track { width: 56px; height: 2px; background: var(--rule); overflow: hidden; }
.meter-track > span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 340ms var(--ease);
}

.tbtn {
  display: none;
  align-items: center;
  height: 44px;
  padding: 0 8px;
  margin: 0 -4px;
  border: 0;
  background: none;
  font-size: 12.5px;
  color: var(--ink-2);
  cursor: pointer;
  transition: color var(--t1) var(--ease);
}
.tbtn:hover { color: var(--accent); }

/* ---------------- 布局 ---------------- */
.layout {
  display: grid;
  grid-template-columns: 248px minmax(0, 700px) 264px;
  column-gap: 56px;
  align-items: start;
  max-width: 1400px;
  margin: 0 auto;
  padding: 44px 32px 140px;
}

/* ---------------- 左侧目录 ---------------- */
.sidebar {
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 116px);
  overflow-y: auto;
  padding-right: 8px;
  scrollbar-width: thin;
  scrollbar-color: #d8d2c4 transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #ded8ca; border-radius: 9px; }

.rail-cap {
  margin: 0 0 20px;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--faint);
}

.chapter { margin-bottom: 26px; }

.chapter-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-bottom: 7px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--rule-2);
}
.chapter-num { font-family: var(--mono); font-size: 9.5px; color: var(--accent); letter-spacing: .04em; }
.chapter-title { font-size: 12px; font-weight: 600; color: var(--ink-2); letter-spacing: .03em; }
.chapter-count { margin-left: auto; font-family: var(--mono); font-size: 9.5px; color: var(--faint); }

.nav-item {
  display: flex;
  align-items: baseline;
  gap: 9px;
  width: 100%;
  padding: 8px 6px 8px 10px;
  border: 0;
  border-left: 1px solid transparent;
  background: none;
  text-align: left;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  cursor: pointer;
  transition: color var(--t1) var(--ease), border-color var(--t1) var(--ease);
}
.nav-item:hover { color: var(--ink); border-left-color: var(--rule); }
.nav-item.active { color: var(--ink); font-weight: 600; border-left-color: var(--accent); }

.nav-item .mk {
  position: relative;
  flex: none;
  width: 14px;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 400;
  color: #b3ada0;
  letter-spacing: .02em;
}
.nav-item.active:not(.done) .mk { color: var(--accent); }

.nav-item.done .mk { color: transparent; }
.nav-item.done .mk::after {
  content: "";
  position: absolute;
  left: 1px;
  top: 5px;
  width: 7px;
  height: 4px;
  border-left: 1px solid var(--accent);
  border-bottom: 1px solid var(--accent);
  transform: rotate(-45deg);
}

.nav-item.locked { color: #aba69a; cursor: default; }
.nav-item.locked .mk { color: #cfc9ba; }
.nav-item.locked:hover { color: #aba69a; border-left-color: transparent; }

.nav-item .t {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-foot {
  margin-top: 34px;
  padding-top: 16px;
  border-top: 1px solid var(--rule-2);
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--faint);
}
.side-foot p { margin: 0 0 6px; }
#sess-text { font-family: var(--mono); font-size: 10.5px; letter-spacing: .04em; color: var(--muted); }

.link-reset {
  display: inline-block;
  margin-top: 8px;
  padding: 0;
  border: 0;
  background: none;
  font-size: 11px;
  color: #a8a296;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: #d5cfc1;
}
.link-reset:hover { color: var(--err); text-decoration-color: currentColor; }

/* ---------------- 正文 ---------------- */
.main { min-width: 0; }

.crumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-bottom: 14px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .12em;
  color: var(--faint);
}
.crumb .sep { color: #cdc7b8; }

.lesson-title {
  margin: 0 0 14px;
  font-size: 38px;
  font-weight: 600;
  line-height: 1.22;
  letter-spacing: -.022em;
  color: var(--ink);
}

.lede {
  margin: 0 0 34px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--rule-2);
  font-size: 15.5px;
  line-height: 1.75;
  color: var(--muted);
}
.cap {
  display: inline-block;
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
}
.lede .cap { margin-right: 10px; }

.prose { font-size: 16.5px; line-height: 1.86; color: var(--ink-2); }
.prose p { margin: 0 0 18px; }
.prose p:last-child { margin-bottom: 0; }
.prose strong { color: var(--ink); font-weight: 600; }
.prose code, .ask code {
  font-family: var(--mono);
  font-size: .84em;
  background: #f0ece2;
  color: #34362f;
  padding: 1.5px 5px;
  border-radius: 2px;
  white-space: nowrap;
}
.prose h3 { margin: 34px 0 10px; font-size: 16px; font-weight: 600; color: var(--ink); }
.prose ul { margin: 0 0 18px; padding: 0; list-style: none; }
.prose li { position: relative; margin-bottom: 7px; padding-left: 16px; }
.prose li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: .92em;
  width: 6px;
  height: 1px;
  background: var(--faint);
}

/* 旁注 */
.aside-note {
  margin: 26px 0;
  padding: 2px 0 2px 16px;
  border-left: 2px solid var(--accent);
}
.aside-note .cap { display: block; margin-bottom: 5px; }
.aside-note p { margin: 0; font-size: 14.5px; line-height: 1.75; color: var(--muted); }
.aside-note.warn { border-left-color: var(--warn); }
.aside-note.warn .cap { color: var(--warn); }
.aside-note code {
  font-family: var(--mono);
  font-size: .86em;
  background: #f1ede3;
  padding: 1px 4px;
  border-radius: 2px;
  color: #4b4d45;
}

/* 代码块 */
.codeblock {
  margin: 22px 0;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--surface);
  overflow: hidden;
}
.codeblock-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--rule-2);
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--faint);
}
.codeblock-head .acts { margin-left: auto; display: flex; gap: 2px; }
.mini-btn {
  border: 0;
  background: none;
  padding: 3px 6px;
  border-radius: 2px;
  font-size: 11px;
  color: var(--faint);
  cursor: pointer;
  transition: color var(--t1) var(--ease), background var(--t1) var(--ease);
}
.mini-btn:hover { color: var(--accent); background: var(--accent-tint); }
.codeblock pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.8;
  color: #2c2e28;
  tab-size: 2;
}
.codeblock .note {
  padding: 8px 16px;
  border-top: 1px solid var(--rule-2);
  background: #fcfaf5;
  font-size: 12px;
  line-height: 1.7;
  color: var(--faint);
}

.tok-kw { color: #2b5470; }
.tok-str { color: #3c6b4f; }
.tok-num { color: #8a5a1f; }
.tok-com { color: #a39d8e; font-style: italic; }

/* 讲解用表格 */
.mini-table-wrap {
  margin: 22px 0;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--surface);
  overflow-x: auto;
}
table.mini { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12px; }
table.mini th {
  padding: 8px 12px;
  background: #f5f2ea;
  border-bottom: 1px solid var(--rule);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
}
table.mini td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--rule-2);
  color: var(--ink-2);
  white-space: nowrap;
}
table.mini tr:last-child td { border-bottom: 0; }
table.mini td.null { color: var(--faint); font-style: italic; }
.mini-table-note {
  padding: 7px 12px;
  border-top: 1px solid var(--rule-2);
  background: #fcfaf5;
  font-size: 11px;
  color: var(--faint);
}

/* ---------------- 练习区 ---------------- */
.practice { margin-top: 56px; }

.practice-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--rule);
}
.practice-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink);
}
.practice-head .count { font-family: var(--mono); font-size: 10px; letter-spacing: .04em; color: var(--faint); }

.task { padding: 26px 0 30px; border-bottom: 1px solid var(--rule-2); }
.task:last-of-type { border-bottom: 0; }

.task-top { display: flex; align-items: baseline; gap: 10px; }
.task-idx { font-family: var(--mono); font-size: 10px; font-weight: 500; letter-spacing: .06em; color: var(--accent); }
.task-kind {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--faint);
}
.task-state { margin-left: auto; font-size: 11px; color: var(--faint); }
.task.done .task-state { color: var(--ok); }
.task.done .task-idx { color: var(--ok); }

.ask { margin: 10px 0 16px; font-size: 16.5px; line-height: 1.75; color: var(--ink); }
.ask b { font-weight: 600; color: var(--ink); }

.editor-wrap { position: relative; }
textarea.editor {
  display: block;
  width: 100%;
  min-height: 92px;
  padding: 14px 15px;
  border: 1px solid #d9d3c5;
  border-radius: 3px;
  background: var(--surface);
  color: #22241f;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.75;
  resize: none;
  outline: none;
  overflow: hidden;
  tab-size: 2;
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
textarea.editor::placeholder { color: #a8a294; font-family: var(--sans); font-size: 13px; }
textarea.editor:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 90, 76, .07);
}

.chips { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chips-label {
  margin-right: 2px;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--faint);
}
.chip {
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: transparent;
  padding: 4px 7px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  transition: color var(--t1) var(--ease), border-color var(--t1) var(--ease), background var(--t1) var(--ease);
}
.chip:hover { color: var(--accent); border-color: #c3d2c9; background: var(--accent-tint); }
.chip:active { transform: translateY(1px); }

.task-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 16px; margin-top: 14px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border: 0;
  border-radius: 3px;
  background: var(--ink);
  color: #faf8f3;
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 140ms var(--ease), transform 80ms var(--ease);
}
.btn:hover { background: var(--accent-ink); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn kbd {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 400;
  padding: 1px 4px;
  border: 1px solid rgba(250, 248, 243, .28);
  border-radius: 2px;
  color: rgba(250, 248, 243, .7);
}
.btn.ghost { height: 40px; padding: 0 2px; background: none; color: var(--muted); font-weight: 400; }
.btn.ghost:hover {
  background: none;
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-color: #c9c3b4;
}
.bar-note { margin-left: auto; font-size: 11px; color: #b3ada0; }

/* 提示 */
.hint-box {
  margin-top: 14px;
  padding: 14px 16px;
  border-left: 2px solid var(--warn);
  background: var(--warn-tint);
  font-size: 13.5px;
  line-height: 1.75;
  color: #6f5227;
}
.hint-box .h { display: flex; gap: 10px; margin-bottom: 6px; }
.hint-box .h:last-child { margin-bottom: 0; }
.hint-box .n { flex: none; width: 14px; padding-top: 3px; font-family: var(--mono); font-size: 9.5px; color: #a9853f; }
.hint-box code {
  font-family: var(--mono);
  font-size: .88em;
  background: #fdf8ee;
  border: 1px solid #ebdcc1;
  border-radius: 2px;
  padding: 1px 4px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 反馈 */
.out { margin-top: 16px; }
.verdict { padding: 12px 16px; border-left: 3px solid var(--rule); background: #f7f5ee; }
.verdict.ok { border-left-color: var(--ok); background: var(--ok-tint); }
.verdict.fail { border-left-color: var(--warn); background: var(--warn-tint); }
.verdict.err { border-left-color: var(--err); background: var(--err-tint); }

.verdict .t { margin: 0 0 3px; font-size: 13.5px; font-weight: 600; line-height: 1.5; color: var(--ink); }
.verdict.ok .t { color: #265a41; }
.verdict.fail .t { color: #7a5310; }
.verdict.err .t { color: #7d332c; }
.verdict .sub { margin: 0; font-size: 13.5px; line-height: 1.72; color: #585a52; }
.verdict .sub code {
  font-family: var(--mono);
  font-size: .88em;
  background: rgba(255, 253, 248, .7);
  border-radius: 2px;
  padding: 1px 4px;
  white-space: pre-wrap;
  word-break: break-word;
}
.acts { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 10px; }
.vbtn {
  border: 0;
  border-bottom: 1px solid rgba(47, 90, 76, .35);
  background: none;
  padding: 0;
  padding: 1px 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
}
.vbtn:hover { border-bottom-color: currentColor; color: var(--accent-ink); }

.verdict details.raw { margin-top: 8px; font-size: 11px; color: #6e6f68; }
.verdict details.raw summary { cursor: pointer; user-select: none; color: #8b8c82; }
.verdict details.raw code {
  display: inline-block;
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 10.5px;
  white-space: pre-wrap;
  word-break: break-word;
  opacity: .85;
}

/* 结果表 */
.result { margin-top: 16px; }
.result-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--faint);
}
.result-head .n { margin-left: auto; }
.result-scroll { max-height: 320px; overflow: auto; }
table.res { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12.5px; }
table.res th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 7px 14px 7px 0;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
}
table.res td {
  padding: 6px 14px 6px 0;
  border-bottom: 1px solid var(--rule-2);
  color: var(--ink-2);
  white-space: nowrap;
}
table.res tr:hover td { background: #f7f4ec; }
table.res td.null { color: var(--faint); font-style: italic; }
.result-foot { padding: 6px 0; font-family: var(--mono); font-size: 10px; color: var(--faint); }

/* 选择题 */
.quiz-opts { border-top: 1px solid var(--rule-2); }
.opt {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 13px 4px;
  border: 0;
  border-bottom: 1px solid var(--rule-2);
  background: none;
  text-align: left;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-2);
  cursor: pointer;
  transition: background var(--t1) var(--ease), color var(--t1) var(--ease);
}
.opt:hover { background: #f7f4ec; color: var(--ink); }
.opt .k { flex: none; width: 14px; padding-top: 2px; font-family: var(--mono); font-size: 10px; color: var(--faint); }
.opt.right { background: var(--ok-tint); color: #265a41; }
.opt.right .k { color: var(--ok); }
.opt.wrong { background: var(--err-tint); color: #7d332c; }
.opt.wrong .k { color: var(--err); }
.opt:disabled { cursor: default; }
.opt:disabled:hover { background: none; color: var(--ink-2); }
.opt.right:disabled:hover { background: var(--ok-tint); color: #265a41; }
.opt.wrong:disabled:hover { background: var(--err-tint); color: #7d332c; }
.quiz-fb .verdict { margin-top: 12px; }

/* 拼句子 */
.build-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
}
.build-line .ph { font-size: 12.5px; color: var(--faint); }
.build-pool { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; min-height: 32px; }
.build-pool .ph { font-size: 12px; color: var(--faint); }
.wblock {
  padding: 6px 10px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--surface);
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  transition: border-color var(--t1) var(--ease), color var(--t1) var(--ease), transform 80ms var(--ease);
}
.wblock:hover { border-color: var(--accent); color: var(--accent); }
.wblock:active { transform: translateY(1px); }
.wblock.ok { border-color: #bcd3c3; background: var(--ok-tint); color: #265a41; }
.wblock.bad { border-color: #dfc0b9; background: var(--err-tint); color: #7d332c; }
.build-fb .verdict { margin-top: 12px; }

/* 本课完成 */
.done-card {
  margin-top: 24px;
  padding: 18px 20px;
  border-left: 3px solid var(--accent);
  background: var(--accent-tint);
}
.done-card .cap { display: block; margin-bottom: 6px; }
.done-card p { margin: 0; font-size: 13.5px; line-height: 1.75; color: #33564a; }

/* 课时底部 */
.lesson-foot {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 56px;
  padding-top: 22px;
  border-top: 1px solid var(--rule);
}
.foot-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 4px;
  border: 0;
  background: none;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
  transition: color var(--t1) var(--ease);
}
.foot-btn:hover { color: var(--ink); }
.foot-btn:disabled { opacity: .38; cursor: default; }
.foot-btn.primary {
  margin-left: auto;
  padding: 0 20px;
  border-radius: 3px;
  background: var(--ink);
  color: #faf8f3;
  font-weight: 500;
  transition: background 140ms var(--ease);
}
.foot-btn.primary:hover { background: var(--accent-ink); color: #faf8f3; }
.foot-btn.primary:disabled {
  background: none;
  color: var(--faint);
  border: 1px solid var(--rule);
  font-weight: 400;
}
.foot-note { font-size: 11px; color: var(--faint); }

/* ---------------- 右侧参考 ---------------- */
.aside {
  position: sticky;
  top: 88px;
  max-height: calc(100vh - 116px);
  overflow-y: auto;
  padding-left: 24px;
  border-left: 1px solid var(--rule-2);
  scrollbar-width: thin;
  scrollbar-color: #ded8ca transparent;
}
.aside::-webkit-scrollbar { width: 4px; }
.aside::-webkit-scrollbar-thumb { background: #ded8ca; border-radius: 9px; }

.drawer-close {
  display: none;
  position: absolute;
  top: 10px;
  right: 10px;
  border: 0;
  background: none;
  padding: 8px;
  font-size: 11.5px;
  color: var(--faint);
  cursor: pointer;
}
.drawer-close:hover { color: var(--ink); }

.ref-block { margin-bottom: 34px; }
.ref-cap {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
}
.ref-cap i { margin-left: auto; font-style: normal; font-size: 9.5px; letter-spacing: 0; color: #b3ada0; }

.schema-top { display: flex; align-items: center; gap: 8px; padding: 6px 0; cursor: pointer; }
.caret {
  flex: none;
  width: 5px;
  height: 5px;
  margin-right: 2px;
  border-right: 1px solid var(--faint);
  border-bottom: 1px solid var(--faint);
  transform: rotate(-45deg);
  transition: transform 180ms var(--ease);
}
.schema-table.open .caret,
.cheat-group.open .caret { transform: rotate(45deg); }

.schema-top .tn { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.schema-top .cnt { margin-left: auto; font-family: var(--mono); font-size: 9.5px; color: var(--faint); }
.schema-top .q {
  border: 0;
  border-radius: 2px;
  background: none;
  padding: 2px 4px;
  font-family: var(--mono);
  font-size: 9px;
  color: #b3ada0;
  cursor: pointer;
}
.schema-top .q:hover { color: var(--accent); background: var(--accent-tint); }

.schema-cols { display: none; padding: 2px 0 8px 8px; }
.schema-table.open .schema-cols { display: block; }
.col-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
}
.col-row:hover { background: var(--accent-tint); color: var(--accent); }
.col-row .ty { margin-left: auto; font-size: 9px; color: #b3ada0; }
.col-row .pk { padding: 0 3px; border: 1px solid #e3d3b3; border-radius: 2px; font-size: 8px; color: #a9853f; }

.cheat-group { border-bottom: 1px solid var(--rule-2); }
.cheat-group:last-child { border-bottom: 0; }
.cheat-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
}
.cheat-items { display: none; padding: 0 0 8px; }
.cheat-group.open .cheat-items { display: block; }
.cheat-item { padding: 5px 0; cursor: pointer; }
.cheat-item code {
  display: block;
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.6;
  color: #3b4a44;
  white-space: pre-wrap;
  word-break: break-word;
}
.cheat-item span { display: block; margin-top: 1px; font-size: 10px; color: var(--faint); }
.cheat-item:hover code { color: var(--accent); }

/* ---------------- 浮层 ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(25, 26, 23, .26);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t2) var(--ease);
}
.overlay.show { opacity: 1; pointer-events: auto; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 80;
  max-width: 78vw;
  padding: 9px 14px;
  border-radius: 3px;
  background: var(--ink);
  color: #f7f4ec;
  font-size: 12.5px;
  line-height: 1.5;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity var(--t2) var(--ease), transform var(--t2) var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.loading { padding: 120px 0; font-family: var(--mono); font-size: 11px; letter-spacing: .1em; color: var(--faint); }
.spin {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 10px;
  border: 1px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 50%;
  vertical-align: -1px;
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.err-page {
  max-width: 620px;
  padding: 22px 24px;
  border-left: 2px solid var(--err);
  background: var(--err-tint);
  font-size: 14px;
  line-height: 1.8;
  color: #6f2f29;
}
.err-page code { font-family: var(--mono); font-size: 12px; background: #fffdf8; padding: 1px 4px; border-radius: 2px; }

/* ---------------- 动效 ---------------- */
@media (prefers-reduced-motion: no-preference) {
  .lesson { animation: rise var(--t3) var(--ease) both; }
  .verdict, .hint-box, .result, .done-card { animation: rise var(--t2) var(--ease) both; }

  @keyframes rise {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}

/* ---------------- 响应式 ---------------- */
@media (max-width: 1360px) {
  .layout { grid-template-columns: 248px minmax(0, 700px); justify-content: center; }
  #btn-aside { display: inline-flex; }

  .aside {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    width: min(86vw, 320px);
    max-height: none;
    padding: 24px 22px calc(28px + env(safe-area-inset-bottom));
    border-left: 1px solid var(--rule);
    background: var(--paper);
    transform: translateX(101%);
    transition: transform 240ms var(--ease);
    overscroll-behavior: contain;
  }
  .aside.open { transform: none; }
  .aside .drawer-close { display: block; }
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    justify-content: center;
    max-width: 760px;
    padding: 36px 24px 120px;
  }
  .main { width: 100%; }
  #btn-nav { display: inline-flex; }
  .bar-note { display: none; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    width: min(84vw, 300px);
    max-height: none;
    padding: 24px 22px calc(28px + env(safe-area-inset-bottom));
    border-right: 1px solid var(--rule);
    background: var(--paper);
    transform: translateX(-101%);
    transition: transform 240ms var(--ease);
    overscroll-behavior: contain;
  }
  .sidebar.open { transform: none; }
  .sidebar .rail-cap { margin-top: 4px; }
  .sidebar .drawer-close { display: block; }
  .nav-item { padding: 12px 6px 12px 10px; }
}

@media (max-width: 720px) {
  html { scroll-padding-top: 72px; }

  .topbar { height: 54px; padding: 0 16px; gap: 10px; }
  .wordmark .n { font-size: 14.5px; }
  .meter { gap: 8px; }
  .meter-track { display: none; }
  .meter-num { font-size: 10.5px; }
  .tbtn { padding: 12px 8px; font-size: 12px; }

  .layout { padding: 26px 18px 104px; }

  .lesson-title { font-size: 27px; line-height: 1.3; }
  .lede { margin-bottom: 26px; padding-bottom: 20px; font-size: 15px; }
  .prose { font-size: 16px; line-height: 1.82; }
  .prose code, .ask code { font-size: .82em; }
  .prose p { margin-bottom: 16px; }

  .practice { margin-top: 40px; }
  .task { padding: 22px 0 24px; }
  .ask { font-size: 16px; }

  textarea.editor { font-size: 16px; line-height: 1.7; min-height: 88px; }
  textarea.editor::placeholder { font-size: 13.5px; }

  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    -webkit-mask-image: linear-gradient(90deg, #000 92%, transparent);
    mask-image: linear-gradient(90deg, #000 92%, transparent);
  }
  .chips::-webkit-scrollbar { display: none; }
  .chips-label { flex: none; }
  .chip { flex: none; padding: 8px 10px; font-size: 11.5px; }

  /* 主按钮占满一行，拇指更容易够到 */
  .task-bar { gap: 10px; margin-top: 12px; }
  .task-bar .btn.run { flex: 1; justify-content: center; height: 44px; font-size: 14px; }
  .btn { padding: 0 16px; }
  .btn.ghost { padding: 0 2px; height: 44px; }
  .bar-note { display: none; }

  .verdict { padding: 12px 14px; }
  .hint-box { padding: 12px 14px; }

  .lesson-foot { flex-wrap: wrap; gap: 12px; margin-top: 40px; }
  .foot-btn.primary { order: -1; width: 100%; justify-content: center; margin-left: 0; }
  .foot-btn.primary:disabled { display: none; }
  .foot-note { margin-left: auto; }

  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); max-width: 86vw; }

  .aside, .sidebar { width: min(88vw, 320px); }
  .ref-cap { font-size: 10px; }
  .schema-top .q { padding: 6px 8px; font-size: 10px; }
  .col-row { padding: 6px 4px; font-size: 11.5px; }
  .cheat-title { padding: 10px 0; }
  .cheat-item { padding: 8px 0; }
  .mini-btn { padding: 8px 7px; margin: -5px 0; }
}
