/* ==========================================================================
 * 简谱工坊 · style.css  （移动优先；兼容旧版 Chromium 内核的国产浏览器：
 * 不使用 flex gap / inset / color-mix / max() 等较新特性）
 * ========================================================================== */
:root {
  --bg: #efece6; --paper: #fffdf9; --ink: #1f1f23; --muted: #7b7b85; --line: #e3dfd6; --bar: #ffffff;
  --accent: #0f766e; --accent-soft: rgba(15, 118, 110, .14); --accent-ink: #ffffff;
  --play-hl: #fde68a; --cur-meas: rgba(253, 230, 138, .3); --sel-bg: rgba(15, 118, 110, .16);
  --danger: #b42318; --danger-soft: rgba(180, 35, 24, .45); --warn: #b45309;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .06);
  --radius: 12px;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --score-font: Georgia, "Times New Roman", "Noto Serif", "Noto Serif CJK SC", "Songti SC", "SimSun", serif;
}
[data-theme="dark"] {
  --bg: #111417; --paper: #1a1e23; --ink: #e7e5e0; --muted: #9a9aa3; --line: #2d333b; --bar: #1b1f24;
  --accent: #2dd4bf; --accent-soft: rgba(45, 212, 191, .18); --accent-ink: #06201d;
  --play-hl: #a16207; --cur-meas: rgba(161, 98, 7, .35); --sel-bg: rgba(45, 212, 191, .22);
  --danger: #f87171; --danger-soft: rgba(248, 113, 113, .45); --warn: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--ui-font);
  display: flex; flex-direction: column; overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button:active { transform: scale(.97); }
svg { display: block; }

/* ---------- 顶部 ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px 6px 12px; padding-top: calc(6px + env(safe-area-inset-top));
  background: var(--bar); border-bottom: 1px solid var(--line);
}
.hdr-left { min-width: 0; display: flex; flex-direction: column; }
.app-name { font-size: 11px; color: var(--accent); font-weight: 700; letter-spacing: .1em; }
.hdr-title { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 62vw; }
.hdr-right { display: flex; flex: none; margin-left: 8px; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid transparent; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; color: var(--ink); flex: none;
}
.icon-btn:disabled { opacity: .3; transform: none; cursor: default; }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
svg.s { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 播放条 ---------- */
.transport {
  display: flex; align-items: center; padding: 6px;
  background: var(--bar); border-bottom: 1px solid var(--line);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.transport::-webkit-scrollbar { display: none; }
.transport > * + * { margin-left: 3px; }
.tbtn {
  min-width: 34px; height: 40px; padding: 0 6px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); display: inline-flex; align-items: center; justify-content: center; flex: none; color: var(--ink);
}
.tbtn svg { width: 22px; height: 22px; fill: currentColor; }
.tbtn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); min-width: 48px; }
.tbtn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tempo { display: flex; align-items: center; flex: none; padding: 0 4px 0 8px; }
.tempo > * + * { margin-left: 4px; }
.tempo input[type=range] { width: 52px; margin: 0; }
.tempo b { min-width: 2.1em; text-align: center; font-variant-numeric: tabular-nums; font-size: 14px; }
.select {
  height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  padding: 0 4px; font-size: 14px; flex: none; width: 72px;
}

/* ---------- 谱面 ---------- */
#scroller { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 10px 8px 24px; }
#paper {
  background: var(--paper); max-width: 920px; margin: 0 auto; padding: 14px 10px 30px;
  border-radius: 14px; box-shadow: var(--shadow); min-height: 55%;
}
#score {
  font-family: var(--score-font); font-size: var(--fs, 24px); color: var(--ink); line-height: 1;
  --cw: 1.15em;
}
.shead { text-align: center; margin: .2em 0 .7em; }
.stitle { font-size: 1.5em; font-weight: 700; letter-spacing: .06em; }
.sby { font-size: .66em; color: var(--muted); margin-top: .35em; font-family: var(--ui-font); }
.sig { display: flex; align-items: center; font-size: .8em; margin: 0 0 .5em .2em; }
.sig > * + * { margin-left: .7em; }
.sigkey { font-weight: 700; }
.tsig { display: inline-flex; flex-direction: column; align-items: center; line-height: 1; font-weight: 700; font-size: 1.15em; font-family: var(--ui-font); }
.tsig b { font-weight: 700; }
.tsig b + b { border-top: .09em solid currentColor; margin-top: .06em; padding-top: .06em; }
.sigtempo { color: var(--muted); }

.flow { display: flex; flex-wrap: wrap; align-items: flex-start; }
.sysbreak { flex-basis: 100%; height: 0; }

.measure {
  position: relative; display: flex; min-height: 6.2em; margin-bottom: 1.3em;
  padding: 1.4em .45em .3em .55em;
  border-right: .09em solid var(--ink);
}
.measure.cur { background: var(--cur-meas); }
.measure.last { border-right-width: .14em; }
.measure.last::after {
  content: ''; position: absolute; right: -.4em; top: 1.4em; bottom: .3em; width: .07em; background: var(--ink);
}
.measure.repStart { border-left: .14em solid var(--ink); padding-left: .7em; }
.measure.repStart::before, .measure.repEnd::after {
  content: ''; position: absolute; width: .22em; height: .22em; border-radius: 50%; background: var(--ink);
  top: 2.65em; box-shadow: 0 .5em 0 var(--ink);
}
.measure.repStart::before { left: .2em; }
.measure.repEnd { border-right-width: .14em; padding-right: .7em; }
.measure.repEnd::after { right: .2em; }
.mnum {
  position: absolute; top: .15em; left: .35em; font-size: .46em; line-height: 1;
  color: var(--muted); font-family: var(--ui-font); font-variant-numeric: tabular-nums;
}
.mnum.under { color: var(--warn); font-weight: 700; }
.mnum.over { color: var(--danger); font-weight: 700; }
.mlabel {
  position: absolute; top: .1em; right: .55em; font-size: .5em; line-height: 1;
  color: var(--accent); font-weight: 700; font-family: var(--ui-font);
}
.mnotes { display: flex; align-items: flex-end; }
.mnotes > * + * { margin-left: .1em; }
.empty-m { display: inline-block; width: 1.8em; height: 1.3em; border-bottom: .07em dashed var(--line); margin-bottom: .4em; }

.note {
  position: relative; display: flex; flex-direction: column; align-items: flex-start;
  padding: .05em .1em; border-radius: .25em; cursor: pointer; min-width: var(--cw);
}
.note.sel { background: var(--sel-bg); }
.measure.has-mark { padding-top: 2em; }
.note .mark {
  position: absolute; bottom: 100%; left: -.05em; margin-bottom: .08em;
  font-size: .5em; color: var(--muted); font-weight: 600; white-space: nowrap; font-family: var(--ui-font); line-height: 1;
}
.note.hasc .mark { margin-bottom: 1.2em; }   /* 放在和弦上方：和弦高 .58em，1.2 × .5em = .6em */
.note.playing { background: var(--play-hl); box-shadow: 0 0 0 .07em var(--accent); }
.chord {
  position: absolute; bottom: 100%; left: -.05em; margin-bottom: -.1em;
  font-size: .58em; font-weight: 700; color: var(--accent); white-space: nowrap; font-family: var(--ui-font); line-height: 1;
}
.hdots, .ldots { height: .85em; display: flex; flex-direction: column; align-items: center; min-width: var(--cw); }
.hdots { justify-content: flex-end; }
.ldots { justify-content: flex-start; }
.hdots i, .ldots i { display: block; width: .3em; height: .3em; border-radius: 50%; background: currentColor; }
.hdots i + i, .ldots i + i { margin-top: .06em; }
.cells { position: relative; display: flex; align-items: center; height: 1.4em; line-height: 1.4em; }
.cell { display: inline-block; text-align: center; min-width: var(--cw); position: relative; }
.cell.num { font-weight: 700; font-variant-numeric: tabular-nums; }
.note.rest .cell.num { color: var(--muted); font-weight: 400; }
.cell.num.ul1::after, .cell.num.ul2::after, .cell.num.ul2::before {
  content: ''; position: absolute; left: .1em; right: .1em; height: .085em; border-radius: 1px; background: currentColor;
}
.cell.num.ul1::after, .cell.num.ul2::after { bottom: .22em; }
.cell.num.ul2::before { bottom: .5em; }
.acc { font-size: .7em; vertical-align: .2em; margin-right: .03em; font-weight: 500; }
.dot { display: inline-block; width: .26em; height: .26em; border-radius: 50%; background: currentColor; margin-left: .1em; vertical-align: .08em; }
.cell.dash { min-width: .95em; font-weight: 400; }
.tie {
  position: absolute; right: -.55em; width: 1em; height: .46em; top: .02em;
  border: .075em solid currentColor; border-bottom: 0;
  border-radius: .55em .55em 0 0 / .5em .5em 0 0; pointer-events: none;
}
.lyr {
  height: 1.4em; line-height: 1.4em; font-size: .88em; min-width: var(--cw);
  white-space: nowrap; font-family: var(--ui-font); text-align: center;
}
.lyr.melisma { color: var(--muted); }
.caret {
  display: inline-block; align-self: stretch; width: .11em; margin: 0 0 0 .06em;
  background: var(--accent); border-radius: 1px; animation: blink 1.1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.empty-hint {
  text-align: center; color: var(--muted); font-size: .66em; padding: 2em .5em; font-family: var(--ui-font); line-height: 1.6;
}

/* ---------- 底部面板 ---------- */
.tabs {
  display: flex; align-items: center; background: var(--bar); border-top: 1px solid var(--line); padding: 0 2px; flex: none;
}
.tab {
  flex: 1; height: 42px; border: 0; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-tools { display: flex; flex: none; }
#btnCollapse svg { transition: transform .2s; }
body.collapsed #btnCollapse svg { transform: rotate(180deg); }

.panels {
  background: var(--bar); padding: 8px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; flex: none;
}
body.collapsed .panels { display: none; }
.panel { display: none; }
.panel.active { display: flex; flex-direction: column; }
.panel.active > * + * { margin-top: 6px; }
.row { display: flex; align-items: center; overflow-x: auto; flex: none; -webkit-overflow-scrolling: touch; }
.row::-webkit-scrollbar { display: none; }
.row > * + * { margin-left: 6px; }
.digits { display: grid; grid-template-columns: repeat(8, 1fr); grid-gap: 6px; gap: 6px; overflow: visible; }
.digits > * + * { margin-left: 0; }
.digit {
  height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
  font-size: 22px; font-weight: 700; font-family: var(--score-font); color: var(--ink);
}
.digit.rest { color: var(--muted); }
.btn {
  height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font-size: 14px; white-space: nowrap; flex: none; display: inline-flex; align-items: center; justify-content: center; min-width: 40px;
}
.btn > * + * { margin-left: 4px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }
.btn.small { height: 34px; padding: 0 10px; font-size: 13px; }
.btn.accbtn { font-size: 18px; font-family: var(--score-font); min-width: 40px; padding: 0 8px; }
.btn:disabled { opacity: .35; transform: none; cursor: default; }
.btn.dur { min-width: 34px; padding: 0 4px; }
.dur .ic svg { height: 22px; width: auto; }
.group { display: flex; flex: none; }
.group > * + * { margin-left: 4px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; }
.seg button { height: 38px; padding: 0 12px; border: 0; background: var(--bg); color: var(--muted); font-size: 14px; font-weight: 600; white-space: nowrap; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.lbl { font-size: 13px; color: var(--muted); flex: none; }
.pos { font-size: 12px; color: var(--muted); flex: 1 1 auto; min-width: 3.5em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right; }
.spacer { flex: 1; min-width: 4px; }
.input {
  flex: 1; min-width: 120px; height: 42px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); padding: 0 12px; font-size: 16px; font-family: inherit;
}
.chk { display: inline-flex; align-items: center; font-size: 13px; color: var(--muted); flex: none; padding: 0 4px; white-space: nowrap; }
.chk input { width: 18px; height: 18px; margin: 0 6px 0 0; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; flex: none; }

/* ---------- 弹层 ---------- */
.overlay {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50; padding: 0;
}
@media (min-width: 600px) { .overlay { align-items: center; padding: 20px; } }
.modal {
  background: var(--bar); width: 100%; max-width: 560px; border-radius: 16px 16px 0 0;
  padding: 14px; padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); box-shadow: var(--shadow);
  max-height: 88vh; display: flex; flex-direction: column; animation: up .18s ease-out;
}
@media (min-width: 600px) { .modal { border-radius: 16px; } }
@keyframes up { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }
.mhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.mhead h3 { margin: 0; font-size: 16px; }
.mx { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--bg); color: var(--muted); font-size: 16px; }
.mbody { overflow: auto; display: flex; flex-direction: column; font-size: 14px; }
.mbody > * + * { margin-top: 10px; }
.mfoot { display: flex; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.mfoot .btn { min-width: 84px; margin: 4px 0 4px 8px; }
.field { display: flex; flex-direction: column; }
.field > * + * { margin-top: 4px; }
.field label { font-size: 12px; color: var(--muted); }
.field .input, .field select, .field textarea { width: 100%; }
.field textarea {
  min-height: 120px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  padding: 10px; font-size: 16px; font-family: inherit; resize: vertical; line-height: 1.6;
}
.field select {
  height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  padding: 0 8px; font-size: 16px; font-family: inherit;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; grid-gap: 10px; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-gap: 10px; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; }
.chips > * { margin: 3px; }
.chip { height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); font-size: 14px; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }
.sample {
  display: flex; align-items: center; justify-content: space-between; padding: 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); width: 100%; text-align: left;
}
.sample > * + * { margin-left: 8px; }
.sample b { display: block; font-size: 15px; }
.sample small { color: var(--muted); }
.pre {
  font-family: ui-monospace, Menlo, Consolas, "Noto Sans Mono CJK SC", monospace; white-space: pre-wrap; word-break: break-all;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 0; font-size: 13px; line-height: 1.55;
  max-height: 50vh; overflow: auto;
}
.help h4 { margin: 10px 0 4px; font-size: 14px; color: var(--accent); }
.help p, .help li { font-size: 13px; line-height: 1.65; color: var(--ink); margin: 0; }
.help ul { margin: 0; padding-left: 18px; }
.help kbd { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 12px; font-family: inherit; }

.toast {
  position: fixed; left: 50%; top: 112px; transform: translateX(-50%) translateY(-10px);
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: 90vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: .95; transform: translateX(-50%) translateY(0); }

/* ---------- 大屏微调 ---------- */
/* ---------- 电脑 / 平板横屏：谱面居中，播放条与工具面板停靠右侧 ---------- */
@media (min-width: 1000px) {
  body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    grid-template-rows: auto auto auto minmax(0, 1fr);
    grid-template-areas: "header header" "score transport" "score tabs" "score panels";
    height: 100vh;
  }
  .app-header { grid-area: header; }
  #scroller { grid-area: score; min-height: 0; padding: 16px 20px 28px; }
  .transport { grid-area: transport; border-left: 1px solid var(--line); padding: 10px 12px; }
  .tabs { grid-area: tabs; border-left: 1px solid var(--line); padding: 0 8px; }
  .panels { grid-area: panels; border-left: 1px solid var(--line); padding: 12px 12px 16px; overflow: auto; min-height: 0; }
  .digit { height: 56px; }
  .btn:hover, .digit:hover, .tbtn:hover, .tab:hover, .chip:hover { filter: brightness(.95); }
  .note:hover { background: var(--sel-bg); }
  body.collapsed .panels { display: none; }
}

/* ---------- 打印 / 存为 PDF ---------- */
@media print {
  body { background: #fff; display: block; }
  .app-header, .transport, .tabs, .panels, .toast, .overlay, .caret, .mnum, .empty-hint { display: none !important; }
  #scroller { overflow: visible; padding: 0; }
  #paper { box-shadow: none; max-width: none; padding: 0; min-height: 0; background: #fff; }
  #score { font-size: 16px !important; }
  .note.sel, .note.playing, .measure.cur { background: none !important; box-shadow: none !important; }
  .measure { margin-bottom: 1em; }
}

/* ---------- 虚拟钢琴 ---------- */
.piano { position: relative; height: 92px; overflow-x: auto; overflow-y: hidden; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 0 0; flex: none; }
.piano-inner { position: relative; height: 76px; min-width: 100%; }
.pw, .pb { position: absolute; top: 0; display: flex; align-items: flex-end; justify-content: center; font-family: var(--score-font); border: 1px solid #8a8a8a; user-select: none; -webkit-user-select: none; }
.pw { height: 76px; width: 28px; background: #fffdf9; color: #333; border-radius: 0 0 4px 4px; font-size: 11px; padding-bottom: 5px; box-sizing: border-box; }
.pb { height: 46px; width: 18px; background: #2b2b2b; color: #ddd; border-color: #111; border-radius: 0 0 3px 3px; font-size: 9px; padding-bottom: 3px; z-index: 2; box-sizing: border-box; }
.pw:active, .pb:active { background: var(--accent); color: #fff; }
.pw.on, .pb.on { background: var(--accent-soft); box-shadow: inset 0 -3px 0 var(--accent); }
.pw.on { color: var(--accent); font-weight: 700; }
[data-theme="dark"] .pw { background: #e8e6e1; }
#quickChordsRow { flex-wrap: nowrap; }
#quickChordsRow .lbl { flex: none; font-size: 12px; color: var(--muted); }
#quickChords { display: flex; overflow-x: auto; flex: 1; min-width: 0; }
#quickChords .chip { flex: none; height: 34px; padding: 0 11px; font-weight: 600; }
#quickChords .chip + .chip { margin-left: 6px; }
#quickChords::-webkit-scrollbar { display: none; }
.cp-root, .cp-list { display: flex; flex-wrap: wrap; }
.cp-root { margin-bottom: 10px; }
.cp-group { margin-bottom: 10px; }
.cp-gname { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.cp-list .chip { height: 32px; padding: 0 10px; }
.input-like { min-height: 38px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: 16px; line-height: 1.3; }
.muted { color: var(--muted); }
.quick .chip { flex: none; height: 34px; font-family: var(--ui-font); font-weight: 600; }
.quick .chip + .chip { margin-left: 6px; }
.quick .empty { font-size: 12px; color: var(--muted); white-space: nowrap; padding: 8px 0; }
.radios { display: flex; flex-direction: column; }
.radios label { display: flex; align-items: flex-start; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 14px; line-height: 1.5; }
.radios label + label { margin-top: 8px; }
.radios input { margin: 3px 8px 0 0; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.radios label.on { border-color: var(--accent); background: var(--accent-soft); }
.radios small { display: block; color: var(--muted); font-size: 12px; }
