/* learn-llm 课程共享样式 — Tufte 风格，中文友好，可打印
   用法：<link rel="stylesheet" href="../assets/style.css"> */
:root {
  --bg: #fffff8;
  --fg: #111;
  --muted: #666;
  --rule: #ddd;
  --accent: #a00000;
  --accent-soft: #fbeaea;
  --ok: #1b6e3a;
  --ok-soft: #e6f4ea;
  --bad: #a33;
  --bad-soft: #fbeaea;
  --code-bg: #f4f1e8;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia,
           "Songti SC", "Noto Serif SC", "Source Han Serif SC", "Noto Serif CJK SC", "STSong", "SimSun", serif;
  --sans: -apple-system, "Segoe UI", "Helvetica Neue", Arial,
          "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", "Noto Sans Mono CJK SC", monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#151515; --fg:#e8e6df; --muted:#9a978f; --rule:#333; --accent:#ff8a80;
          --accent-soft:#3a2323; --ok:#7bd88f; --ok-soft:#1d3324; --bad:#ff8a80; --bad-soft:#3a2323; --code-bg:#1f1f1c; }
}
* { box-sizing: border-box; }
html { font-size: 17px; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--serif); line-height: 1.8;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
main, .page { max-width: 1100px; margin: 0 auto; padding: 3rem 1.5rem 5rem; }
article { width: 62%; position: relative; }
@media (max-width: 900px) { article { width: 100%; } }

/* 标题 */
h1 { font-weight: 400; font-size: 2.2rem; line-height: 1.25; margin: 0 0 .3rem; }
h2 { font-weight: 400; font-style: italic; font-size: 1.5rem; margin: 2.6rem 0 .6rem; border-top: 1px solid var(--rule); padding-top: 1.2rem; }
h3 { font-weight: 600; font-size: 1.1rem; margin: 1.8rem 0 .4rem; }
.subtitle { font-style: italic; color: var(--muted); font-size: 1.1rem; margin: 0 0 1.5rem; }
.meta { font-family: var(--sans); font-size: .8rem; color: var(--muted); letter-spacing: .02em; }
.meta a { color: inherit; }

p, li { font-size: 1rem; }
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
a:hover { border-bottom-color: var(--accent); }
strong { font-weight: 600; }
.en { font-family: var(--sans); font-size: .9em; color: var(--muted); }  /* 中文术语后的英文原名 */
hr { border: 0; border-top: 1px solid var(--rule); margin: 2rem 0; }

/* Tufte 旁注：<span class="sidenote">…</span> 放在段落内 */
.sidenote, .marginnote {
  float: right; clear: right; margin-right: -62%; width: 50%;
  margin-top: .2rem; margin-bottom: 1rem;
  font-size: .82rem; line-height: 1.5; color: var(--muted); font-family: var(--sans);
}
@media (max-width: 900px) {
  .sidenote, .marginnote { float: none; display: block; margin: .5rem 0 1rem 1rem; width: auto;
    border-left: 2px solid var(--rule); padding-left: .8rem; }
}

/* 代码 */
code, pre, kbd { font-family: var(--mono); font-size: .86em; }
code { background: var(--code-bg); padding: .1em .35em; border-radius: 3px; }
pre { background: var(--code-bg); padding: 1rem 1.1rem; border-radius: 4px; overflow-x: auto;
      line-height: 1.55; border-left: 3px solid var(--accent); }
pre code { background: none; padding: 0; font-size: .82rem; }
pre.output { border-left-color: var(--ok); }
pre.output::before { content: "预期输出 expected output"; display: block; font-family: var(--sans);
      font-size: .7rem; color: var(--muted); margin-bottom: .4rem; letter-spacing: .05em; }

/* 公式块 */
.formula { font-family: var(--serif); font-size: 1.25rem; text-align: center; margin: 1.4rem 0;
           padding: .8rem; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.formula var, var { font-style: italic; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .9em; }
.frac > span:first-child { border-bottom: 1px solid currentColor; padding: 0 .2em; }

/* 提示框 */
.callout { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: .8rem 1rem; margin: 1.4rem 0; border-radius: 0 4px 4px 0; }
.callout.ok { border-color: var(--ok); background: var(--ok-soft); }
.callout > :first-child { margin-top: 0; } .callout > :last-child { margin-bottom: 0; }
.callout .label { font-family: var(--sans); font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); display:block; margin-bottom:.2rem; }

/* 表格 */
table { border-collapse: collapse; width: 100%; margin: 1.2rem 0; font-size: .92rem; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-family: var(--sans); font-weight: 600; font-size: .8rem; color: var(--muted); border-bottom: 2px solid var(--fg); }
td code { white-space: nowrap; }

/* 折叠答案 */
details { border: 1px solid var(--rule); border-radius: 4px; padding: .6rem 1rem; margin: 1rem 0; }
details > summary { cursor: pointer; font-family: var(--sans); font-size: .92rem; font-weight: 600; }
details[open] > summary { margin-bottom: .6rem; }

/* 步骤清单 */
ol.steps { counter-reset: s; list-style: none; padding-left: 0; }
ol.steps > li { counter-increment: s; position: relative; padding-left: 2.2rem; margin-bottom: .8rem; }
ol.steps > li::before { content: counter(s); position: absolute; left: 0; top: .15rem; width: 1.5rem; height: 1.5rem;
  border-radius: 50%; background: var(--fg); color: var(--bg); font-family: var(--sans); font-size: .8rem; text-align: center; line-height: 1.5rem; }

/* 课程导航 / 页脚 */
nav.course { font-family: var(--sans); font-size: .82rem; color: var(--muted); margin-bottom: 2rem; display:flex; gap:1.2rem; flex-wrap:wrap; }
nav.course a { color: var(--muted); border: 0; } nav.course a:hover { color: var(--accent); }
footer { margin-top: 4rem; padding-top: 1rem; border-top: 1px solid var(--rule); font-family: var(--sans); font-size: .8rem; color: var(--muted); }
.badge { display:inline-block; font-family: var(--sans); font-size:.72rem; padding:.05rem .5rem; border:1px solid var(--rule); border-radius: 999px; color: var(--muted); }
.win { font-size: 1.05rem; }

/* 词汇表 */
dl.glossary dt { font-weight: 600; margin-top: 1.2rem; }
dl.glossary dt .en { font-weight: 400; margin-left: .4rem; }
dl.glossary dd { margin: .2rem 0 0 0; }
dl.glossary .avoid { font-size: .85rem; color: var(--muted); font-style: italic; }

/* 测验组件（assets/quiz.js） */
.quiz { margin: 1.5rem 0; }
.quiz-q { border-top: 1px solid var(--rule); padding: 1rem 0; }
.quiz-q .prompt { font-weight: 600; margin-bottom: .6rem; }
.quiz-q .prompt .num { font-family: var(--sans); color: var(--muted); margin-right: .4rem; font-weight: 400; }
.quiz-opts { display: grid; gap: .45rem; }
.quiz-opt { all: unset; box-sizing: border-box; cursor: pointer; display: block; width: 100%;
  font-family: var(--serif); font-size: .95rem; line-height: 1.5; padding: .55rem .8rem;
  border: 1px solid var(--rule); border-radius: 4px; background: transparent; color: var(--fg); }
.quiz-opt:hover:not([disabled]) { border-color: var(--fg); }
.quiz-opt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.quiz-opt .key { font-family: var(--sans); color: var(--muted); margin-right: .5rem; font-size: .8rem; }
.quiz-opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.quiz-opt.wrong { border-color: var(--bad); background: var(--bad-soft); text-decoration: line-through; text-decoration-color: var(--bad); }
.quiz-opt[disabled] { cursor: default; }
.quiz-feedback { margin-top: .6rem; font-size: .9rem; line-height: 1.6; display: none; }
.quiz-feedback.show { display: block; }
.quiz-feedback .verdict { font-family: var(--sans); font-weight: 600; margin-right: .3rem; }
.quiz-feedback.ok .verdict { color: var(--ok); } .quiz-feedback.no .verdict { color: var(--bad); }
.quiz-score { font-family: var(--sans); font-size: .9rem; color: var(--muted); padding-top: .8rem; border-top: 1px solid var(--rule); }
.quiz-actions { margin-top: .6rem; }
.quiz-actions button { font-family: var(--sans); font-size: .8rem; padding: .3rem .8rem; border: 1px solid var(--rule); border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; }

/* 复制按钮（assets/site.js） */
pre { position: relative; }
.copy-btn { position: absolute; top: .4rem; right: .4rem; font-family: var(--sans); font-size: .72rem;
  padding: .15rem .55rem; border: 1px solid var(--rule); border-radius: 4px; background: var(--bg);
  color: var(--muted); cursor: pointer; opacity: .85; }
.copy-btn:hover { opacity: 1; color: var(--fg); }

/* 手机 */
@media (max-width: 520px) {
  html { font-size: 16px; }
  main, .page { padding: 1.5rem 1rem 4rem; }
  h1 { font-size: 1.7rem; }
  pre code { font-size: .74rem; }
  table { display: block; overflow-x: auto; }
  .formula { font-size: 1rem; white-space: nowrap; overflow-x: auto; }
  .formula .frac { white-space: nowrap; }
}

/* 打印 */
@media print {
  .copy-btn { display: none !important; }
  :root { --bg:#fff; --fg:#000; --code-bg:#f5f5f5; }
  html { font-size: 11pt; }
  main, .page { max-width: none; padding: 0; }
  article { width: 68%; }
  .sidenote, .marginnote { margin-right: -48%; width: 42%; }
  nav.course, .quiz-actions, .no-print { display: none !important; }
  a { color: #000; border: 0; }
  article a[href^="http"]::after { content: " ⟨" attr(href) "⟩"; font-size: .75em; color: #555; word-break: break-all; }
  pre, table, .callout, .quiz-q, details { break-inside: avoid; }
  details { border: 0; padding: 0; } details > :not(summary) { display: block !important; }
  .quiz-feedback { display: block !important; }  /* 打印时显示解析 */
  h2 { break-after: avoid; }
}

/* 注意力可视化（assets/attn-viz.js） */
.attn-viz { font-family: var(--sans); border: 1px solid var(--rule); border-radius: 6px; padding: .9rem; margin: 1rem 0 1.4rem; max-width: 34rem; background: var(--bg); }
.av-controls { display: grid; gap: .55rem; margin-bottom: .8rem; }
.av-slider { font-family: var(--mono); font-size: .95rem; }
.av-dk { font-weight: 700; color: var(--accent); }
.attn-viz input[type=range] { width: 100%; height: 2rem; accent-color: var(--accent); margin: 0; touch-action: pan-y; }
.av-presets, .av-toggles { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.av-presets::before { content: "快捷："; font-size: .8rem; color: var(--muted); }
.av-btn, .av-toggle { font-family: var(--sans); font-size: .85rem; min-height: 2.2rem; padding: .25rem .75rem; border: 1px solid var(--rule); border-radius: 4px; background: transparent; color: var(--fg); cursor: pointer; }
.av-btn[aria-pressed=true], .av-toggle[aria-pressed=true] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.av-grid { display: grid; gap: 2px; }
.av-head, .av-rowhead, .av-corner { font-size: .85rem; color: var(--muted); text-align: center; align-self: center; padding: .15rem .3rem; }
.av-corner { font-size: .7rem; }
.av-cell { position: relative; aspect-ratio: 1; min-height: 2.4rem; border: 1px solid var(--rule); border-radius: 3px; background: var(--bg); padding: 0; cursor: pointer; overflow: hidden; color: var(--fg); font: inherit; }
.av-fill { position: absolute; inset: 0; background: var(--accent); transition: opacity .12s; }
.av-num { position: relative; font-family: var(--mono); font-size: .72rem; }
.av-cell.av-dark { color: var(--bg); }
.av-cell.av-masked { background: repeating-linear-gradient(45deg, transparent 0 4px, var(--rule) 4px 5px); color: var(--muted); }
.av-cell.av-sel { outline: 2px solid var(--fg); outline-offset: 1px; }
.av-stats { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .82rem; color: var(--muted); margin-top: .8rem; }
.av-stats b { color: var(--fg); font-family: var(--mono); }
.av-detail { font-size: .82rem; color: var(--muted); margin: .5rem 0 0; min-height: 2.4em; }
@media print { .attn-viz { display: none; } }
.av-cell, .av-btn, .av-toggle { -webkit-tap-highlight-color: transparent; -webkit-appearance: none; appearance: none; }
.av-cell:focus { outline: none; background: var(--bg); }
.av-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.av-cell.av-sel, .av-cell.av-sel:focus { outline: 2px solid var(--fg); outline-offset: 1px; }
.av-cell.av-sel { z-index: 1; }
