/* app.css —— 只用 tokens.css 里的变量，不出现任何十六进制颜色 */

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  text-rendering: optimizeLegibility;
}

html[lang='el'] body { font-family: var(--font-greek); }

h1, h2, h3 { line-height: 1.2; margin: 0 0 var(--space-3); }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
p { margin: 0 0 var(--space-4); }
ul { margin: 0; padding: 0; list-style: none; }

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip {
  position: absolute;
  left: var(--space-3);
  top: calc(-1 * var(--space-8));
  z-index: 20;
  background: var(--accent);
  color: var(--on-accent);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.skip:focus { top: var(--space-3); }

.wrap {
  width: 100%;
  max-width: var(--max-content);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

/* ---------- 顶栏 ---------- */

.site-head {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.head-in {
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding-top: var(--space-2);
  padding-bottom: var(--space-2);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.brand-mark { width: 24px; height: 24px; color: var(--accent); }

.site-nav { display: flex; gap: var(--space-4); margin-inline-end: auto; }
.site-nav a {
  color: var(--text-muted);
  text-decoration: none;
  padding: var(--space-1) 0;
  border-bottom: 2px solid transparent;
}
.site-nav a[aria-current='page'] { color: var(--text); border-bottom-color: var(--accent); }

.head-tools { display: flex; align-items: center; gap: var(--space-2); }

.lang-switch { display: flex; align-items: center; gap: var(--space-1); }

.lang-select {
  min-height: var(--touch-target-min);
  padding: var(--space-1) var(--space-2);
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  cursor: pointer;
}
.lang-select:hover { border-color: var(--text-muted); }

/* 关掉 JS 时才显示的三个语言链接（在 <noscript> 里，见 src/pages/layout.js）。
   开了 JS 这些元素压根不会被解析出来，所以这套规则只在 no-JS 场景生效。 */
.lang-noscript { display: flex; gap: var(--space-1); }
.lang-noscript a {
  display: inline-block;
  min-width: var(--touch-target-min);
  padding: var(--space-1) var(--space-2);
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-target-min);
  height: var(--touch-target-min);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text);
  cursor: pointer;
}
.theme-icon {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  background: linear-gradient(to right, currentColor 0 50%, transparent 50% 100%);
}
html[data-theme='dark'] .theme-icon { background: currentColor; }
html[data-theme='light'] .theme-icon { background: transparent; }

/* ---------- 主体 ---------- */

main { padding-top: var(--space-6); padding-bottom: var(--space-8); }

.lede {
  font-size: var(--fs-lg);
  color: var(--text-muted);
  max-width: 52ch;
}

/* 首页首屏：左文右谱。参考站的首屏是「欢迎语 + 两个按钮」，谱面在分类卡上；
   我们把一小句真谱面提到首屏，让第一眼就看出这是乐理产品。 */
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: var(--space-6) var(--space-7);
  align-items: center;
  padding: var(--space-5) 0 var(--space-7);
}
.hero h1 { font-size: var(--fs-display); line-height: var(--lh-display); max-width: 18ch; }
.hero-copy .lede { margin-bottom: var(--space-5); }
.hero-cta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-bottom: 0; }

.btn-quiet {
  border-color: transparent;
  background: none;
  padding-inline: var(--space-2);
  color: var(--accent);
}
.btn-quiet:hover { background: var(--surface); }

.stat-row {
  display: flex;
  gap: var(--space-6);
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
}
.stat-row li { display: flex; flex-direction: column; }
.stat-row b { font-size: var(--fs-xl); font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-row span { font-size: var(--fs-sm); color: var(--text-muted); }

.fig-card {
  margin: 0;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}
.fig-card figcaption {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  letter-spacing: 0.06em;
  margin-bottom: var(--space-3);
}

/* 谱面插图：颜色跟着 currentColor 走，所以深浅色都能用同一份 SVG */
.fig { display: flex; align-items: center; justify-content: center; color: var(--text); }
.fig svg { width: auto; height: 56px; max-width: 100%; }
.fig-card .fig { padding: var(--space-5) var(--space-3); background: var(--bg); border-radius: var(--radius-md); }
.fig-card .fig svg { height: 88px; }

.group-block { margin-top: var(--space-5); }
.group-title {
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: var(--space-6) 0 0;
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

/* 卖点区：原来是四个小胶囊（一排词），现在是一栏一栏讲清楚 */
.why-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: var(--space-5);
  margin-top: var(--space-5);
}
.why-item h3 { font-size: var(--fs-base); margin-bottom: var(--space-2); }
.why-item p { font-size: var(--fs-sm); color: var(--text-muted); margin: 0; }
.why-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-bottom: var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--accent);
}
.why-ico svg { width: 22px; height: 22px; }

/* 目录页/分类页的左右分栏 */
.layout-side {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: var(--space-7);
  align-items: start;
}
.side { position: sticky; top: calc(var(--header-height) + var(--space-4)); }
.side-h {
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}
.side-list { display: grid; gap: var(--space-1); }
.side-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: var(--fs-sm);
}
.side-list a:hover { background: var(--surface); }
.side-list a[aria-current='page'] { background: var(--surface-2); font-weight: 600; }
.side-n { color: var(--text-muted); font-variant-numeric: tabular-nums; }

.sec-h {
  margin-top: var(--space-7);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

/* ---------- 分类卡：上半是现算的谱面插图，下半是名字与一句说明 ---------- */

.cat-grid {
  display: grid;
  /* min(100%, …)：轨道的最小宽度不能大于容器本身，否则 320px 宽的手机上整行会撑出屏幕
     （auto-fit + minmax(320px, …) 在可用宽 288px 时就是 16px 横向溢出的元凶） */
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}
.cat-grid-mini { grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }

.cat-card a {
  display: flex;
  flex-direction: column;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform var(--motion-base) var(--motion-ease),
    box-shadow var(--motion-base) var(--motion-ease),
    border-color var(--motion-base) var(--motion-ease);
}
.cat-card a:hover,
.cat-card a:focus-visible {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-pop);
}
.cat-fig {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 132px;
  padding: var(--space-5) var(--space-3);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.cat-fig svg { height: 64px; }
.cat-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4) var(--space-5) var(--space-5);
}
.cat-name { font-weight: 600; font-size: var(--fs-lg); }
.cat-meta { font-size: var(--fs-xs); color: var(--text-muted); text-transform: none; }
.cat-desc { font-size: var(--fs-sm); color: var(--text-muted); }
.cat-go {
  margin-top: var(--space-3);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--accent);
}

/* ---------- 练习卡（分类页 / 练耳组） ---------- */

.ex-card a {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: var(--space-1);
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
  transition: border-color var(--motion-base) var(--motion-ease),
    background var(--motion-base) var(--motion-ease);
}
.ex-card a:hover,
.ex-card a:focus-visible { border-color: var(--accent); background: var(--surface); }
.ex-card .ex-go {
  grid-row: auto;
  margin-top: auto;
  padding-top: var(--space-3);
  font-size: var(--fs-sm);
  font-weight: 600;
}
.ex-card-mini a { background: var(--surface); border-style: dashed; }
.ex-card-mini a:hover { background: var(--bg); }

/* 练习卡上的小谱面：同一份 SVG，缩到 40px 高 */
.ex-fig {
  display: flex;
  align-items: center;
  height: 40px;
  margin-bottom: var(--space-2);
  color: var(--text-muted);
}
.ex-fig svg { height: 40px; }

.ex-dots { display: inline-flex; gap: 4px; margin-top: var(--space-2); }
.ex-dots .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border); }
.ex-dots .dot[data-on='yes'] { background: var(--accent); }

.ex-ico { display: inline-flex; margin-bottom: var(--space-2); color: var(--accent); }

/* ---------- 目录页：每个分类一小块 ---------- */

.cat-block {
  padding: var(--space-5) 0 var(--space-4);
  border-bottom: 1px solid var(--border);
}
.cat-block-h {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin-bottom: var(--space-1);
  font-size: var(--fs-lg);
}
.cat-block-h a { color: var(--text); text-decoration: none; }
.cat-block-h a:hover { color: var(--accent); text-decoration: underline; }
.ex-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.ex-chips a {
  display: inline-block;
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text);
  text-decoration: none;
  font-size: var(--fs-sm);
  transition: border-color var(--motion-base) var(--motion-ease),
    color var(--motion-base) var(--motion-ease);
}
.ex-chips a:hover { border-color: var(--accent); color: var(--accent); }

/* 错题本（src/client/mistakes.js 现渲染，类名不能改） */
.ex-list { display: grid; gap: var(--space-2); margin-top: var(--space-5); }
.ex-row a {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-1) var(--space-4);
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text);
  min-height: var(--touch-target-min);
}
.ex-row a:hover { border-color: var(--accent); background: var(--surface); }
.ex-name { font-weight: 600; }
.ex-desc { grid-column: 1; font-size: var(--fs-sm); }
.ex-go { grid-row: 1 / 3; color: var(--accent); }

.prose { max-width: 68ch; margin-top: var(--space-6); }
.note-block { max-width: 68ch; margin-top: var(--space-7); padding-top: var(--space-5); border-top: 1px solid var(--border); }

.crumb { font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: var(--space-2); }

/* ---------- 按钮 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-target-min);
  padding: var(--space-2) var(--space-5);
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-input);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn-primary:hover { color: var(--on-accent); opacity: 0.92; }
.btn-lg { min-height: calc(var(--touch-target-min) + 8px); padding: var(--space-3) var(--space-6); font-size: var(--fs-lg); }
.btn-ghost { border-style: dashed; color: var(--text-muted); }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn:disabled, .btn[aria-disabled='true'] { opacity: 0.45; cursor: not-allowed; }
/* 表格里的小按钮：跟 .btn 一样的边框与焦点，只是不占一整行高 */
.btn-small { min-height: 0; padding: var(--space-1) var(--space-3); font-size: var(--fs-xs); }
.btn svg { width: 18px; height: 18px; }
.file-btn { position: relative; }

/* ---------- 计分条 ---------- */

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
  margin: 0 0 var(--space-5);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
}
.hud > div { display: flex; gap: var(--space-2); align-items: baseline; }
.hud dt { color: var(--text-muted); }
.hud dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
/* ④ 游戏化：等级名 + "还差几题"，比数字小一号，不抢主数字 */
.hud-sub { color: var(--text-muted); font-weight: 400; }
.hud-hint { color: var(--text-muted); font-weight: 400; font-size: var(--fs-xs); margin-left: var(--space-1); }
.hud-link { margin: 0 0 var(--space-5); font-size: var(--fs-sm); }
.hud-link a { color: var(--accent); }

/* ---------- 本机排行榜（④ 游戏化） ---------- */

.board-wrap { margin-top: var(--space-5); }
/* 窄屏横向滚动而不是压缩列：名次/积分这类数字被挤成两行就没法对着看了 */
.board-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.board-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}
.board-table th,
.board-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.board-table th { color: var(--text-muted); font-weight: 500; }
.board-table tr[aria-current='true'] { background: var(--surface); }
.board-table tr[aria-current='true'] .board-name-text { font-weight: 700; }
.board-rank { font-weight: 700; color: var(--text-muted); }
.board-table tr[aria-current='true'] .board-rank { color: var(--accent); }
.board-you {
  margin-left: var(--space-2);
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--fs-xs);
}
.board-actions { display: flex; gap: var(--space-2); align-items: center; }
/* 手机上这排按钮是唯一的操作入口：别为了紧凑把高度压到手指点不准（原来 min-height:0 ⇒ 26px） */
.board-actions .btn { padding: var(--space-1) var(--space-3); font-size: var(--fs-xs); min-height: 2rem; }
.board-edit { display: flex; gap: var(--space-2); align-items: center; }
.board-edit input { max-width: 12ch; }
.board-note { margin-top: var(--space-3); font-size: var(--fs-xs); }
.board-add {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-end;
  margin-top: var(--space-5);
}
.board-add label { font-size: var(--fs-sm); color: var(--text-muted); }
/* 排行榜里的文本框（加人 / 改名）此前没有任何样式，走浏览器默认 ⇒ 只有 21px 高：
   手机上点不准，而且和站内其它控件长相不一致。统一到与 .field 控件同样的外观与高度。 */
.board-add input,
.board-edit input {
  min-height: var(--touch-target-min);
  padding: var(--space-1) var(--space-2);
  background: var(--bg);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-base);
}
/* 窄屏上表格要横向滑动，而"操作"列（切换/改名/删除）是整页唯一的操作入口 ——
   滑出去就等于手机上换不了人。让它贴右边常驻；背景必须不透明，否则底下的字会透出来。 */
@media (max-width: 760px) {
  .board-table th:last-child,
  .board-table td:last-child {
    position: sticky;
    right: 0;
    background: var(--bg);
    box-shadow: inset 1px 0 0 var(--border);
  }
  .board-table tr[aria-current='true'] td:last-child { background: var(--surface); }
}
/* 存储被禁时客户端给表单加 hidden，但上面那条 display:flex 会盖掉浏览器默认的
   [hidden]{display:none} —— 少这一行，"不让存数据"的页面照样画出一个点了没反应的加人表单。 */
.board-add[hidden] { display: none; }
.board-ladders {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-2) var(--space-4);
  font-size: var(--fs-sm);
}
.board-ladders li { display: flex; justify-content: space-between; border-bottom: 1px dotted var(--border); }

/* ---------- 答题卡 ---------- */

.q-card {
  max-width: var(--card-max);
  padding: var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg);
}
.q-count { font-size: var(--fs-xs); color: var(--text-muted); margin-bottom: var(--space-2); font-variant-numeric: tabular-nums; }
.q-prompt { font-size: var(--fs-lg); margin-bottom: var(--space-5); }

.staff-card {
  display: flex;
  justify-content: center;
  padding: var(--space-5) var(--space-4);
  margin-bottom: var(--space-5);
  background: var(--surface);
  border-radius: var(--radius-md);
  overflow-x: auto;
}
/* 谱面按自身比例缩放：拉满宽度会把一个音符和谱号扯到两头，看着像坏掉了 */
.staff-card svg { width: auto; height: 88px; max-width: 100%; }
/* 简谱是数字，给得比五线谱矮一点更像谱面而不是标题 */
.staff-card[data-notation="jianpu"] svg { height: 64px; }

.notation-toggle { margin: calc(var(--space-3) - var(--space-5)) 0 var(--space-5); font-size: var(--fs-sm); }
.notation-toggle-mark { font-family: var(--font-mono); letter-spacing: 0.05em; }

.ear-hint { color: var(--text-muted); font-size: var(--fs-sm); margin-bottom: var(--space-3); }
.kbd-hint { color: var(--text-muted); font-size: var(--fs-sm); margin-top: var(--space-4); }

.options { display: grid; gap: var(--space-2); grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); }
.btn-opt {
  min-height: calc(var(--touch-target-min) + 12px);
  font-size: var(--fs-lg);
  font-variant-numeric: tabular-nums;
}
.btn-opt[data-state='correct'] {
  background: var(--success);
  border-color: var(--success);
  color: var(--bg);
}
.btn-opt[data-state='wrong'] {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--bg);
  text-decoration: line-through;
}

.piano { display: flex; gap: var(--space-1); }
.pkey {
  flex: 1;
  min-height: calc(var(--touch-target-min) * 2.2);
  font: inherit;
  font-weight: 600;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-input);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: var(--space-3);
}
.pkey:hover { background: var(--surface); }
.pkey[data-state='correct'] { background: var(--success); color: var(--bg); }
.pkey[data-state='wrong'] { background: var(--danger); color: var(--bg); }

.tap-area { display: grid; gap: var(--space-4); justify-items: center; }
.btn-tap { min-width: 220px; min-height: calc(var(--touch-target-min) * 2); font-size: var(--fs-lg); }
.btn-tap[data-state='live'] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tap-dots { display: flex; gap: var(--space-2); min-height: var(--space-6); }
.tap-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
}
.tap-dot[data-state='wrong'] { background: var(--danger); }

.q-actions { display: flex; gap: var(--space-3); margin-top: var(--space-5); flex-wrap: wrap; }

.feedback { margin-top: var(--space-4); min-height: var(--lh-base); font-weight: 600; }
.feedback[data-state='correct'] { color: var(--success); }
.feedback[data-state='wrong'] { color: var(--danger); }
.feedback .why { display: block; font-weight: 400; color: var(--text-muted); }

/* ---------- 离线提示 ---------- */

.sw-notice {
  position: fixed;
  left: 50%;
  bottom: var(--space-4);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  z-index: 30;
}

/* ---------- 页脚 ---------- */

.site-foot {
  border-top: 1px solid var(--border);
  padding: var(--space-6) 0 var(--space-8);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.site-foot p { margin-bottom: var(--space-2); }

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; gap: var(--space-6); padding-top: var(--space-4); }
  .fig-card { order: 2; }
  .stat-row { gap: var(--space-5); }
}

@media (max-width: 760px) {
  .layout-side { grid-template-columns: 1fr; gap: var(--space-5); }
  .side { position: static; }
  .side-h { margin-bottom: var(--space-2); }
  .side-list { display: flex; flex-wrap: wrap; gap: var(--space-2); }
  .side-list a { border: 1px solid var(--border); border-radius: var(--radius-pill); }
  .side-n { margin-inline-start: var(--space-2); }
}

@media (max-width: 640px) {
  .hero h1 { font-size: var(--fs-xl); }
  .q-card { padding: var(--space-4); }
  .site-nav { order: 3; width: 100%; margin-inline-end: 0; }
}

/* ── 工具页（③ 钢琴 / 节拍器 / 调音器 / 和弦 / 音阶 / 五度圈） ──────────
   只用 tokens.css 的变量，不写死颜色；可点控件一律 ≥ --touch-target-min。
   键帽颜色在明暗两套主题下分别算（黑键在暗色里不能比白键更暗，否则看不出来）。 */
.tool-panel {
  margin: var(--space-4) 0 var(--space-5);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}
.tool-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
}
.field { display: flex; flex-direction: column; gap: var(--space-1); color: var(--text-muted); font-size: var(--fs-sm); }
.field select,
.field input[type='number'] {
  min-height: var(--touch-target-min);
  padding: var(--space-1) var(--space-2);
  background: var(--bg);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-base);
}
.field input[type='number'] { width: 6rem; }
.field-check {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--touch-target-min);
  color: var(--text);
  font-size: var(--fs-base);
}
.field-check input { width: 1.25rem; height: 1.25rem; accent-color: var(--accent); }
.tool-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.tool-readout { margin: var(--space-3) 0 0; min-height: 1.5em; font-size: var(--fs-base); }
.tool-help { margin-top: var(--space-3); color: var(--text-muted); font-size: var(--fs-sm); }
.tool-help summary { cursor: pointer; }
.tool-help p { margin: var(--space-2) 0 0; }
.tool-out { display: grid; gap: var(--space-3); margin-top: var(--space-4); }
.tool-symbol { margin: 0; font-size: var(--fs-xl); font-weight: 700; }
.tool-notes { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-1) var(--space-3); margin: 0; }
.tool-notes dt { color: var(--text-muted); font-size: var(--fs-sm); }
.tool-notes dd { margin: 0; font-family: var(--font-mono); font-size: var(--fs-sm); }

/* 钢琴：白键放在等宽的槽位里，黑键绝对定位贴到槽位右缘（贴在 C–D 这种缝上）。
   不用内联 style —— CSP 的 style-src 'self' 会把内联样式拦掉。 */
.piano {
  --piano-cap: var(--text);
  --piano-cap-label: var(--bg);
  position: relative;
  display: flex;
  align-items: stretch;
  height: 10rem;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  user-select: none;
  touch-action: manipulation;
}
html[data-theme='dark'] .piano { --piano-cap: var(--border); --piano-cap-label: var(--text); }
@media (prefers-color-scheme: dark) {
  html:not([data-theme='light']) .piano { --piano-cap: var(--border); --piano-cap-label: var(--text); }
}
.pk-slot { position: relative; display: flex; flex: 1 1 0; }
.pk { position: relative; padding: 0; font: inherit; cursor: pointer; }
.pk-white {
  flex: 1 1 auto;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: var(--space-1);
  background: var(--bg);
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--fs-xs);
}
.pk-slot:last-child .pk-white { border-right: none; }
.pk-black {
  position: absolute;
  top: 0;
  left: 100%;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 62%;
  height: 62%;
  transform: translateX(-50%);
  padding-bottom: var(--space-1);
  background: var(--piano-cap);
  border: 1px solid var(--piano-cap);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  color: var(--piano-cap-label);
  font-size: var(--fs-xs);
}
.pk[data-on='yes'] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pk-label { pointer-events: none; }
.piano[data-labels='off'] .pk-label { opacity: 0; }

/* 节拍器：一排圆点，第一拍描边重音，响的那一拍填实 */
.metro-dots { display: flex; gap: var(--space-2); margin-top: var(--space-3); }
.mdot { width: 1rem; height: 1rem; border: 1px solid var(--border); border-radius: 50%; background: var(--surface-2); }
.mdot[data-accent='yes'] { border-color: var(--accent); }
.mdot[data-on='yes'] { background: var(--accent); border-color: var(--accent); }

/* 调音器：半圆刻度 + 指针，±50 音分对应 ±45° */
.tuner-gauge { display: grid; justify-items: center; gap: var(--space-2); margin-top: var(--space-2); }
.tuner-arc { width: min(100%, 22rem); height: auto; }
.tuner-rim { stroke: var(--border); stroke-width: 3; stroke-linecap: round; }
.tuner-tick { stroke: var(--border); stroke-width: 2; }
.tuner-tick[data-major='yes'] { stroke: var(--text-muted); stroke-width: 3; }
.tuner-needle-line { stroke: var(--accent); stroke-width: 3; stroke-linecap: round; }
.tuner-hub { fill: var(--accent); }
.tuner-readout { display: flex; align-items: baseline; gap: var(--space-2); margin: 0; font-size: var(--fs-lg); }
.tuner-readout .muted { font-family: var(--font-mono); font-size: var(--fs-sm); }

/* 五度圈：SVG 只画两个圈，按钮是绝对定位的真按钮（键盘与读屏都能用） */
.circle-wrap { position: relative; width: min(100%, 30rem); margin: var(--space-4) auto; aspect-ratio: 1 / 1; }
.circle-rings { position: absolute; inset: 0; width: 100%; height: 100%; }
/* 圈线用 --border-input 而不是 --border：后者在浅底上几乎看不见（实测圈线像"消失"） */
.circle-rim { fill: none; stroke: var(--border-input); stroke-width: 2; }
.circle-keys { position: absolute; inset: 0; }
.ck {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
  padding: 0 var(--space-1);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.ck-minor { color: var(--text-muted); font-size: var(--fs-xs); }
.ck:hover { border-color: var(--accent); }
.ck[aria-pressed='true'] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* 12 个位置写在 CSS 里（由 tools/circle.js 的 circleGeometry 算出，300×300 坐标系换成百分比）。
   外圈大调 .ck-p0-11 沿着五度圈顺时针；内圈关系小调 .ck-m0-11 半径小一些。
   生成方式：node 里调 circleGeometry(150,150,100,58) 打印百分比后粘进来（改半径要重算）。 */
.ck-p0 { left: 50.00%; top: 10.00%; }
.ck-p1 { left: 70.00%; top: 15.36%; }
.ck-p2 { left: 84.64%; top: 30.00%; }
.ck-p3 { left: 90.00%; top: 50.00%; }
.ck-p4 { left: 84.64%; top: 70.00%; }
.ck-p5 { left: 70.00%; top: 84.64%; }
.ck-p6 { left: 50.00%; top: 90.00%; }
.ck-p7 { left: 30.00%; top: 84.64%; }
.ck-p8 { left: 15.36%; top: 70.00%; }
.ck-p9 { left: 10.00%; top: 50.00%; }
.ck-p10 { left: 15.36%; top: 30.00%; }
.ck-p11 { left: 30.00%; top: 15.36%; }
.ck-m0 { left: 50.00%; top: 23.33%; }
.ck-m1 { left: 63.33%; top: 26.91%; }
.ck-m2 { left: 73.09%; top: 36.67%; }
.ck-m3 { left: 76.67%; top: 50.00%; }
.ck-m4 { left: 73.09%; top: 63.33%; }
.ck-m5 { left: 63.33%; top: 73.09%; }
.ck-m6 { left: 50.00%; top: 76.67%; }
.ck-m7 { left: 36.67%; top: 73.09%; }
.ck-m8 { left: 26.91%; top: 63.33%; }
.ck-m9 { left: 23.33%; top: 50.00%; }
.ck-m10 { left: 26.91%; top: 36.67%; }
.ck-m11 { left: 36.67%; top: 26.91%; }

@media (max-width: 640px) {
  .tool-panel { padding: var(--space-3); }
  /* 390px 里 15 个白键每个只剩 ~26px：把键盘改成横向可滑，竖着也不会把键压成一条线 */
  .piano { height: 8rem; overflow-x: auto; overflow-y: hidden; }
  /* 槽位 2.5rem ⇒ 黑键约 24.8px（实测 2.4rem 时是 23.8px，刚好卡在触屏目标下限 24px 之下）。
     键盘本来就能横滑，加宽只会多滑一点，不会把按键压变形 */
  .pk-slot { min-width: 2.5rem; }
  /* 黑键只有 ~17px 宽，"C♯3" 这种标签会溢到邻键上（实测截图里糊成一片）——窄屏就不写了，
     认得出黑键靠的是位置和颜色，白键标签留着 */
  .pk-black .pk-label { display: none; }
  .circle-wrap { width: 100%; }
}
