/* ================================================================
   BeatBone — 文本写谱工具（无音频）
   格子里的值 = 任意文本；文本 → 颜色由哈希稳定分配（同字同色）
   ================================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel2: #f2f4f7;
  --line: #e2e6ee;
  --line-strong: #c3cad6;
  --beatline: #7d8798;
  --cell-border: #d3d9e3;
  --cell-empty-bg: #f6f7f9;
  --text: #1f2329;
  --muted: #7a8494;
  --accent: #1f6feb;
  /* 分区浅色 */
  --c-top: #eef4fc;
  --c-head: #eef8f1;
  --c-foot: #fdfaf2;
  --c-sheet: #f8fafd;
  /* 尺寸基准：媒体查询只改 base，JS 用 base × 缩放系数写入 --cell / --beat-w */
  --cell-base: 30px;
  --beat-w-base: 132px;
  --cell: var(--cell-base);
  --beat-w: var(--beat-w-base);   /* 每拍槽宽（固定拍宽模型）；横向缩放改它 */
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- 背景呼吸光层 ----------
   fixed 铺满视口、z-index:-1 → 画在根背景之上、所有内容之下；
   谱面卡片仍是不透明白底，格子线条与文字永不被染色。
   --breath-a 由 JS 按拍内相位逐帧写入（0=无 → 1=拍首最强）。 */
#breath-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.45s ease;      /* 关闭时柔顺淡出；开启时由逐帧值直接驱动 */
  background:
    radial-gradient(120% 95% at 50% 4%, var(--breath-c1, #ffd6e6) 0%, rgba(255,255,255,0) 62%),
    radial-gradient(95% 85% at 8% 96%, var(--breath-c2, #cfe9ff) 0%, rgba(255,255,255,0) 58%),
    radial-gradient(95% 85% at 94% 90%, var(--breath-c2, #cfe9ff) 0%, rgba(255,255,255,0) 55%);
}
body.breath-on #breath-layer {
  opacity: var(--breath-a, 0);
  transition: none;                    /* 逐帧更新期间禁用过渡，避免拖尾 */
}

/* ---------- 顶栏（浅蓝） ---------- */
#transport {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--c-top), #ffffff 85%);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  flex-shrink: 0;
  z-index: 5;
}
.t-left, .t-mid, .t-right { display: flex; align-items: center; gap: 8px; }
.t-left { flex: 1; min-width: 150px; }
.t-mid { gap: 6px; }
.t-right { gap: 6px; }

#title-input {
  background: rgba(255,255,255,0.7);
  border: 1px solid transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 6px;
  width: 150px;
  outline: none;
}
#title-input:hover, #title-input:focus { border-color: var(--line); background: #fff; }

/* 写谱人 / 来源输入框（顶栏小号，随谱保存，导出 PNG 显示） */
.meta-input {
  background: rgba(255,255,255,0.7);
  border: 1px solid transparent;
  color: var(--text);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  width: 82px;
  outline: none;
}
.meta-input::placeholder { color: var(--muted); }
.meta-input:hover, .meta-input:focus { border-color: var(--line); background: #fff; }

.badge {
  font-size: 11px;
  color: var(--muted);
  background: rgba(255,255,255,0.8);
  border: 1px solid var(--line);
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s;
}
.badge.ok { color: #2d9d5f; border-color: rgba(45,157,95,0.35); }

/* 当前谱子文件徽标（顶栏）：未关联文件时虚线灰、关联后实线可读 */
.file-chip {
  font-size: 12px;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  padding: 3px 8px;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-chip.set { border-style: solid; color: var(--text); background: var(--panel2); }

.lbl { font-size: 12px; color: var(--muted); white-space: nowrap; }
.adj {
  width: 24px; height: 24px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.adj:hover { border-color: var(--accent); color: var(--accent); }
.adj.txt {                                  /* 文字版（复制/粘贴/删此节）：固定 24px 会把汉字挤成竖排溢出 */
  width: auto;
  min-width: 24px;
  padding: 0 7px;
  white-space: nowrap;
}

#bpm-input {
  width: 58px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 14px;
  text-align: center;
  outline: none;
}
#bpm-input:focus { border-color: var(--accent); }
.seg-count { font-size: 14px; min-width: 18px; text-align: center; }

/* 播放组（顶栏 BPM 左侧） */
.play-grp {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 4px;
  padding-right: 8px;
  border-right: 1px solid var(--line);
}
.pb {
  width: 28px; height: 26px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.pb:hover { border-color: var(--accent); color: var(--accent); }
#btn-play { min-width: 34px; }
#btn-play.play-on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.pb.active {
  background: #e2eeff;
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- 工作区（只有写谱区，无音色面板） ---------- */
#workspace {
  flex: 1;
  display: flex;
  flex-wrap: wrap;                 /* 窄屏时图例栏换到谱面下方 */
  min-height: 0;
  position: relative;
}

#sheet-area {
  flex: 1;
  min-width: 0;                    /* 允许被右侧图例栏挤压，谱面自身横向滚动 */
  max-height: 100%;                /* 关键：轨道再多也不许撑破工作区高度（否则整块压住底部工具栏），超出部分内部滚动 */
  overflow: auto;
  padding: 16px;
  background: transparent;         /* 通透：让底层 #breath-layer 的呼吸光透上来 */
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

/* 轨道工具条（写谱区顶部，随滚动吸附） */
#track-tools {
  position: sticky;
  top: -1px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: max-content;
  max-width: 100%;
  margin: 0 auto 12px;
  padding: 5px 12px;
  background: rgba(248, 250, 253, 0.92);
  backdrop-filter: blur(4px);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 1px 4px rgba(17, 24, 39, 0.05);
  flex-wrap: wrap;
}
.tt-label { font-size: 12px; color: var(--muted); }
.tt-count { font-size: 12px; font-weight: 700; color: var(--text); min-width: 30px; text-align: center; font-variant-numeric: tabular-nums; }
.tt-hint { font-size: 11px; color: var(--muted); padding-left: 6px; }
.zoom-chip {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 2px 8px;
  cursor: pointer;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.zoom-chip:hover { border-color: var(--accent); color: var(--accent); }

/* 缩放方向切换（↔ 横向 / ↕ 纵向 / ⤢ 整体）：− 与 ＋ 作用于当前方向 */
.zoom-modes {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  overflow: hidden;
  background: var(--panel);
}
.zoom-mode {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  padding: 5px 7px;
  cursor: pointer;
  font-family: inherit;
}
.zoom-mode + .zoom-mode { border-left: 1px solid var(--line); }
.zoom-mode:hover { color: var(--accent); }
.zoom-mode.active { background: #eef4fc; color: var(--accent); font-weight: 700; }

/* 迷你下拉（呼吸强度等） */
.tool-select-sm {
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  font-size: 12px;
  padding: 3px 4px;
  outline: none;
  cursor: pointer;
}
.tool-select-sm:focus { border-color: var(--accent); }
.tt-sep { width: 1px; height: 16px; background: var(--line); margin: 0 4px; }
.tt-beat { font-size: 12px; color: var(--accent); font-weight: 600; white-space: nowrap; }
#tuplet-sel {
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  font-size: 12px;
  padding: 3px 4px;
  outline: none;
  cursor: pointer;
}
#tuplet-sel:focus { border-color: var(--accent); }
.tool-mini {
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  font-size: 12px;
  padding: 3px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.tool-mini:hover { border-color: var(--accent); color: var(--accent); }
.tool-mini.active {
  border-color: var(--accent);
  background: #eef4fc;
  color: var(--accent);
  font-weight: 600;
}

/* 当前字形：输入框 + 颜色预览块 */
#paint-text {
  width: 92px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 13px;
  font-weight: 600;
  outline: none;
  text-align: center;
}
#paint-text:focus { border-color: var(--accent); }
.glyph-swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  padding: 0 6px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  border: 1.5px solid var(--line-strong);
  background: var(--panel2);
  color: var(--muted);
  white-space: nowrap;
}

/* 谱面：一个八拍一段，纵向排列 */
#grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  position: relative;
  min-height: 100%;
  width: max-content;
  margin: 0 auto;
  padding: 10px 16px;
}

/* 排列方式：竖排(默认) / 两列 / 横向（DAW 时间轴） */
#grid.layout-2col {
  display: grid;
  grid-template-columns: repeat(2, max-content);
  justify-content: center;
  align-content: start;                     /* 关键：行不摊分剩余高度（否则 min-height:100% 会把行撑开、卡片在行内垂直居中 → 行间隔巨大） */
  width: 100%;
  max-width: 100%;
  gap: 2px 14px;                            /* 行间距挨着（列间保留 14px 呼吸） */
}
#grid.layout-2col .seg-block { width: auto; }
#grid.layout-row {
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-start;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 8px;
}
#grid.layout-row .seg-block { flex: 0 0 auto; }

/* 节拍器音量滑条（顶栏） */
.metro-vol-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
#metro-vol {
  width: 88px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* 小节卡片：无边框 + 柔和阴影 + 大圆角（1 张卡片 = 1 小节 = 4 拍） */
.seg-block {
  border: none;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.05), 0 4px 14px rgba(17, 24, 39, 0.06);
  padding: 10px 12px 12px;
  position: relative;
}
.seg-block.current {
  box-shadow: 0 0 0 1px rgba(31, 111, 235, 0.18), 0 4px 16px rgba(31, 111, 235, 0.10);
}
.seg-block.current::before {
  content: '';
  position: absolute;
  left: 0; top: 14px; bottom: 14px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.seg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px 6px;
  font-size: 11px;
  color: #a2aab8;
  cursor: pointer;
  white-space: nowrap;
}
.seg-head:hover { color: var(--text); }
.seg-head .idx {
  background: #eef1f6;
  color: #5a6472;
  border-radius: 999px;
  padding: 2px 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.seg-block.current .seg-head .idx { background: #e2eeff; color: var(--accent); }
.seg-head .trk-badge {
  font-size: 10px;
  color: var(--accent);
  background: #e2eeff;
  border-radius: 999px;
  padding: 1px 7px;
  font-weight: 600;
}
.seg-head .beats { margin-left: auto; color: #b0b8c4; }

/* 拍号行：每小节 4 个拍数字（定位参考；点击 = 选拍并短显该拍格子） */
.track-row.tk-nums { margin-bottom: 10px; }  /* 底部留空：拍号数字与拍首点之间保持清晰间距 */
.beat-numbers { position: relative; height: 20px; }
.num-group {
  position: absolute;
  top: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 6px;
  line-height: 1;
}
.num-group:hover { background: rgba(31, 111, 235, 0.07); }
.num-group .beat-num {
  font-size: 12px;
  font-weight: 600;
  color: #aab2c0;
  user-select: none;
  font-variant-numeric: tabular-nums;
}
.num-group.sel { background: #e2eeff; }
.num-group.sel .beat-num { color: var(--accent); font-weight: 700; }

/* 轨道行：行头标签（左） + 拍号行 / 步骤行（右） */
.track-row { display: flex; align-items: flex-start; }
.track-row + .track-row { margin-top: 3px; }
.tk-label {
  width: 58px;
  flex-shrink: 0;
  height: var(--cell);          /* 跟随纵向缩放，与格子行等高对齐 */
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 0 6px 0 0;
  font-size: 11px;
  color: var(--muted);
  user-select: none;
  box-sizing: border-box;
  position: relative;              /* 轨道头重命名输入框绝对定位的锚点 */
}
.tk-blank { height: 12px; }
.tk-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.tk-label { cursor: pointer; border-radius: 6px; transition: background .12s; }
.tk-label:hover { background: var(--panel2); }
.tk-label.sel {
  background: var(--panel2);
  box-shadow: 0 0 0 1.5px var(--accent);
  color: var(--text);
}
.tk-name {
  max-width: 40px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  color: #7a8494;
}
.track-row:hover .tk-name { color: var(--text); }
/* 轨道头就地重命名输入框：撑满标签，右对齐与文字对齐 */
.track-input {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  text-align: right;
  padding: 0 5px;
  box-sizing: border-box;
  outline: none;
}
/* 全屏模式：隐藏顶部那行操作提示，画面更干净 */
body.is-fullscreen .tt-hint { display: none; }

/* 步骤行：格子由 JS 绝对定位（每格独立，不合并） */
.steps {
  position: relative;
  padding: 0;
  height: calc(var(--cell) + 10px);   /* 底部 10px 空隙 = 行距的一部分，给拍首点留空间 */
  touch-action: pan-y;   /* 纵向滑=滚页面；横向滑=连续写字 */
}
.steps > .step-cell { position: absolute; top: 0; }

/* 贯穿拍线层 */
.seg-lines { position: absolute; left: 0; right: 0; pointer-events: none; z-index: 1; }
.seg-lines .vline {
  position: absolute; top: 0; bottom: 0;
  width: 2px;
  background: var(--beatline);
  border-radius: 1px;
}

/* 播放光标：随 BPM 在谱面滑动的一条竖线（不演奏音色） */
.play-line {
  position: absolute;
  display: none;
  width: 3px;
  top: 0; bottom: 0;
  background: #ef4056;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(239, 64, 86, 0.18), 0 0 8px rgba(239, 64, 86, 0.45);
  pointer-events: none;
  z-index: 8;                               /* 播放光标最顶层：层级链 = 普通格 < 跳动格(6) < 编辑游标(7) < 播放光标(8) */
}
.play-line::before {
  content: '';
  position: absolute;
  top: -5px; left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #ef4056;
}
.play-line.playing { display: block; }

/* 格子：字号基准 = 拍槽宽/份数 × 0.46（--n 所在拍份数）。
   多字格子的缩字由 JS 的 fitCellFont() 按「实测文本宽度」决定：
   放得下就保持基准字号，放不下才等比缩 —— 这里的值只是 JS 未介入时的兜底。 */
.step-cell {
  width: var(--cell);
  height: var(--cell);
  border-radius: min(5px, 20%);
  border: 1px solid var(--cell-border);
  background: var(--cell-empty-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  font-size: clamp(7px, calc(var(--beat-w) / var(--n, 4) * 0.46), 20px);
  font-weight: 700;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.05s;
  white-space: nowrap;
}
.step-cell:hover { box-shadow: 0 1px 4px rgba(31, 111, 235, 0.18); }
.step-cell:active { transform: scale(0.92); }
.step-cell.empty { color: #c8ced8; font-weight: 400; }

/* 拍首标记点：每拍第 1 格（j=0）正上方的灰点 —— 独立 .beat-dot 层悬在格子
   外的行间空隙里（不占格子内部），示意该格是拍的起点；
   播放光标扫过该拍 → 点短暂闪亮绿（.lit）后自动回灰 */
.beat-dot {
  position: absolute;
  top: -11px;                       /* 距格子顶 7px，悬于行间空隙中部（数字/上行格不碰） */
  height: 4px;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}
.beat-dot::after {
  content: '';
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #c3cad6;
  box-shadow: inset 0 0 0 1px rgba(90, 100, 114, 0.3);
  transition: background 0.06s, box-shadow 0.06s;
}
.beat-dot.lit::after {
  background: #2ee06a;
  box-shadow: 0 0 5px rgba(46, 224, 106, 0.95);
}

/* 播放可视化：走带光标跨入格子时跳一下（pulse-w 普通格 / pulse-s 拍首格更大）
   pulse-s = 拍首格增强：弹跳 + 金罩闪底（::after，z-1 不遮字）+ 外圈金晕（box-shadow） */
.step-cell.pulse-w,
.step-cell.pulse-s { z-index: 6; }          /* 跳动格置顶：放大 + 金晕不被右侧/相邻格子盖住 */
.step-cell.pulse-w { animation: pulse-w 0.24s ease-out; }
.step-cell.pulse-s {
  isolation: isolate;                       /* 让金罩 z:-1 落在格底上方、文字下方 */
  animation: pulse-s 0.4s ease-out, gold-halo 0.5s ease-out;
}
.step-cell.pulse-s::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: #FAC775;
  opacity: 0;
  z-index: -1;
  pointer-events: none;
  animation: gold-cover 0.5s ease-out;
}
@keyframes gold-cover {
  0%   { opacity: 0; }
  18%  { opacity: 0.95; }
  62%  { opacity: 0.35; }
  100% { opacity: 0; }
}
@keyframes gold-halo {
  0%   { box-shadow: 0 0 0 0 rgba(239, 159, 39, 0); }
  22%  { box-shadow: 0 0 0 6px rgba(239, 159, 39, 0.55), 0 0 18px rgba(239, 159, 39, 0.35); }
  100% { box-shadow: 0 0 0 0 rgba(239, 159, 39, 0); }
}
@keyframes pulse-w {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.09) translateY(-3px); }
  100% { transform: scale(1) translateY(0); }
}
@keyframes pulse-s {
  0%   { transform: scale(1); }
  25%  { transform: scale(1.18) translateY(-7px); }
  55%  { transform: scale(1.06) translateY(-2px); }
  100% { transform: scale(1) translateY(0); }
}

/* 键盘游标：方向键选中的格子（蓝框 + 外发光，与配色描边不冲突）
   z-7 = 压过跳动格的 z-6：编辑游标永远在最上层 */
.step-cell.cursor {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.22);
  z-index: 7;
  font-weight: 700;
}

/* 拍位短显：选拍/切分/应用后，蓝环淡入淡出 1.5s（不影响格底色） */
.step-cell.beat-flash {
  animation: beat-flash 1.5s ease-out forwards;
}
@keyframes beat-flash {
  0%   { box-shadow: 0 0 0 0 rgba(31, 111, 235, 0); }
  15%  { box-shadow: 0 0 0 2px var(--accent), 0 0 10px rgba(31, 111, 235, 0.45); }
  100% { box-shadow: 0 0 0 0 rgba(31, 111, 235, 0); }
}

/* 双击编辑态：覆盖在格子上的输入框 */
.steps > .cell-input {
  position: absolute;
  top: 0;
  height: var(--cell);
  border: 2px solid var(--accent);
  border-radius: min(5px, 20%);
  background: #fff;
  color: var(--text);
  font-size: clamp(8px, calc(var(--beat-w) / var(--n, 4) * 0.38), 18px);
  font-weight: 700;
  text-align: center;
  outline: none;
  padding: 0 2px;
  z-index: 9;                               /* 必须压过被编辑格子自身的 .cursor(z-7)：否则双击输入框被自己的格子盖住（73ba0a1 回归）；层级链 = 格子 < 跳动(6) < 游标(7) < 播放线(8) < 输入框(9) */
  box-shadow: 0 2px 10px rgba(31, 111, 235, 0.25);
}

/* ---------- 底部（浅米） ---------- */
footer {
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--c-foot), #ffffff 60%);
  border-top: 1px solid var(--line);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#tools { display: flex; gap: 8px; flex-wrap: wrap; }
.tool-btn {
  padding: 6px 14px;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.tool-btn:hover { border-color: var(--accent); color: var(--accent); }
.tool-btn.active { border-color: var(--accent); color: var(--accent); background: #eef4ff; }
.tool-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.tool-btn.primary:hover { opacity: 0.9; color: #fff; }
.tool-btn.danger:hover { border-color: #e5534b; color: #e5534b; }

/* 导出 PNG 背景风格选择器（与工具按钮同风格） */
.tool-select {
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  outline: none;
}
.tool-select:hover { border-color: var(--accent); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1f2329;
  color: #fff;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  z-index: 99;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 音色字形面板（颜色 + 字形 + 名称 + 音色） ---------- */
.name-modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
}
.name-modal.hidden { display: none; }
.name-panel {
  width: min(880px, calc(100vw - 32px));
  max-height: min(78vh, 760px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 10px 34px rgba(17, 24, 39, 0.20);
  padding: 16px 18px;
}
.name-head { display: flex; align-items: center; justify-content: space-between; }
.name-title { font-size: 15px; font-weight: 700; color: var(--text); }
.name-desc { font-size: 12px; color: var(--muted); line-height: 1.65; }
.name-desc b { color: var(--text); }
.name-cols {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 11px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.3px;
}
.nc-swatch { width: 40px; flex-shrink: 0; text-align: center; }
.nc-glyph { width: 62px; flex-shrink: 0; text-align: center; }
.nc-name { width: 146px; flex-shrink: 0; }
.nc-audio { flex: 1; min-width: 0; }
.name-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  min-height: 64px;
  padding-right: 2px;
}
.name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 6px 10px;
  background: var(--panel2);
}
.name-row.none { justify-content: center; border-style: dashed; background: none; color: var(--muted); font-size: 13px; padding: 18px 10px; }

/* 色块（点击展开 12 色板；右下角小三角提示可点） */
.nr-swatch {
  position: relative;
  width: 40px;
  height: 34px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1.5px solid var(--line-strong);
  background: #fff;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}
.nr-swatch::after {
  content: '';
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-bottom: 5px solid currentColor;
  opacity: 0.5;
}
.nr-swatch:hover { border-color: var(--accent); }
.nr-glyph-input {
  width: 62px;
  flex-shrink: 0;
  text-align: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 6px 4px;
  font-size: 13px;
  font-weight: 700;
  outline: none;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
.nr-name-input {
  width: 146px;
  flex-shrink: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 13px;
  outline: none;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
.nr-glyph-input:focus, .nr-name-input:focus { border-color: var(--accent); }
.nr-glyph-input::placeholder, .nr-name-input::placeholder { color: #b3bcc9; }

/* 音色操作区 */
.nr-audio { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.nr-btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.nr-btn:hover { border-color: var(--accent); color: var(--accent); }
.nr-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.nr-btn:disabled:hover { border-color: var(--line-strong); color: var(--text); }
.nr-btn.rec-on { background: #e5534b; border-color: #e5534b; color: #fff; }
.nr-dur { font-size: 11px; color: var(--muted); }
.nr-none { font-size: 11px; color: #b3bcc9; }

/* 色板浮层（展开在行内，占满一行） */
.nr-palette {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}
.nr-color {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 6px;
  border: 1.5px solid rgba(0, 0, 0, 0.12);
  cursor: pointer;
}
.nr-color.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.nr-color-auto {
  height: 24px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
}
.nr-color-auto:hover { border-color: var(--accent); color: var(--accent); }
.name-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.name-count { font-size: 12px; color: var(--muted); margin-left: auto; }

/* ---------- 字形图例栏（可停靠右侧/底部，可拖拽改尺寸，含混音控制） ---------- */
.legend-panel {
  position: relative;                 /* 拖拽手柄的定位基准 */
  width: var(--legend-w, 170px);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 10px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow: hidden;
}
.legend-panel.hidden { display: none; }
/* 停靠底部：整条铺在谱面下方、横向排布；高度由拖拽手柄决定 */
.legend-panel.dock-bottom {
  flex: 0 0 100%;
  width: 100%;
  max-height: var(--legend-h, 168px);
  border-left: none;
  border-top: 1px solid var(--line);
}
.legend-panel.dock-bottom .legend-list {
  flex-direction: row;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 4px 18px;
}
.legend-panel.dock-bottom .legend-item { width: 206px; }
.legend-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.legend-head-btns { display: inline-flex; gap: 4px; }
.legend-title { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: 0.4px; }
.legend-list {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.legend-empty { font-size: 12px; color: var(--muted); padding: 8px 2px; }
.legend-item { display: flex; flex-direction: column; gap: 3px; }
.lg-row1 { display: flex; align-items: center; gap: 6px; }

/* 总音量区（图例头部下方常显） */
.legend-master {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel2);
}
.lm-label { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.lm-pct { font-size: 11px; color: var(--muted); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* 图标小按钮（总静音 / 单音色静音） */
.lg-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  font-family: inherit;
  cursor: pointer;
}
.lg-icon:hover { border-color: var(--accent); color: var(--accent); }
.lg-icon.on { background: #e5534b; border-color: #e5534b; color: #fff; }

/* 音量滑条（总音量 / 单音色共用） */
.lg-vol {
  -webkit-appearance: none;
  appearance: none;
  flex: 1 1 auto;
  min-width: 0;
  height: 4px;
  border-radius: 2px;
  background: var(--line-strong);
  outline: none;
  cursor: pointer;
}
.lg-vol::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line-strong);
  cursor: pointer;
}
.lg-vol::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  cursor: pointer;
}
.lg-vol.dim { opacity: 0.45; }

/* 拖拽手柄：停右侧时贴左缘调宽，停底部时贴顶缘调高 */
.legend-grip {
  position: absolute;
  z-index: 4;
  background: transparent;
  transition: background 0.15s;
  touch-action: none;
}
.legend-panel:not(.dock-bottom) .legend-grip { left: -1px; top: 0; bottom: 0; width: 8px; cursor: ew-resize; }
.legend-panel.dock-bottom .legend-grip { left: 0; right: 0; top: -1px; height: 8px; cursor: ns-resize; }
.legend-grip:hover, .legend-grip.dragging { background: rgba(31, 111, 235, 0.16); }
.legend-swatch {
  width: 32px;
  height: 26px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1.5px solid var(--line-strong);
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
}
.legend-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.legend-name.unnamed { color: #b3bcc9; font-size: 12px; font-weight: 400; }
/* 图例试听：有音色的字形右侧一枚小喇叭（基础样式复用 .lg-icon） */
.legend-play { font-size: 10px; }
.legend-play.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- 剪切台（音色掐头去尾） ---------- */
.trim-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
}
.trim-overlay.hidden { display: none; }
.trim-panel {
  width: min(780px, calc(100vw - 32px));
  max-height: calc(100vh - 56px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 10px 34px rgba(17, 24, 39, 0.24);
  padding: 16px 18px;
}
.trim-head { display: flex; align-items: center; justify-content: space-between; }
.trim-title { font-size: 15px; font-weight: 700; color: var(--text); }
.trim-tip { font-size: 12px; color: var(--muted); line-height: 1.65; }
#trim-canvas {
  width: 100%;
  height: auto;
  display: block;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 10px;
  touch-action: none;
  cursor: ew-resize;
}
.trim-info { font-size: 12px; color: var(--muted); }
.trim-info b { color: var(--text); font-weight: 700; }
.trim-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- 手机适配 ---------- */
@media (max-width: 720px) {
  :root { --cell-base: 26px; --beat-w-base: 116px; }
  .tk-label { width: 44px; padding-right: 4px; }
  .tk-name { display: none; }
  .tk-blank { display: block; height: 12px; }
  .tt-hint { display: none; }
  #paint-text { width: 72px; }
  #title-input { width: 110px; }
  .meta-input { width: 64px; }
  /* 图例栏：窄屏一律停靠在谱面下方（JS 同步补 .dock-bottom，这里是兜底） */
  .legend-panel {
    flex: 0 0 100%;
    width: 100%;
    max-height: var(--legend-h, 140px);
    padding: 8px 12px;
    border-left: none;
    border-top: 1px solid var(--line);
  }
  .legend-panel .legend-list { flex-direction: row; flex-wrap: wrap; align-content: flex-start; gap: 4px 14px; }
  .legend-panel .legend-item { width: 168px; }
  #legend-panel .legend-grip { left: 0; right: 0; top: -1px; bottom: auto; width: auto; height: 8px; cursor: ns-resize; }
  /* 音色面板 / 剪切台收窄 */
  .name-panel { width: calc(100vw - 20px); max-height: 86vh; padding: 12px; }
  .name-cols { display: none; }
  .nr-glyph-input { width: 52px; }
  .nr-name-input { width: 104px; }
  .trim-panel { width: calc(100vw - 20px); padding: 12px; }
}
