/* 有谱儿 · 网页版五线谱编辑器
 *
 * 仿 editor.drawthedots.com（abcjs 官方编辑器）的三栏结构：左栏写 ABC 记谱、
 * 右栏实时出谱、下方出二维码。差别在于「排版」这件事交给 abcjs，我们把
 * 精力放在「写谱 → 训练码」这条链上。
 *
 * 配色刻意用近黑 + 绿：和眼镜端的单色绿保持同一套语言，用户从浏览器看到
 * 的和戴在头上看到的是同一个应用。
 */

:root {
  --bg: #0b0f0c;
  --panel: #111713;
  --panel-2: #161d18;
  --line: #24302a;
  --line-strong: #35473d;
  --ink: #e6f2ea;
  --ink-dim: #8b9d93;
  --ink-faint: #5c6b62;
  --green: #40ff5e;
  --green-dim: rgba(64, 255, 94, 0.62);
  --green-faint: rgba(64, 255, 94, 0.14);
  --warn: #ffcc55;
  --bad: #ff6b6b;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

.top {
  height: 52px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 9px;
  flex-shrink: 0;
}

.brand-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--green);
}

.brand-sub {
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.3px;
}

/*
 * 示例曲标签。
 *
 * 曲库扩到 10 首之后，全部标签并排放不下 —— 顶栏总宽减去品牌与右侧按钮，
 * 剩下的横向空间约 500px，而 10 个标签每个 60–90px 加起来七百多。
 *
 * 处理方式是**横向滚动而不是换行**：顶栏高度 52 是定死的，换行会把
 * 第二行挤到 header 外面盖住正文。滚动条隐藏，靠触控板/触摸横滑，
 * 鼠标用户还有滚轮（浏览器默认把纵向滚轮映射到横向可滚容器）。
 */
.top-tabs {
  display: flex;
  gap: 2px;
  margin-left: 10px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.top-tabs::-webkit-scrollbar {
  display: none;
}

/* 标签不允许被压缩：压扁之后文字会被省略号吃掉，反而更难认 */
.top-tab {
  flex: 0 0 auto;
  white-space: nowrap;
  height: 30px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-dim);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

.top-tab:hover {
  color: var(--ink);
  background: var(--panel-2);
}

.top-tab.on {
  color: var(--green);
  border-color: var(--green-dim);
  background: var(--green-faint);
}

.top-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.btn {
  height: 32px;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--ink-dim);
  font-family: inherit;
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}

.btn:hover {
  color: var(--ink);
  border-color: var(--ink-faint);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  border-color: var(--green-dim);
  color: var(--green);
  background: var(--green-faint);
}

.btn.primary:hover {
  border-color: var(--green);
  background: rgba(64, 255, 94, 0.2);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn.sm {
  height: 26px;
  padding: 0 9px;
  font-size: 11.5px;
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
}

.btn.ghost:hover {
  background: var(--panel-2);
  border-color: var(--line);
}

/* ---------- 主布局 ---------- */

.work {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 0;
  height: calc(100vh - 52px);
  overflow: hidden;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.pane-edit {
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.pane-view {
  background: var(--bg);
}

/* ---------- 工具栏 ---------- */

.bars {
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(36, 48, 42, 0.55);
}

.bar:last-child {
  border-bottom: none;
}

.bar-label {
  width: 100%;
  margin-bottom: 1px;
  font-size: 10.5px;
  letter-spacing: 0.6px;
  color: var(--ink-faint);
  text-transform: uppercase;
}

.key {
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--panel-2);
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: 12.5px;
  cursor: pointer;
}

.key:hover {
  color: var(--ink);
  border-color: var(--ink-faint);
  background: #1b241e;
}

.key:active {
  transform: translateY(1px);
}

.key.wide {
  min-width: 44px;
}

.key.hot {
  color: var(--green);
  border-color: var(--green-dim);
  background: var(--green-faint);
}

/* ---------- 编辑器 ---------- */

.editor-wrap {
  flex: 1;
  min-height: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.editor {
  flex: 1;
  min-height: 200px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0d120f;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.72;
  tab-size: 2;
  resize: none;
  outline: none;
  caret-color: var(--green);
}

.editor:focus {
  border-color: var(--green-dim);
}

.editor::selection {
  background: rgba(64, 255, 94, 0.26);
}

.editor-foot {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  color: var(--ink-faint);
}

.editor-foot .grow {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 谱面 ---------- */

.score-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 18px 20px 26px;
}

.score-paper {
  min-height: 100%;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdfb;
  color: #10160f;
}

/* abcjs 输出的是 SVG，黑色描边在浅底上正好 */
.score-paper svg {
  display: block;
  max-width: 100%;
  height: auto;
}

.score-empty {
  height: 100%;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #6b7d72;
  font-size: 13px;
}

/* ---------- 状态条 ---------- */

.status {
  min-height: 30px;
  padding: 6px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  font-size: 11.5px;
  color: var(--ink-faint);
}

.status .grow {
  flex: 1;
}

.status .bad {
  color: var(--bad);
}

.status .warn {
  color: var(--warn);
}

.status .ok {
  color: var(--green-dim);
}

.chip {
  padding: 1px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 99px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-dim);
}

.chip.on {
  border-color: var(--green-dim);
  color: var(--green);
}

/* ---------- 二维码弹层 ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(4, 7, 5, 0.82);
  backdrop-filter: blur(3px);
}

.modal[hidden] {
  display: none;
}

.sheet {
  width: min(460px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 20px 12px;
}

.sheet-title {
  font-size: 15px;
  font-weight: 600;
}

.sheet-sub {
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--ink-faint);
  line-height: 1.5;
}

.sheet-body {
  padding: 4px 20px 18px;
}

.qr-stage {
  display: flex;
  justify-content: center;
  padding: 16px;
  border-radius: 12px;
  background: #fff;
}

.qr-stage canvas,
.qr-stage img,
.qr-stage table {
  display: block;
  image-rendering: pixelated;
}

.qr-stage table {
  border-collapse: collapse;
  border: 0;
}

.qr-stage td {
  padding: 0;
  margin: 0;
  line-height: 0;
  font-size: 0;
}

.qr-meta {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  font-size: 11px;
  color: var(--ink-faint);
}

.qr-meta b {
  color: var(--ink-dim);
  font-weight: 500;
}

.code-line {
  margin-top: 12px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0d120f;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--green-dim);
  word-break: break-all;
  user-select: all;
}

.note-box {
  margin-top: 12px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-left: 2px solid var(--warn);
  border-radius: 7px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--warn);
}

.sheet-foot {
  display: flex;
  gap: 8px;
  padding: 0 20px 18px;
}

.sheet-foot .grow {
  flex: 1;
}

/* ---------- 窄屏 ---------- */

@media (max-width: 900px) {
  .work {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(300px, 46vh) 1fr;
    height: auto;
  }

  .pane-edit {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .score-wrap {
    min-height: 46vh;
  }
}
