/*
  色：六色；夜间值是日间值的 L* 换成 100 − L*，色相不变
  字：正文 --sans（Margins Sans 与思源黑体），交互图里小一号；副文（注、图注、元信息、留言）--serif（Alegreya 与朱雀仿宋）；字号 --small : 1rem : --heading : 标题 = 3/4 : 1 : 5/4 : 2
  字体随网页发布（构建时只取本站用到的字），不依赖读者的系统；唯一的例外是留言的输入框，用系统字体
  距：行高 --line 为字号的 1.75 倍（中文常用 1.5～2 倍，取中）；竖向用 --line 的 1/4、1/2、1、2 倍；副文成行处一行高 --row = 2 --small；横向用 em；线一律 1px
  版：纸宽 --width = 屏宽 − 2rem，最宽 45rem；页边 --margin = --width / 9，连续缩放、没有断点；屏宽不足 --narrowest（360px，常见手机里最窄的）时不再缩，横向滚动
  件：带框的按钮（.boxed）连框高 --row，框内左右各留半个字，并排时相隔 1/4 字；悬停时字与框转朱红，选中时朱红底、纸色字
  动：一律 --ease（--duration = 0.25 秒，界面动效常用 0.2～0.3 秒，取中；缓入缓出）
  层：base（变量与初始样式）、katex（公式）、page（各页的 page.css）、site（全站）、state（悬停、选中、隐藏、静止）；后层胜前层，不看具体程度；page 在 site 之前，单页改不动全站的规矩
  选定的值（观感，无从推导）：纸高至少为纸宽的 1.5 倍；会折行的副文行高 1.5；书签宽 4rem；交互图在脚本运行前按 16 : 9 留位；交互图并排行每栏至少 16 字；图例色带长 6 字；留言的称呼、邮箱栏至少 12 字宽
*/
@layer base, katex, page, site, state;

/* 换页：浏览器整页导航，新旧两页的画面整张交叉淡化（--duration）。两页的海是同一刻的海、纸在同一处，交叉淡化后看上去不动，只有字过渡 */
@view-transition { navigation: auto; }

@layer base {
  :root {
    --backdrop: light-dark(#f1f4f9, #0b0e13);
    --paper: light-dark(#fff, #000);
    --ink: light-dark(#000, #fff);
    --muted: light-dark(#6a6a6a, #848484);
    --rubric: light-dark(#c93016, #e3492a);
    --blue: light-dark(#1963e4, #5080ff);
    --small: .75rem;
    --heading: 1.25rem;
    --line: 1.75rem;
    --row: calc(2 * var(--small));
    --narrowest: 22.5rem;
    --field: 12em;
    --duration: .25s;
    --ease: var(--duration) ease-in-out;
    color-scheme: light;
  }
  :root[data-theme="dark"] { color-scheme: dark; }
  /* 字体：英文在前、中文在后，各取所长；字体文件到之前最多空着 3 秒（block），免得先用系统字体排一遍再跳 */
  @font-face { font-family: "Margins Sans"; src: url(/assets/fonts/margins-sans.woff2?v=38d0ea60) format("woff2"); font-weight: 200 900; font-display: block; }
  @font-face { font-family: "Margins Sans"; src: url(/assets/fonts/margins-sans-italic.woff2?v=92c36ff3) format("woff2"); font-weight: 200 900; font-style: italic; font-display: block; }
  @font-face { font-family: Alegreya; src: url(/assets/fonts/alegreya.woff2?v=d33c1b7c) format("woff2"); font-weight: 400 900; font-display: block; }
  @font-face { font-family: Alegreya; src: url(/assets/fonts/alegreya-italic.woff2?v=6d2b66a7) format("woff2"); font-weight: 400 900; font-style: italic; font-display: block; }
  @font-face { font-family: "Noto Sans SC"; src: url(/assets/fonts/noto-sans-sc.woff2?v=7e7ff345) format("woff2"); font-weight: 100 900; font-display: block; }
  @font-face { font-family: "Zhuque Fangsong"; src: url(/assets/fonts/zhuque-fangsong.woff2?v=42098162) format("woff2"); font-display: block; }
  /* 中文的引号、破折号、省略号用中文字体的全角字形（同一个文件，不另下载）；按元素的语言定，中文页里标了别的语言的字（如英文副标题、法文题记）仍用西文标点 */
  @font-face { font-family: "Zh Sans"; src: url(/assets/fonts/noto-sans-sc.woff2?v=7e7ff345) format("woff2"); font-weight: 100 900; unicode-range: U+2014, U+2018-2019, U+201C-201D, U+2026; font-display: block; }
  @font-face { font-family: "Zh Serif"; src: url(/assets/fonts/zhuque-fangsong.woff2?v=42098162) format("woff2"); unicode-range: U+2014, U+2018-2019, U+201C-201D, U+2026; font-display: block; }
  :root, [lang]:not(:lang(zh-CN)) { --sans: "Margins Sans", "Noto Sans SC", sans-serif; --serif: Alegreya, "Zhuque Fangsong", serif; }
  :lang(zh-CN) { --sans: "Zh Sans", "Margins Sans", "Noto Sans SC", sans-serif; --serif: "Zh Serif", Alegreya, "Zhuque Fangsong", serif; }

  * { box-sizing: border-box; margin: 0; padding: 0; }
  html { min-width: var(--narrowest); scrollbar-gutter: stable; background: var(--backdrop); }  /* 总留滚动条的位置，有无滚动条的页面之间换页时不左右跳 */
  body { font: 1rem/var(--line) var(--sans); font-synthesis: weight; color: var(--ink); overflow-wrap: break-word; -webkit-font-smoothing: antialiased; }
  a, button, summary { color: inherit; text-decoration: underline 1px; text-underline-offset: .25em; touch-action: manipulation; }
  button, summary { font: inherit; text-align: inherit; background: none; border: 0; cursor: pointer; list-style: none; }
  summary::-webkit-details-marker { display: none; }
  :focus-visible { outline: 1px solid var(--rubric); outline-offset: .25em; }
  img { display: block; max-width: 100%; height: auto; }
  sup { line-height: 0; }
  b { color: var(--rubric); }
  blockquote { padding-left: 1em; border-left: 1px solid var(--rubric); }
  h1 { font-size: 2rem; line-height: calc(1.5 * var(--line)); font-weight: 400; }
  h2, h3 { font-size: inherit; font-weight: 400; }
}

@layer site {
  /* ── 通用 ── */
  .sub, .device, .meta, .tag, time, .date, .contents .list, header blockquote, .note, figcaption, .comment { font-family: var(--serif); }
  .note, figcaption { line-height: 1.5; }  /* 会折行的副文 */
  .sub:lang(en), .device:lang(en) { font-style: italic; }
  .trap { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .eqn { -webkit-user-select: none; user-select: none; }
  /* 脚本没运行（没有 data-theme）时，藏起要靠脚本的按钮与只含这种按钮的菜单（订阅、分享）；留言的表单照常可用 */
  html:not([data-theme]) :is([data-act], .pop), .nosea [data-act=sea], .noshare .menu > [data-act=share] { display: none; }
  #sea { position: fixed; inset: 0; width: 100%; height: 100%; }
  .icon { flex: none; width: 1em; height: 1em; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation-duration: var(--duration); animation-timing-function: ease-in-out; }  /* 换页与昼夜切换（site.js）的过渡 */

  /* 读者填写的框（.field：留言）：框与带框的按钮同高，左右留半个字，灰框；悬停转墨、聚焦转朱红见 state 层
     读者打的字可能是本站字体里没有的（字体只取了本站用到的字），所以整个框用系统字体，免得一行里两种字体夹杂 */
  .field { width: 100%; padding: 0 .5em; font: inherit; font-family: system-ui; line-height: calc(var(--row) - 2px); color: var(--ink); background: var(--paper); border: 1px solid var(--muted); border-radius: 0; resize: none; }
  /* 带框的按钮：关于页的联系方式、留言的寄出、交互图的复位、下载与编号按钮，由构建与引擎贴上 .boxed。一律墨框；悬停、选中、停用见 state 层 */
  .boxed { padding: 0 .5em; font-size: var(--small); line-height: calc(var(--row) - 2px); text-align: center; text-decoration: none; white-space: nowrap; color: var(--ink); border: 1px solid var(--ink); }

  /* ── 纸 ── */
  /* 四角十字标出版心，下边距是上边距的两倍 */
  #page {
    --width: clamp(var(--narrowest) - 2rem, 100vw - 2rem, 45rem);
    --margin: calc(var(--width) / 9);
    position: relative;
    z-index: 1;
    width: var(--width);
    margin: 0 auto calc(2 * var(--margin));
  }
  .paper {
    --rule: linear-gradient(var(--muted), var(--muted));
    --left: calc(var(--margin) / 2);
    --right: calc(100% - var(--margin) / 2);
    --top: calc(var(--margin) / 2);
    --bottom: calc(100% - var(--margin));
    --arm: min(var(--line), var(--margin) / 2);
    --half-arm: calc(var(--arm) / 2);
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: calc(var(--width) * 1.5);
    padding: var(--margin) var(--margin) calc(2 * var(--margin));
    outline: 1px solid var(--muted);
    outline-offset: -1px;
    background:
      var(--rule) calc(var(--left) - var(--half-arm)) var(--top) / var(--arm) 1px no-repeat, var(--rule) var(--left) calc(var(--top) - var(--half-arm)) / 1px var(--arm) no-repeat,
      var(--rule) calc(var(--right) + var(--half-arm)) var(--top) / var(--arm) 1px no-repeat, var(--rule) var(--right) calc(var(--top) - var(--half-arm)) / 1px var(--arm) no-repeat,
      var(--rule) calc(var(--left) - var(--half-arm)) var(--bottom) / var(--arm) 1px no-repeat, var(--rule) var(--left) calc(var(--bottom) + var(--half-arm)) / 1px var(--arm) no-repeat,
      var(--rule) calc(var(--right) + var(--half-arm)) var(--bottom) / var(--arm) 1px no-repeat, var(--rule) var(--right) calc(var(--bottom) + var(--half-arm)) / 1px var(--arm) no-repeat,
      var(--paper);
  }

  /* ── 纸上方 ── */
  /* 书签与工具：工具总在上一行、书签在下一行，不随屏宽与语言变；语言切换在纸的右上角 */
  .bar, .langs { font-size: var(--small); line-height: var(--row); white-space: nowrap; }
  .bar { position: relative; z-index: 2; display: flex; flex-wrap: wrap-reverse; min-height: var(--margin); padding-left: calc(var(--margin) / 2); }
  .bar a, .langs a { -webkit-user-drag: none; }
  .tabs, .tools { display: flex; align-self: flex-start; }
  .tabs { gap: 1px; }
  .tabs a { width: 4rem; text-align: center; text-decoration: none; color: var(--muted); background: var(--paper); }
  .tools { position: relative; flex-basis: 100%; justify-content: flex-end; gap: 1em; margin-bottom: calc(var(--line) / 4); }
  .tools > * { color: var(--muted); }
  /* 语言切换：下划线压在右上角十字的横线上。下划线在基线下 .25em（a 的 text-underline-offset），所以让文字与一块看不见的垫块按基线对齐，
     垫块从纸顶起、底边在横线之上 .25em（不看字体的度量）。最窄的屏幕上，横线之上也放得下字（--top ≥ 18px） */
  .langs { position: absolute; top: 0; right: var(--margin); display: flex; align-items: baseline; color: var(--muted); }
  .langs::before { content: ""; height: calc(var(--top) - .25em); }
  .langs ul { display: flex; list-style: none; }
  .langs a { color: var(--rubric); }
  .langs li + li::before { content: "/"; margin: 0 .5em; }  /* 分隔符属于列表项，不带链接的下划线 */

  /* 两态按钮：两面叠放，只显示一面，宽度不跳 */
  .swap { display: inline-grid; }
  .swap > * { grid-area: 1 / 1; }
  .swap > :last-child { visibility: hidden; }
  :is(.still [data-act=sea], [data-theme="dark"] [data-act=theme], .done) { > :first-child { visibility: hidden; } > :last-child { visibility: visible; } }
  .swap > *, .menu > :not(.swap) { display: flex; align-items: center; gap: .5em; }
  /* 菜单：自上方淡入 1/4 行 */
  .menu { position: absolute; z-index: 2; top: calc(100% + var(--line) / 4); right: 0; display: flex; flex-direction: column; width: max-content; max-width: var(--width); opacity: 0; translate: 0 calc(var(--line) / -4); transition: var(--ease) opacity, var(--ease) translate; }
  .menu :is(a, button) { text-decoration: none; }
  .menu > .swap { justify-items: start; }
  .pop::details-content { transition: var(--ease) content-visibility allow-discrete; }
  .pop[open] .menu { opacity: 1; translate: none; }
  @starting-style { .pop[open] .menu { opacity: 0; translate: 0 calc(var(--line) / -4); } }
  .cut .menu, .pop.cut::details-content { transition: none; }
  .menu, article > .note { padding: calc(var(--line) / 4) 1em; color: var(--ink); background: var(--paper); border: 1px solid var(--muted); }

  /* ── 页头与目录行 ── */
  /* 目录行（首页的条目、关于页的经历）：名称在左，点线引到右端的日期 */
  main { container-type: inline-size; }
  main > header { margin-bottom: calc(2 * var(--line)); }
  main > header blockquote { margin-top: var(--line); }
  .sub { font-size: var(--heading); color: var(--rubric); }
  .by { font-size: var(--small); }
  .by > span { color: var(--muted); }
  .by > span > * + *::before { content: " · "; color: var(--muted); }
  /* 名称折行时，日期仍在最后一行的右端（浮在右边），点线从最后一个字后接着走。点线挂在日期后面、向左伸满整行（100cqi，即 main 的宽），
     画在基线上；名称与日期各带纸色底，盖住压在字下面的那段，只露出两者之间的一段（两边各隔半个字） */
  .line { display: flow-root; }  /* 最后一行放不下日期时，日期另起一行，仍算在这一条里 */
  .lead { display: inline; padding-right: .5em; background: var(--paper); }
  .lead > :is(.tag, .meta) { margin-left: .5em; }  /* 名称后的附注（交互式、时长、学位）隔半个字 */
  .tail { float: right; }
  .tail > * { position: relative; padding-left: .5em; background: var(--paper); }
  .tail::after { content: ""; display: inline-block; width: 100cqi; margin-left: -100cqi; border-bottom: 1px dotted var(--muted); }
  .meta, time, .date { font-size: var(--small); color: var(--muted); }
  .tag { font-size: var(--small); color: var(--rubric); }  /* 交互式 */
  time, .date { white-space: nowrap; font-variant-numeric: tabular-nums; }

  /* 文章目录：展开、收起时宽高都过渡 */
  .contents {
    interpolate-size: allow-keywords;
    width: fit-content;
    max-width: 100%;
    margin-bottom: calc(2 * var(--line));
    padding: 0 1em;
    font-size: var(--small);
    border: 1px solid var(--muted);
    transition: var(--ease) width;
    & summary { line-height: var(--row); font-size: 1rem; text-decoration: none; color: var(--muted); }
    & summary::after {
      --rule: linear-gradient(currentColor, currentColor);
      content: "";
      display: inline-block;
      width: 1em;
      height: var(--row);
      margin-left: 1em;
      vertical-align: top;
      background: var(--rule) center / 1em 1px no-repeat, var(--rule) center / 1px 1em no-repeat;
      transition: var(--ease) background-size;
    }
    & [open] > summary::after { background-size: 1em 1px, 1px 0; }
    & details::details-content { block-size: 0; overflow: clip; transition: var(--ease) block-size, var(--ease) content-visibility allow-discrete; }
    & [open]::details-content { block-size: auto; }
    & :not([open])::details-content { contain: inline-size; }
    & .list { width: max-content; max-width: calc(100cqi - 2em - 2px); padding-bottom: calc(var(--line) / 4); line-height: var(--row); }
    & a { display: block; }
  }

  /* ── 正文 ── */
  /* 块与块只用上边距：段距 1/2 行；图与公式这类独立块前后各 1 行，相邻的公式算一组；小节标题前 2 行
     这四条用 :where 去掉具体程度，只按书写次序后者胜，所以第一块没有上边距，小节标题紧跟在图后也空 2 行 */
  :where(article > * + *) { margin-top: calc(var(--line) / 2); }
  :where(article > * + :is(figure, .eq), article > :is(figure, .eq) + *) { margin-top: var(--line); }
  :where(article > .eq + .eq) { margin-top: calc(var(--line) / 2); }
  :where(article > * + h2) { margin-top: calc(2 * var(--line)); }
  article [id] { scroll-margin-top: var(--line); }
  /* 用电脑看的提示：只在手机、平板这类没有鼠标的设备上显示；藏起时，下一块当作第一块，不留上边距 */
  .device { font-size: var(--small); color: var(--muted); }
  @media not ((hover: none) and (pointer: coarse)) { .device { display: none; } .device + * { margin-top: 0; } }
  article > h2 { clear: both; padding-bottom: calc(var(--line) / 4); font-size: var(--heading); border-bottom: 1px solid var(--muted); }
  /* 段首标：首段前的站标，高两行（--line + 1em），宽按站标 viewBox 的 19 : 24 */
  .open { display: flow-root; }
  .open::before {
    --mask: url(/assets/icon.svg?v=3696ad22) 0 0 / 100% 100% no-repeat;
    content: "";
    float: left;
    height: calc(var(--line) + 1em);
    aspect-ratio: 19 / 24;
    margin: calc((var(--line) - 1em) / 2) 1em calc((var(--line) - 1em) / 2) 0;
    background: var(--rubric);
    -webkit-mask: var(--mask);
    mask: var(--mask);
  }
  article a:not(.boxed, .fn) { color: var(--blue); }  /* 正文链接蓝；带框按钮与脚注号另有颜色 */
  article .fn { padding: 0 .25em; text-decoration: none; color: var(--rubric); }
  /* 脚注：方框与正文同宽，字号是正文的 3/4，文字也只占 3/4 宽（两侧各留 1/8），每行字数与正文相同
     展开、收起时高度与边距过渡；边框展开时立即加上，收起完才去掉 */
  article > .note {
    --motion: var(--ease) height, var(--ease) margin-top, var(--ease) padding-block, var(--ease) content-visibility allow-discrete;
    interpolate-size: allow-keywords;
    overflow: clip;
    padding-inline: calc(100% / 8);
    margin-top: calc(var(--line) / 4);
    font-size: var(--small);
    transition: var(--motion);
  }
  article > .note[hidden] { height: 0; margin-top: 0; padding-block: 0; border-width: 0; transition: var(--motion), border-width var(--duration) step-end; }
  .note .n { color: var(--rubric); }
  .note p + p { margin-top: calc(var(--line) / 4); }
  .note .katex-display { margin: calc(var(--line) / 4) 0; }

  /* ── 图 ── */
  figure img { width: 100%; }
  figcaption { margin-top: calc(var(--line) / 4); font-size: var(--small); color: var(--muted); }
  .label { font-family: var(--sans); color: var(--ink); }

  /* ── 交互图 ── */
  /* 正文里只是一个空框；引擎建出板（格子与其下的控件）、铺满板的画布与最上的字层，板之后是滑条。16:9 只是脚本运行前的样子 */
  [data-stage] {
    position: relative;
    container-type: inline-size;
    font-size: var(--small);
    line-height: var(--row);
    border: 1px solid var(--muted);
    &:empty { aspect-ratio: 16 / 9; }
    /* 格子：引擎按版面建的 HTML 元素，由这里排；画布与字层铺在格子之上，往各格的位置画
       叶子按宽高比定高；横排里每项按所含叶子数 n 分宽、至少 n 个 --cell（平面坐标图左右共留白 5 字，数据区要不小于留白），放不下就折行，
       折出的每行各自居中对齐；竖排里各项占满宽 */
    --cell: 10em;
    & .board { position: relative; }
    & .row { display: flex; flex-wrap: wrap; align-items: center; }
    & .col { display: flex; flex-direction: column; }
    /* 格子与控件压在画布之上，指针却穿过它们落到画布上（拖动、点选）；只有按钮、链接与图例本身接指针，可按、可选中复制；各页另有要接指针的（如读数），在 page.css 里自己开 */
    & .board > * { position: relative; pointer-events: none; }
    & .board > canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: auto; touch-action: pan-y; }  /* 单指竖拖滚动页面，其余手势归交互图 */
    & .board :is(button, a, .key) { pointer-events: auto; }
    /* 触屏上三维的格整格接管单指（见 stage.js「手势」）：旋转要两个方向，页面不跟着滚；长按不选字、不弹菜单 */
    @media (pointer: coarse) { & .board .spin { pointer-events: auto; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; } }
    & .words { position: absolute; inset: 0; overflow: hidden; }
    & .words > span { position: absolute; transform-origin: 0 0; line-height: 1; white-space: nowrap; pointer-events: auto; }  /* 位置、转角、颜色、斜体由引擎逐个给 */
    & .words > .quiet { pointer-events: none; -webkit-user-select: none; user-select: none; }
    /* 滑条一行三列：名称、滑条、读数；名称与读数按内容取宽，滑条占满其余 */
    & .controls { display: grid; grid-template-columns: max-content minmax(0, 1fr) max-content; align-items: center; gap: 0 1em; padding: calc(var(--line) / 4) 1em; white-space: nowrap; }
    & .controls > * { display: contents; }
    & .controls > * > :first-child { grid-column: 1; justify-self: end; }
    & .controls > * > output { grid-column: 3; text-align: end; font-variant-numeric: tabular-nums; }
    & .play { color: var(--rubric); }
    /* 格子之下：工具行、并排行、图例，各占一行，居中 */
    & .below { display: flex; flex-direction: column; align-items: center; gap: calc(var(--line) / 4); padding: calc(var(--line) / 4) 1em; }
    & .below:empty { display: none; }
    & .strip { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .25em; white-space: nowrap; }
    & .strip > * + .switch { margin-left: 1em; }
    /* 并排行两栏等分，每栏至少 16 字，更窄时上下排；只看宽度，不看内容 */
    & .duo { display: grid; grid-template-columns: 1fr 1fr; justify-items: center; align-items: center; gap: calc(var(--line) / 4) 1em; width: 100%; }
    @container (width < 32em) { & .duo { grid-template-columns: 1fr; } }
    & .stack { display: flex; flex-direction: column; align-items: center; gap: calc(var(--line) / 4); width: 100%; }
    /* 选择器：一组一行，按钮组居中，组名挂在左侧；多行时按钮等宽排成格，单行时按字宽，放不下就折行，不越出所在的栏 */
    & .picker { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .25em 1em; width: 100%; }
    & .picker > * { display: contents; }
    & .picker > * > :first-child { grid-column: 1; justify-self: end; white-space: nowrap; }
    & .seg { grid-column: 2; display: flex; flex-wrap: wrap; justify-content: center; gap: .25em; }
    & .picker:has(> :nth-child(2)) .seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
    /* 图例：标题一行，其下各项按给的分行，项间隔 2 字；标记与文字隔 1/4 字 */
    & .key { display: flex; flex-direction: column; align-items: center; color: var(--ink); }
    & .key > div { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 2em; }
    & .key span { display: flex; align-items: center; gap: .25em; }
    & .key i { display: inline-block; border-radius: 50%; }
    & .key .ramp { width: 6em; height: .25em; border-radius: 0; }
    /* 开关：文字在左，滑槽 2 × 1 字 */
    & .switch { display: flex; align-items: center; gap: .5em; text-decoration: none; }
    & .switch i { position: relative; width: 2em; height: 1em; border: 1px solid var(--muted); transition: var(--ease) background, var(--ease) border-color; }
    & .switch i::after { content: ""; position: absolute; inset: 1px auto 1px 1px; aspect-ratio: 1; background: var(--muted); transition: var(--ease) translate, var(--ease) background; }
    /* 滑条：轨 1px；滑块看上去是 1/4 字宽、半行高的朱红短竖，可按的范围是一行见方（最小触控目标）；轨两端各缩进半个滑块，短竖能走到轨的两端
       两种浏览器的轨与滑块要分开写（一条规则里有不认识的选择器，整条作废），样子由 --track、--knob 给出，只写一次 */
    & input[type=range] {
      --track: linear-gradient(var(--muted), var(--muted)) center / calc(100% - var(--row)) 1px no-repeat;
      --knob: linear-gradient(var(--rubric), var(--rubric)) center / .25em 50% no-repeat;
      -webkit-appearance: none;
      appearance: none;
      width: 100%;
      height: var(--row);
      background: none;
    }
    & input[type=range]::-webkit-slider-runnable-track { height: 1px; background: var(--track); }
    & input[type=range]::-moz-range-track { height: 1px; background: var(--track); }
    & input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: var(--row); height: var(--row); margin-top: calc((1px - var(--row)) / 2); background: var(--knob); border: 0; border-radius: 0; box-shadow: none; }  /* iOS 另给滑块白底与阴影，去掉 */
    & input[type=range]::-moz-range-thumb { width: var(--row); height: var(--row); background: var(--knob); border: 0; border-radius: 0; }
  }

  /* ── 公式 ── */
  .katex { font-size: 1.25em; }  /* 公式比所在文字大一级（正文 1rem → --heading） */
  .tex { white-space: nowrap; }
  .katex-display { position: relative; margin: 0; overflow: auto hidden; scrollbar-width: none; }
  .eq { display: grid; grid-template-columns: 1fr minmax(0, auto) 1fr; align-items: center; }
  .eq > .katex-display { grid-column: 2; }
  .eqn { grid-column: 3; justify-self: end; padding-left: 1em; }

  /* ── 留言 ── */
  /* 文章末尾，前空 2 行；框与带框的按钮同样一行高 --row、左右留半个字；格与格相隔 1/4 行 */
  .comment {
    margin-top: calc(2 * var(--line));
    & form { display: grid; gap: calc(var(--line) / 4); font-size: var(--small); line-height: calc(var(--row) - 2px); }
    & ::placeholder { color: var(--muted); opacity: 1; }
    & .fields { display: flex; flex-wrap: wrap; gap: calc(var(--line) / 4) 1em; }
    & .fields input { flex: 1 1 var(--field); }
    /* 说明在左、按钮在右；放不下时按钮折到下一行，仍靠右 */
    & .send { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: calc(var(--line) / 4) 1em; color: var(--muted); }
    & .send button { margin-left: auto; }
  }

  /* ── 页尾 ── */
  footer { margin-top: auto; padding-top: calc(2 * var(--line)); font-size: var(--small); color: var(--muted); }
  .legal { padding-top: calc(var(--line) / 4); border-top: 1px solid var(--muted); }
}

/* ── 状态 ── */
/* 悬停、选中、隐藏、静止单独一层，压过 site 层的颜色与显示方式，不看具体程度；
   同一层里更具体的例外照常胜出：纸上方的工具与语言切换悬停转墨色，选中的书签与带框按钮是朱红底、纸色字 */
@layer state {
  [hidden]:not([hidden="until-found"]) { display: none; }  /* until-found 留给脚注 */
  .still *, .still ::before, .still ::after, .still ::details-content { transition: none; }
  .still::view-transition-group(*), .still::view-transition-old(*), .still::view-transition-new(*) { animation: none; }  /* 暂停动画时换页直接换 */

  /* 悬停只在有鼠标的设备上：触屏上点过之后不会一直停在悬停的颜色 */
  @media (hover: hover) {
    :is(a, button, summary):hover { color: var(--rubric); }
    .tools > :hover, .tools summary:hover, .langs a:hover { color: var(--ink); }
    .boxed:not(.on):hover { color: var(--rubric); border-color: var(--rubric); }
    .tabs a:not(.on):hover { background: color-mix(in srgb, var(--paper), var(--muted) 25%); }  /* 未选中的书签悬停时底色转浅灰（纸色混四分之一的灰） */
    [data-stage] .switch:hover i { border-color: var(--rubric); }
    .field:hover { border-color: var(--ink); }
  }
  .pop[open] > summary { color: var(--ink); }
  :is(.tabs .on, .boxed.on) { color: var(--paper); background: var(--rubric); border-color: var(--rubric); }
  [data-stage] .switch.on i { background: var(--rubric); border-color: var(--rubric); }
  [data-stage] .switch.on i::after { translate: 1em; background: var(--paper); }
  .field:focus-visible { outline: 0; border-color: var(--rubric); }
  .boxed:disabled { opacity: .5; cursor: wait; }
  .comment .failed { color: var(--rubric); }
}
