:root {
  --bg: #14110e;
  --bg-soft: #1a1612;
  --panel: #201b16;
  --panel-2: #272119;
  --line: #352d24;
  --text: #ece5da;
  --muted: #9d9384;
  --accent: #e6a95a;
  --accent-dim: #b4803f;
  --danger: #d4685c;
  --radius: 10px;
  --font-ui: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  --font-mono: "Cascadia Mono", "JetBrains Mono", Consolas, "Microsoft YaHei", monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  overflow: hidden;
  overscroll-behavior: none;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

.hidden { display: none !important; }

/* ---------- 外壳：左侧栏 + 内容区 ---------- */
.app {
  --sidebar-w: 268px;
  position: relative;
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.app.collapsed { --sidebar-w: 0px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 16px 16px 14px;
  font-weight: 600;
  letter-spacing: .04em;
  white-space: nowrap;
}

.brand-mark {
  width: 9px;
  height: 26px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  box-shadow: 0 0 12px rgba(230, 169, 90, .35);
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 10px 10px;
}

.tab {
  background: transparent;
  border: 0;
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  text-align: left;
}

.tab:hover { color: var(--text); background: var(--panel); }
.tab.active { color: var(--bg); background: var(--accent); font-weight: 600; }

/* 侧栏边缘的收起 / 展开把手 */
.rail-toggle {
  position: fixed;
  left: var(--sidebar-w);
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  width: 18px;
  height: 52px;
  padding: 0;
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 8px 8px 0;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  opacity: .55;
  transition: left .22s ease, opacity .15s, background .15s, color .15s, border-color .15s;
}
.rail-toggle:hover { opacity: 1; background: #312920; color: var(--accent); }
.app.collapsed .rail-toggle { opacity: .95; color: var(--accent); border-color: var(--accent-dim); }

/* ---------- 按钮 ---------- */
.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 13px;
  color: var(--text);
  transition: background .15s, border-color .15s, color .15s;
}

.btn:hover { background: #312920; border-color: #4a3d30; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:disabled:hover { background: var(--panel-2); border-color: var(--line); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1b1206; font-weight: 600; }
.btn.primary:hover { background: #f0b96d; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); background: rgba(212, 104, 92, .1); }
.btn.danger-ghost { color: var(--muted); }
.btn.danger-ghost:hover { color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: 12px; }

/* ---------- 页面骨架 ---------- */
main {
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

.back-btn { display: none; }
.mobile-only { display: none; }
.hint-mobile { display: none; }
.grid-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.page { display: none; height: 100%; }
.page.active { display: flex; }

/* ---------- 左侧栏 ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  border-right: 1px solid var(--line);
  background: var(--bg-soft);
  overflow: hidden;
  transition: flex-basis .22s ease, width .22s ease;
}
.app.collapsed .sidebar { border-right-color: transparent; }

.sidebar-inner {
  width: 268px;
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  padding: 0 12px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.new-song { width: 100%; padding: 9px 13px; }

/* ---------- 曲谱页 ---------- */
#page-songs.active { display: flex; }

#song-search {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
#song-search:focus { border-color: var(--accent-dim); }
#song-search::placeholder { color: #6b6255; }

.song-items { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; }

.song-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 6px 8px 10px;
}
.song-item:hover { background: var(--panel); }
.song-item.active { background: var(--panel-2); border-color: var(--line); }

.song-pick {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  background: transparent;
  border: 0;
  padding: 0;
  text-align: left;
}
.song-item .t { font-size: 14px; font-weight: 500; }
.song-item.active .t { color: var(--accent); }
.song-item .m { font-size: 11.5px; color: var(--muted); }

.song-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.song-item:hover .song-actions,
.song-item.active .song-actions { opacity: 1; }
.icon-btn {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}
.icon-btn:hover { background: var(--panel-2); border-color: var(--line); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 4px;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  font-size: 10px;
  line-height: 15px;
  vertical-align: 1px;
  font-weight: 400;
}

/* 图片曲谱 */
.score-images {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.score-page {
  position: relative;
  width: 100%;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .35);
}
.score-img {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  border-radius: 6px;
  cursor: zoom-in;
}

/* 图片上的节拍编号：坐标归一化，随图片缩放自动对齐 */
.beat-markers {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 6px;
}
.beat-marker {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  border: 1px solid rgba(90, 170, 255, .9);
  background: rgba(28, 82, 160, .65);
  color: #a9d4ff;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  opacity: .3;
  transform: translate(-50%, -50%);
  transform-origin: center;
  transition: transform .12s ease, background .12s ease, color .12s ease, box-shadow .12s ease, opacity .12s ease;
}
.beat-marker.active {
  background: #8b1a1a;
  border-color: #ff9a9a;
  color: #fff0f0;
  opacity: .7;
  transform: translate(-50%, -50%) scale(1.9);
  box-shadow: 0 0 14px rgba(160, 24, 24, .8);
  z-index: 2;
}

/* 演奏时的单页模式：只显示当前页，整页缩放到可视区域内 */
.song-view.page-mode .song-scroll {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.song-view.page-mode .score-images {
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
}
.song-view.page-mode .score-page { display: none; }
.song-view.page-mode .score-page.current {
  display: block;
  margin: 0 auto;
}
.song-view.page-mode .score-page.current img {
  width: 100%;
  height: auto;
  max-width: none;
  max-height: none;
  cursor: default;
}

/* ---------- 演奏模式：隐藏多余信息，把空间留给图谱与节拍 ---------- */
.app.performing .sidebar,
.app.performing .rail-toggle { display: none; }
.song-view.performing { padding-top: env(safe-area-inset-top); }
.song-view.performing .song-head { display: none; }
.song-view.performing .song-scroll {
  padding: 8px 10px calc(76px + env(safe-area-inset-bottom));
}
.song-view.performing.page-mode .song-scroll {
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  overflow: hidden;
}

/* 节拍条：桌面与手机统一显示在曲谱顶部 */
.song-view.performing .beat-bar:not(.hidden) {
  display: flex;
  gap: 6px;
  width: min(calc(100% - 12px), 960px);
  margin: 8px auto 2px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(20, 17, 14, .6);
}
.song-view.performing .beat-bar span {
  flex: 1;
  height: 18px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .07);
  transition: background .12s ease, transform .12s ease;
}
.song-view.performing .beat-bar span.passed { background: rgba(217, 168, 92, .35); }
.song-view.performing .beat-bar span.now { background: var(--accent); transform: scaleY(1.35); }

.perform-exit {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 78;
  min-width: 84px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid rgba(230, 169, 90, .5);
  background: rgba(20, 17, 14, .74);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  backdrop-filter: blur(4px);
  opacity: .7;
  transition: opacity .15s, background .15s, color .15s;
}
.perform-exit:hover { background: var(--accent); color: #1b1206; opacity: .85; }

.zoom-label {
  min-width: 42px;
  text-align: center;
  font-size: 12px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(4, 3, 2, .94);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 16px;
  cursor: zoom-out;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  background: #fff;
  border-radius: 4px;
}

/* ---------- 节拍标记窗口 ---------- */
.marker-mask {
  position: fixed;
  inset: 0;
  z-index: 86;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(6, 5, 3, .9);
  backdrop-filter: blur(3px);
}
.marker-panel {
  width: min(1200px, 100%);
  height: calc(100vh - 32px);
  height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
}
.marker-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.marker-title { font-size: 15px; font-weight: 600; }
.marker-tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.marker-beat {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.marker-beat input { width: 78px; padding: 5px 8px; }
.marker-tip {
  margin: 0;
  padding: 8px 16px 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: #6f665a;
}
.marker-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  overflow: auto;
}
.marker-canvas {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  cursor: crosshair;
  background: #fff;
  border-radius: 4px;
}
#marker-img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 250px);
  max-height: calc(100dvh - 250px);
  background: #fff;
  border-radius: 4px;
  pointer-events: none;
}
.marker-layer { position: absolute; inset: 0; pointer-events: none; }
.marker-layer .beat-marker {
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  font-size: 12px;
}
.marker-layer .beat-marker.selected {
  background: #3b97ff;
  border-color: #b8dcff;
  color: #06172c;
  opacity: .3;
  box-shadow: 0 0 10px rgba(59, 151, 255, .75);
  transform: translate(-50%, -50%) scale(1.35);
  z-index: 3;
}
.marker-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.marker-status { min-width: 0; }
.marker-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.empty-small { padding: 20px 12px; color: var(--muted); font-size: 12.5px; line-height: 1.7; }

/* ---------- 曲谱正文 ---------- */
.song-view {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.placeholder {
  margin: auto;
  text-align: center;
  color: var(--muted);
}
.placeholder-title { font-size: 16px; color: #c9bfae; margin-bottom: 6px; }

.song-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 26px 14px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.song-head h1 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: .02em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.title-edit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
}
.title-edit:hover { color: var(--accent); background: var(--panel-2); border-color: var(--line); }

.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 12.5px; }

.song-tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.seg-group {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
}
.seg-group button {
  background: transparent;
  border: 0;
  padding: 6px 10px;
  color: var(--text);
}
.seg-group button:hover { background: #3a3026; }
.seg-group .tr {
  min-width: 42px;
  text-align: center;
  font-size: 12px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.scroll-speed {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px;
}
.speed-label { font-size: 12px; color: var(--muted); }
.scroll-speed input[type="range"] { width: 120px; }
.scroll-speed output {
  min-width: 24px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  cursor: text;
  border-bottom: 1px dashed transparent;
}
.scroll-speed output:hover { border-bottom-color: var(--accent-dim); }
.speed-input {
  width: 52px;
  padding: 2px 5px;
  text-align: center;
  color: var(--accent);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  border-color: var(--accent-dim);
  -moz-appearance: textfield;
}
.speed-input::-webkit-outer-spin-button,
.speed-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.song-scroll {
  flex: 1;
  overflow: auto;
  padding: 22px 26px 80px;
  scroll-behavior: auto;
}

.song-content {
  font-family: var(--font-mono);
  font-size: 17px;
  line-height: 1.5;
  max-width: 900px;
}

.line { min-height: 1.2em; }
.line.gap { height: .9em; }
.line.plain { color: var(--muted); white-space: pre-wrap; margin: 4px 0; }

.line.chords { margin: 2px 0 10px; }

.seg { display: inline-block; vertical-align: top; }

.chord {
  display: block;
  color: var(--accent);
  font-size: .74em;
  font-weight: 600;
  line-height: 1.6;
  letter-spacing: .01em;
}

.lyr { display: block; white-space: pre-wrap; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(8, 6, 4, .7);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.modal {
  width: 680px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}

.modal h2 { margin: 0 0 16px; font-size: 17px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); }

input, select, textarea {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent-dim); }

select { cursor: pointer; }

label.full { display: flex; margin-top: 4px; }

.kind-switch {
  display: inline-flex;
  gap: 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 3px;
  margin-bottom: 16px;
}
.kind-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 6px 16px;
  border-radius: 7px;
  font-size: 13px;
}
.kind-btn:hover { color: var(--text); }
.kind-btn.active { background: var(--accent); color: #1b1206; font-weight: 600; }

.upload-box {
  position: relative;
  border: 1px dashed #4a3d30;
  border-radius: 10px;
  padding: 22px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, .015);
  transition: border-color .15s, background .15s;
}
.upload-box:hover, .upload-box.drag {
  border-color: var(--accent-dim);
  background: rgba(230, 169, 90, .05);
}
.sheet-file {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.upload-title { font-size: 13.5px; color: var(--text); margin-bottom: 5px; }
.upload-sub { font-size: 11.5px; }

.upload-status { min-height: 18px; font-size: 12px; color: var(--accent); margin-top: 8px; }
.upload-status.err { color: var(--danger); }

.image-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 6px;
}
.thumb {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}
.thumb img { display: block; width: 100%; height: 96px; object-fit: cover; cursor: zoom-in; }
.thumb-bar {
  display: flex;
  justify-content: center;
  gap: 2px;
  padding: 4px;
  background: var(--panel-2);
}
.thumb-bar button {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 12px;
}
.thumb-bar button:hover { background: #3a3026; color: var(--text); }
.thumb-bar button.del:hover { color: var(--danger); }
.thumb-mark {
  display: block;
  width: 100%;
  padding: 5px 4px;
  border: 0;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  touch-action: manipulation;
}
.thumb-mark:hover { background: #3a3026; color: var(--accent); }
.thumb-mark.on { color: var(--accent); }

textarea {
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.65;
  resize: vertical;
  tab-size: 2;
}

.form-tip { color: #6f665a; font-size: 11.5px; margin: 8px 0 0; }

/* 多套图片曲谱 */
.sheet-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px 12px;
  margin-bottom: 10px;
  background: rgba(255, 255, 255, .015);
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.sheet-head label { flex: 0 0 auto; font-size: 12px; color: var(--muted); }
.sheet-name { flex: 1; min-width: 0; }
.sheet-del {
  flex: 0 0 auto;
  background: transparent;
  border: 0;
  padding: 4px 7px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
}
.sheet-del:hover { color: var(--danger); background: rgba(212, 104, 92, .1); }
.add-sheet-btn {
  display: block;
  width: 100%;
  border-style: dashed;
  color: var(--muted);
}
.add-sheet-btn:hover { color: var(--accent); border-color: var(--accent-dim); }
.sheet-select {
  max-width: 190px;
  min-width: 0;
  padding: 5px 8px;
}

.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}

.form-err { color: var(--danger); font-size: 12.5px; margin-right: auto; }

/* ---------- 鼓机页 ---------- */
#page-drums.active { display: flex; }

.drum-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 26px;
}

.drum-panel {
  max-width: 1080px;
  margin: 0 auto;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
}

.drum-top {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }

#pattern-select { min-width: 190px; }

.transport {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.transport .field { flex-direction: row; align-items: center; gap: 9px; }
.transport input[type="range"] { width: 190px; accent-color: var(--accent); }
.transport output { color: var(--accent); font-variant-numeric: tabular-nums; min-width: 30px; text-align: right; }
.transport .unit { margin-left: -4px; }
.vol-field input[type="range"] { width: 100px; }

.play { min-width: 92px; }

/* 演奏倒计时 */
.countdown {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 6, 4, .55);
  backdrop-filter: blur(1.5px);
  pointer-events: none;
}
.countdown-num {
  font-size: clamp(150px, 32vw, 300px);
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  text-shadow: 0 0 46px rgba(230, 169, 90, .5);
  font-variant-numeric: tabular-nums;
}
.countdown-num.pop { animation: countPop .45s ease-out; }
@keyframes countPop {
  0% { transform: scale(.45); opacity: .15; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* 演奏时居中显示的鼓点图 */
.perform-grid {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 70;
  width: min(88vw, 700px);
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(20, 17, 14, .6);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
  opacity: .3;
  pointer-events: none;
}
.pg-row {
  display: grid;
  grid-template-columns: 40px repeat(var(--steps, 16), minmax(0, 1fr));
  gap: 3px;
  margin-bottom: 4px;
}
.pg-row:last-child { margin-bottom: 0; }
.pg-label {
  display: flex;
  align-items: center;
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}
.pg-cell {
  height: 11px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .07);
}
.pg-cell.beat { background: rgba(230, 169, 90, .14); }
.pg-cell.on { background: var(--accent); }
.pg-cell.now { outline: 1px solid rgba(255, 255, 255, .6); }
.pg-cell.now.first { outline-color: var(--danger); background: rgba(212, 104, 92, .3); }
.pg-cell.now.first.on { background: var(--danger); animation: beatPulse .18s ease-out; }

/* 每小节第 1 拍的鼓点放大脉冲 */
@keyframes beatPulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.5); }
  100% { transform: scale(1); }
}

/* 手机演奏节拍条：默认隐藏，仅演奏时在曲谱上方显示 */
.beat-bar { display: none; }

.grid-head {
  display: grid;
  grid-template-columns: 66px 1fr;
  gap: 8px;
  margin: 22px 0 8px;
  color: var(--muted);
  font-size: 11px;
}

.row-label-head { align-self: end; }

.beat-numbers {
  display: grid;
  grid-template-columns: repeat(var(--steps, 16), minmax(0, 1fr));
  gap: 5px;
}
.beat-numbers span { text-align: center; font-variant-numeric: tabular-nums; }
.beat-numbers span.beat { color: var(--accent); font-weight: 600; }
.beat-numbers span.now { color: var(--text); }
.beat-numbers span.now.first { color: var(--danger); font-weight: 700; animation: beatPulse .18s ease-out; }

.drum-grid {
  display: grid;
  grid-template-columns: 66px repeat(var(--steps, 16), minmax(0, 1fr));
  gap: 5px;
  align-items: stretch;
}

.row-label {
  display: flex;
  align-items: center;
  font-size: 12.5px;
  color: var(--muted);
  padding-right: 4px;
}

.cell {
  height: 38px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 0;
  transition: background .1s, border-color .1s, box-shadow .1s;
}
.cell:hover { border-color: #5a4a38; background: var(--panel-2); }
.cell.beat { border-color: #443a2e; }
.cell.on { background: var(--accent); border-color: var(--accent); }
.cell.on:hover { background: #f0b96d; }
.cell.now { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .55); }
.cell.now.on { box-shadow: inset 0 0 0 2px #fff; }
.cell.now:not(.on) { background: #3a3126; }
.cell.now.first { box-shadow: inset 0 0 0 2px var(--danger); }
.cell.now.first:not(.on) { background: rgba(212, 104, 92, .22); }
.cell.now.first.on { background: var(--danger); border-color: var(--danger); box-shadow: inset 0 0 0 2px var(--danger); animation: beatPulse .18s ease-out; }

.hint { color: #6f665a; font-size: 11.5px; margin: 16px 0 0; }

/* ---------- 侧栏底部：当前用户 ---------- */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}
.user-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12.5px;
}
.user-name::before { content: "● "; color: var(--accent-dim); }

/* ---------- 登录 / 注册 ---------- */
.auth-mask {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 22%, #241d15 0%, var(--bg) 68%);
}
.auth-card {
  width: 340px;
  max-width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}
.auth-brand { padding: 0 0 16px; }
.auth-tabs { display: flex; width: 100%; margin-bottom: 16px; }
.auth-tabs .kind-btn { flex: 1; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-err {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 12.5px;
}
.auth-submit { width: 100%; padding: 9px 13px; }
.auth-tip { margin: 12px 0 0; color: #6f665a; font-size: 11.5px; line-height: 1.6; }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #3a3129; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 手机 / 窄屏 ---------- */
@media (max-width: 820px) {
  /* 手机：侧栏铺满全屏，与正文单栏切换 */
  .app { display: block; }
  .rail-toggle { display: none; }
  .sidebar {
    position: absolute;
    inset: 0;
    width: 100%;
    flex: 0 0 auto;
    border-right: 0;
    z-index: 3;
  }
  .app.song-open .sidebar,
  .app.drums-open .sidebar { display: none; }
  .sidebar-inner { width: 100%; }
  main { height: 100%; }

  .sidebar-brand { padding: 14px 14px 10px; font-size: 13px; }
  .brand-mark { width: 7px; height: 20px; }
  .tabs { flex-direction: row; padding: 0 12px 10px; }
  .tab { width: auto; padding: 7px 14px; font-size: 13px; text-align: center; }
  .btn { padding: 8px 12px; }

  .sidebar-head { padding: 0 12px 12px; }
  #song-search { font-size: 16px; padding: 10px 12px; }
  .song-items { padding: 6px 8px 24px; }
  .song-item { padding: 10px 8px 10px 12px; }
  .song-item .t { font-size: 15px; }
  .song-item .m { font-size: 12px; }
  /* 手机没有 hover，操作按钮常显 */
  .song-actions { opacity: 1; }
  .icon-btn { width: 30px; height: 30px; font-size: 14px; }

  .song-head { padding: 12px 14px 10px; gap: 10px; }
  .song-head h1 { font-size: 19px; margin-bottom: 4px; }
  .meta { font-size: 12px; gap: 4px 10px; }
  .song-tools {
    margin-left: 0;
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }
  .song-tools > * { flex: 0 0 auto; }
  .sheet-select { max-width: none; flex: 1 1 0; min-width: 0; }
  .title-edit { width: 28px; height: 28px; font-size: 15px; }
  .sheet-card { padding: 10px; }
  .back-btn { display: inline-flex; align-items: center; }
  .mobile-only { display: inline-flex; align-items: center; }
  .song-scroll { padding: 14px 14px 70px; }
  .line.chords { margin: 2px 0 12px; }
  .scroll-speed input[type="range"] { display: none; }
  .song-tools .zoom-group { display: none; }
  .score-img { border-radius: 4px; }

  /* 弹窗改为底部抽屉 */
  .modal-mask { padding: 0; align-items: flex-end; }
  .modal {
    width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: 16px 16px 0 0;
    border-bottom: 0;
    padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  }
  .modal h2 { font-size: 16px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .form-grid label:first-child { grid-column: 1 / -1; }
  input, select, textarea { font-size: 16px; }
  .modal-foot {
    position: sticky;
    bottom: 0;
    background: var(--bg-soft);
    padding-top: 12px;
    margin-top: 14px;
    border-top: 1px solid var(--line);
  }
  .upload-box { padding: 18px 12px; }
  .upload-title { font-size: 13px; }
  .image-preview { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
  .thumb img { height: 76px; }

  /* 节拍标记窗口铺满手机屏幕 */
  .marker-mask { padding: 0; }
  .marker-panel {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }
  .marker-head { padding: 10px 12px; gap: 8px; }
  .marker-title { width: 100%; font-size: 14px; }
  .marker-tools { margin-left: 0; width: 100%; gap: 6px; }
  .marker-tools .btn { padding: 6px 9px; font-size: 12px; }
  .marker-beat input { width: 72px; }
  .marker-tip { padding: 8px 12px 0; font-size: 11px; }
  .marker-stage { padding: 8px 12px; }
  #marker-img { max-height: calc(100dvh - 300px); }
  .marker-foot {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  }
  .marker-status { flex: 1 1 100%; }
  .marker-nav { margin-left: 0; width: 100%; justify-content: space-between; }

  /* 鼓机 */
  .drum-wrap { padding: 10px; }
  .drum-panel { padding: 12px; border-radius: 12px; }
  .drum-top {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
    align-items: end;
  }
  .drum-top .field { grid-column: 3 / 7; grid-row: 1; min-width: 0; }
  #btn-drums-back { grid-column: 1 / 3; grid-row: 1; }
  #btn-save-pattern { grid-column: 1 / 3; grid-row: 2; }
  #btn-delete-pattern { grid-column: 3 / 5; grid-row: 2; }
  #btn-clear { grid-column: 5 / 7; grid-row: 2; }
  #pattern-select { min-width: 0; width: 100%; }
  .transport { gap: 10px; margin-top: 12px; padding-top: 12px; }
  .play { min-width: 84px; padding: 9px 16px; }
  .transport .field { flex: 1 1 0; min-width: 0; }
  .transport .vol-field { flex: 1 1 100%; }
  .transport input[type="range"] { flex: 1; width: auto; min-width: 0; }
  .vol-field input[type="range"] { width: auto; }
  .grid-scroll { margin: 14px -2px 0; }
  .grid-head {
    margin: 0 0 8px;
    grid-template-columns: 52px 1fr;
    gap: 4px;
    min-width: calc(52px + var(--steps, 16) * 34px);
  }
  .drum-grid {
    grid-template-columns: 52px repeat(var(--steps, 16), minmax(30px, 1fr));
    gap: 4px;
    min-width: calc(52px + var(--steps, 16) * 34px);
  }
  .beat-numbers { gap: 4px; }
  .cell { height: 34px; border-radius: 5px; }
  .row-label {
    font-size: 11.5px;
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--bg-soft);
  }
  .row-label-head {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--bg-soft);
  }
  .hint { font-size: 11px; margin-top: 12px; }
  .hint-desktop { display: none; }
  .hint-mobile { display: inline; }
}

@media (max-width: 380px) {
  .tab { padding: 7px 10px; }
  .song-head h1 { font-size: 18px; }
}
