/* ============================================================
   琴谱练习台 —— 温暖纸感的 iPad 优先界面
   ============================================================ */

:root {
  --paper: #f6f3ee;
  --paper-2: #efeae2;
  --card: #fffdfa;
  --ink: #23272a;
  --ink-2: #5b625f;
  --ink-3: #8d938f;
  --line: #e4ded4;
  --line-strong: #d3cbbf;
  --accent: #16624f;
  --accent-ink: #0e4a3c;
  --accent-soft: #e3efe9;
  --gold: #c08a2e;
  --danger: #b4453a;
  --danger-soft: #fbecea;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(35, 39, 42, .05), 0 8px 24px rgba(35, 39, 42, .05);
  --shadow-lg: 0 24px 70px rgba(28, 30, 32, .22);
  --topbar: 60px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 90% -10%, #fffdf8 0%, transparent 60%),
    linear-gradient(180deg, #f8f5f0 0%, var(--paper) 40%, #f2eee7 100%);
}
body.library-open { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { cursor: default; opacity: .42; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
img { max-width: 100%; }

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

.topbar {
  position: relative; z-index: 30; flex: none;
  height: var(--topbar);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  background: rgba(250, 248, 244, .82);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand-mark {
  width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: 11px; color: #fff;
  background: linear-gradient(160deg, #1d7a62, #0f5142);
  box-shadow: 0 3px 10px rgba(15, 81, 66, .28);
}
.brand-mark svg { width: 19px; height: 19px; stroke-width: 2.2; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.pill-button {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line-strong);
  color: var(--ink); font-size: 14px; font-weight: 600;
  transition: background .15s, border-color .15s, transform .1s;
}
label.pill-button, label.big-button { cursor: pointer; position: relative; }
/* iOS Safari will not open the picker for a display:none file input, so the
   label's input is hidden by size/opacity instead. */
label.big-button > input[type="file"], label.pill-button > input[type="file"] {
  position: absolute; left: 0; top: 0; width: 1px; height: 1px;
  opacity: 0; overflow: hidden; pointer-events: none;
}
.pill-button:hover { background: #fff; border-color: #c3b9aa; }
.pill-button:active { transform: scale(.97); }
.pill-button.solid { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill-button.solid:hover { background: var(--accent-ink); }
.pill-button svg { width: 17px; height: 17px; }
.pill-button > .pill-count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent-ink);
}

/* ---------- 主工作区：左谱面满屏，右侧控制栏 ---------- */

html, body { height: 100%; }
body { display: flex; flex-direction: column; overflow: hidden; }

.shell {
  flex: 1;
  display: flex;
  min-height: 0;
  padding-bottom: env(safe-area-inset-bottom);
}

.sheet-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: var(--paper-2);
}

.practice-panel {
  flex: none;
  width: 372px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--card);
  border-left: 1px solid var(--line);
}

.panel-head { display: flex; align-items: flex-start; gap: 10px; padding: 16px 18px 10px; }
.panel-heading { flex: 1; min-width: 0; }
.panel-heading h1 { font-size: 19px; font-weight: 700; letter-spacing: -.25px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-heading p { margin-top: 4px; font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.panel-statusline {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 0 18px 12px; border-bottom: 1px solid var(--line);
}

.pager {
  display: flex; align-items: center; gap: 2px; height: 34px; padding: 0 4px;
  border-radius: 999px; background: var(--paper-2); border: 1px solid var(--line);
}
.pager span { min-width: 54px; text-align: center; font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.pager .icon-button { width: 28px; min-height: 28px; background: none; border: 0; }
.pager .icon-button:not(:disabled):hover { background: #00000008; }

.toolbar-tools { display: flex; gap: 6px; }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--paper-2); border: 1px solid var(--line); border-radius: 999px;
}
.segmented button {
  min-height: 34px; padding: 0 16px; border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--ink-2); white-space: nowrap;
  transition: background .15s, color .15s, box-shadow .15s;
}
.segmented button.active { background: var(--card); color: var(--accent-ink); box-shadow: 0 1px 3px rgba(35, 39, 42, .12); }
.segmented.small button { min-height: 30px; padding: 0 13px; font-size: 12px; }
.segmented.wide { display: flex; width: 100%; }
.segmented.wide button { flex: 1; min-height: 38px; padding: 0 8px; text-align: center; }
#part-tabs { display: flex; }

.icon-button {
  display: inline-grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--line); color: var(--ink-2);
  transition: background .15s, border-color .15s, color .15s;
}
.icon-button:hover { background: #fff; border-color: var(--line-strong); color: var(--ink); }
.icon-button svg { width: 17px; height: 17px; }
.icon-button.large { width: 40px; height: 40px; border-radius: 12px; }
.icon-button.small { width: 30px; height: 30px; border-radius: 8px; }
.icon-button.small svg { width: 15px; height: 15px; }
.icon-button.danger { color: var(--danger); }
.icon-button.danger:hover { background: var(--danger-soft); border-color: #edc9c4; }

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

.score-view {
  position: relative; flex: 1; min-height: 0;
  background: #e9e5dd;
  /* `safe` keeps the left edge reachable when the sheet is wider than the
     panel; plain centring would clip it beyond the scroll origin. The plain
     value stays first as a fallback for browsers that reject the keyword. */
  overflow: auto; display: flex; align-items: flex-start;
  justify-content: center; justify-content: safe center;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.score-view.empty { align-items: center; justify-content: center; }
/* The photo shrinks to its own width so the crop box can be measured against
   the image itself, not the flex container. */
#score-sheet {
  position: relative; flex: 0 0 auto;
  width: fit-content; max-width: calc(100% - 24px);
  margin: 12px; background: #fff;
  box-shadow: 0 1px 3px rgba(35, 39, 42, .08), 0 12px 32px rgba(35, 39, 42, .08);
}
#score-sheet > img { display: block; width: auto; max-width: 100%; height: auto; }
.score-view > #recognized-sheet { flex: 0 0 auto; margin: 12px; max-width: calc(100% - 24px); }
#score-sheet[hidden] { display: none !important; }
#score-sheet.cropping { cursor: crosshair; touch-action: none; }
#crop-box { position: absolute; border: 2px solid var(--accent); background: rgba(22, 98, 79, .22); pointer-events: none; }
#crop-box[hidden] { display: none !important; }

.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 40px 24px; max-width: 480px; }
.empty-illustration {
  width: 78px; height: 78px; border-radius: 24px; display: grid; place-items: center; margin-bottom: 12px;
  background: linear-gradient(160deg, #eef4f0, #e2ebe5); color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(22, 98, 79, .08);
}
.empty-illustration svg { width: 34px; height: 34px; stroke-width: 1.6; }
.empty-state strong { font-size: 19px; font-weight: 700; }
.empty-state p { font-size: 13.5px; line-height: 1.6; color: var(--ink-3); }
.empty-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }

.big-button {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line-strong);
  font-size: 14px; font-weight: 650; color: var(--ink);
}
.big-button:hover { border-color: #c3b9aa; }
.big-button.solid { background: var(--accent); border-color: var(--accent); color: #fff; }
.big-button.subtle { background: transparent; border-color: transparent; color: var(--ink-2); }
.big-button.subtle:hover { background: #00000008; }
.big-button svg { width: 18px; height: 18px; }

/* Status line sits at the foot of the right-hand panel: the sheet keeps the
   full left side, and progress text still never covers the music. */
.status {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 11px 18px;
  border-top: 1px solid var(--line); background: var(--paper);
  min-height: 40px; font-size: 12.5px; color: var(--ink-3);
}
#status-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #b9b3a9; flex: none; }
.status.running .status-dot { background: var(--gold); animation: pulse 1.2s ease-in-out infinite; }
.status.done .status-dot { background: var(--accent); }
.status.error .status-dot { background: var(--danger); }
.status.running { color: var(--gold); }
.status.error { color: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- 练习面板 ---------- */

.practice-scroll {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  padding: 14px 18px 16px;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.practice-block { padding: 14px 0; border-bottom: 1px solid var(--line); }
.practice-block:first-child { padding-top: 2px; }
.practice-block:last-of-type { border-bottom: 0; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.block-head h2 { font-size: 14px; font-weight: 700; letter-spacing: .1px; }
.range-chip {
  font-size: 12px; font-weight: 700; color: var(--accent-ink);
  background: var(--accent-soft); padding: 4px 10px; border-radius: 999px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.hint { font-size: 12px; line-height: 1.55; color: var(--ink-3); }
.hint.inline { margin: 0; }
.practice-block > .segmented + .segmented,
.practice-block > .segmented + .toolbar-tools,
.practice-block > .toolbar-tools + .hint { margin-top: 10px; }
/* The score toolbar is intentionally quiet; undo remains available through
   the edit transaction, while the old gesture explanation took useful space. */
#undo-score, .score-selection-hint { display: none !important; }

.slider:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.slider {
  -webkit-appearance: none; appearance: none; width: 100%; height: 28px; margin: 0 0 8px;
  background: transparent; accent-color: var(--accent);
}
.slider::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: var(--paper-2); border: 1px solid var(--line); }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; margin-top: -11px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent); box-shadow: 0 2px 6px rgba(35, 39, 42, .18);
}
.slider::-moz-range-track { height: 6px; border-radius: 999px; background: var(--paper-2); }
.slider::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2px solid var(--accent); }

#play-source { margin-bottom: 10px; }
#play-source button { border-radius: 999px; }

.command-row { display: flex; gap: 8px; }
.primary-button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 650;
  box-shadow: 0 4px 14px rgba(22, 98, 79, .22);
  transition: background .15s, transform .1s;
}
.primary-button:not(:disabled):hover { background: var(--accent-ink); }
.primary-button:not(:disabled):active { transform: scale(.985); }
.primary-button svg { width: 18px; height: 18px; fill: currentColor; stroke-width: 1.5; }
.command-row .icon-button.large { width: 48px; height: 48px; }

.keyboard-legend { display: flex; justify-content: flex-end; gap: 12px; margin: 14px 0 6px; font-size: 11px; color: var(--ink-3); }
.keyboard-legend span { display: flex; align-items: center; gap: 5px; }
.keyboard-legend i { width: 9px; height: 9px; border-radius: 3px; }
.legend-right { background: var(--accent); }
.legend-left { background: #cf8a3c; }
.legend-unknown { background: #7d858c; }

.keyboard-scroll {
  overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch;
  border-radius: 10px; padding-bottom: 6px; overscroll-behavior-x: contain;
}
.piano-keyboard { --key-w: 24px; position: relative; margin: 0; flex: none; height: 72px; }
.piano-key.white { width: var(--key-w); }
.piano-key.black { width: calc(var(--key-w) * 0.66); }
.piano-key { position: absolute; top: 0; transition: background .08s; }
.piano-key.white {
  height: 72px; border: 1px solid #cfd5d0; border-radius: 0 0 6px 6px;
  background: linear-gradient(180deg, #fff, #f2f2ef); color: #9aa19b; font-size: 10px;
  text-align: center; padding-top: 53px; font-variant-numeric: tabular-nums;
}
.piano-key.black {
  z-index: 1; height: 46px; border-radius: 0 0 5px 5px;
  background: linear-gradient(180deg, #3a4145, #1e2427); border: 1px solid #10161a;
  box-shadow: 0 1px 3px rgba(20, 24, 26, .35);
}
.piano-keyboard.compact .piano-key.white { padding-top: 0; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px; font-size: 9px; }
.piano-key.right { background: var(--accent); border-color: var(--accent-ink); color: #fff; }
.piano-key.left { background: #cf8a3c; border-color: #a96a22; color: #fff; }
.piano-key.unknown { background: #7d858c; border-color: #636b72; color: #fff; }
.piano-key.right.left { background: linear-gradient(90deg, var(--accent) 50%, #cf8a3c 50%); }

.record-button {
  width: 100%; display: flex; align-items: center; gap: 10px;
  min-height: 48px; padding: 0 16px; border-radius: var(--radius-sm);
  background: var(--card); border: 1px solid #e5cdc8; color: var(--danger);
  font-size: 14px; font-weight: 650;
}
.record-button:hover { background: var(--danger-soft); }
.record-button svg { width: 18px; height: 18px; }
.record-button.recording { background: var(--danger); border-color: var(--danger); color: #fff; animation: rec 1.6s ease-in-out infinite; }
@keyframes rec { 50% { box-shadow: 0 0 0 6px rgba(180, 69, 58, .14); } }
.record-time { margin-left: auto; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.recording-playback { margin-top: 10px; }
.recording-playback audio { width: 100%; height: 40px; }
.secondary-button {
  width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; margin-top: 8px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--accent-ink); font-size: 14px; font-weight: 650;
}
.secondary-button:hover { background: #d7e8e0; }
.secondary-button svg { width: 17px; height: 17px; }
.practice-block > .hint { margin-top: 10px; }

/* ---------- 分析结果 ---------- */

.analysis { margin-top: 14px; }
.analysis-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.analysis-head strong { font-size: 13.5px; }
.analysis-head span { font-size: 11.5px; color: var(--ink-3); }
.score-summary { display: flex; align-items: center; gap: 16px; padding: 12px; background: var(--paper); border-radius: var(--radius-sm); border: 1px solid var(--line); }
.score-total {
  width: 62px; height: 62px; flex: none; border-radius: 50%;
  display: grid; place-content: center; text-align: center;
  background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(22, 98, 79, .25);
}
.score-total b { font-size: 23px; line-height: 1; }
.score-total span { font-size: 10px; margin-top: 3px; opacity: .85; }
.score-metrics { flex: 1; display: grid; gap: 8px; min-width: 0; }
.score-metrics > div { display: grid; grid-template-columns: 32px 26px 1fr; align-items: center; gap: 8px; font-size: 11.5px; color: var(--ink-2); }
.score-metrics strong { text-align: right; }
.score-metrics i, .measure-result i { height: 6px; background: var(--paper-2); border-radius: 999px; overflow: hidden; display: block; }
.score-metrics em, .measure-result em { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.score-metrics > div:last-child em { background: var(--gold); }
.measure-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; margin-top: 12px; }
.measure-result { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 5px; text-align: left; }
.measure-result span { display: block; font-size: 10px; color: var(--ink-3); margin-bottom: 4px; }
.measure-result.has-error { border-color: #efcfc4; background: #fff8f5; }
.measure-result.has-error em { background: #d26a3f; }
.measure-result:hover { border-color: var(--accent); }

/* ---------- 识谱数据 ---------- */

.score-data { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.score-data summary { font-size: 13px; font-weight: 650; color: var(--ink-2); cursor: pointer; list-style: none; }
.score-data summary::-webkit-details-marker { display: none; }
.score-data summary::before { content: "▸"; display: inline-block; margin-right: 7px; color: var(--ink-3); transition: transform .15s; }
.score-data[open] summary::before { transform: rotate(90deg); }
.transcription { max-height: 320px; overflow: auto; margin-top: 10px; }
.measure { padding: 9px 0; border-bottom: 1px solid var(--line); }
.measure-title { font-size: 12px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }
.measure-notes { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.measure-notes span { font-size: 11.5px; color: var(--ink-3); }
.measure-notes .note-chip {
  display: inline-flex; align-items: center; min-height: 26px; padding: 0 8px;
  border-radius: 7px; background: var(--paper-2); border: 1px solid var(--line);
  color: var(--ink-2); font-size: 11.5px;
}
.measure-notes .note-chip:hover { background: var(--accent-soft); border-color: #bcd8cc; color: var(--accent-ink); }
.muted { font-size: 12px; color: var(--ink-3); font-weight: 400; }
.loading-text { font-size: 12px; color: var(--gold); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px); z-index: 200;
  padding: 11px 18px; border-radius: 999px;
  background: rgba(35, 39, 42, .92); color: #fff; font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  backdrop-filter: blur(10px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 乐谱库（全屏相册） ---------- */

.library {
  position: fixed; inset: 0; z-index: 90;
  background: var(--paper);
  display: flex; flex-direction: column;
  animation: library-in .22s ease-out;
  padding-top: env(safe-area-inset-top);
}
@keyframes library-in { from { opacity: 0; transform: translateY(10px); } }
.library-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px max(20px, env(safe-area-inset-left)) 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(250, 248, 244, .9);
  backdrop-filter: blur(14px);
}
.library-heading { min-width: 0; flex: 1; }
.library-heading h2 { font-size: 19px; font-weight: 700; letter-spacing: -.2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library-heading p { margin-top: 3px; font-size: 12px; color: var(--ink-3); }
.library-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.library-actions .pill-button { min-height: 38px; padding: 0 14px; font-size: 13px; }
#library-edit[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.library-body {
  flex: 1; overflow: auto; -webkit-overflow-scrolling: touch;
  padding: 22px max(22px, env(safe-area-inset-left)) calc(32px + env(safe-area-inset-bottom));
}
.practice-calendar { margin: 0 22px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); }
.practice-calendar-head { display:flex; align-items:center; gap:12px; margin-bottom:10px; }
.practice-calendar-head strong { font-size:14px; }
.practice-calendar-head span { color:var(--ink-3); font-size:12px; }
.practice-calendar-head button { margin-left:auto; border:1px solid var(--accent); border-radius:999px; background:var(--accent); color:#fff; min-height:32px; padding:0 12px; font-size:12px; }
.practice-calendar-grid { display:grid; grid-template-columns:repeat(7, 1fr); gap:6px; }
.practice-day { width:28px; height:28px; display:grid; place-items:center; justify-self:center; border-radius:50%; color:var(--ink-2); font-size:12px; }
.practice-day.marked { background:var(--accent); color:#fff; font-weight:700; box-shadow:0 0 0 3px var(--accent-soft); }
.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 22px 18px; }
.album { display: flex; flex-direction: column; gap: 10px; text-align: left; padding: 0; background: none; }
.album-cover {
  position: relative; aspect-ratio: 3 / 4; border-radius: 6px 12px 12px 6px; overflow: hidden;
  background: #fff; border: 1px solid var(--line-strong);
  box-shadow: 0 1px 2px rgba(35, 39, 42, .06), 0 10px 22px rgba(35, 39, 42, .1);
  transition: transform .18s ease, box-shadow .18s ease;
}
.album:hover .album-cover { transform: translateY(-3px); box-shadow: 0 2px 4px rgba(35, 39, 42, .06), 0 18px 32px rgba(35, 39, 42, .16); }
.album-cover .thumb { width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block; }
.album-cover .thumb[src*="kind=page"] { object-fit: contain; background: #fff; padding: 12px 10px; }
.album-spine { position: absolute; inset: 0 auto 0 0; width: 10px; background: linear-gradient(90deg, rgba(35,39,42,.16), rgba(35,39,42,0)); }
.album-badge {
  position: absolute; left: 14px; bottom: 10px; padding: 4px 9px; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; color: #fff; background: rgba(35, 39, 42, .74);
  backdrop-filter: blur(6px);
}
.album-badge.pending { background: rgba(192, 138, 46, .92); }
.album-badge.warn { background: rgba(180, 69, 58, .92); }
.album-meta strong { display: block; font-size: 14px; font-weight: 650; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album-meta small { display: block; margin-top: 3px; font-size: 12px; color: var(--ink-3); }

.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 20px 16px; }
.page-card { display: flex; flex-direction: column; gap: 8px; }
.page-cover {
  position: relative; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden;
  background: #fff; border: 1px solid var(--line-strong);
  box-shadow: 0 1px 2px rgba(35, 39, 42, .06), 0 8px 18px rgba(35, 39, 42, .09);
  cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.page-card.done .page-cover:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(35, 39, 42, .06), 0 14px 26px rgba(35, 39, 42, .15); }
.page-cover .thumb { width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block; }
.page-cover .thumb[src*="kind=page"] { object-fit: contain; object-position: center; background: #fff; padding: 10px 8px; }
.page-card.queued .page-cover, .page-card.running .page-cover { cursor: default; }
.page-card.error .page-cover { cursor: default; border-color: #ecc7c0; }
.thumb.placeholder { display: grid; place-items: center; width: 100%; height: 100%; color: var(--gold); background: var(--paper); }
.thumb.placeholder svg { width: 26px; height: 26px; stroke-width: 1.7; }
.page-card.queued .thumb.placeholder svg, .page-card.running .thumb.placeholder svg { animation: spin 1.6s linear infinite; }
.page-card.error .thumb.placeholder { color: var(--danger); background: var(--danger-soft); }
@keyframes spin { to { transform: rotate(360deg); } }
.page-num {
  position: absolute; left: 8px; top: 8px; min-width: 24px; height: 24px; padding: 0 7px;
  display: grid; place-items: center; border-radius: 999px;
  background: rgba(35, 39, 42, .68); color: #fff; font-size: 11.5px; font-weight: 700;
  backdrop-filter: blur(6px);
}
.page-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.page-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.page-meta strong { display: block; font-size: 13px; font-weight: 650; }
.page-meta small { display: block; margin-top: 2px; font-size: 11px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.page-meta small.error { color: var(--danger); }
.page-meta small.running, .page-meta small.queued { color: var(--gold); }
.drag-handle { position: absolute; right: 8px; top: 8px; width: 28px; height: 28px; border-radius: 8px; background: rgba(255,255,255,.88); display: grid; place-items: center; color: var(--ink-2); box-shadow: 0 1px 4px rgba(35,39,42,.2); }
.drag-handle svg { width: 16px; height: 16px; }
.page-grid.reordering .page-cover { cursor: grab; }
.page-grid.reordering .page-card.done .page-cover:hover { transform: none; box-shadow: 0 1px 2px rgba(35, 39, 42, .06), 0 8px 18px rgba(35, 39, 42, .09); }
/* The dragged card must not intercept elementFromPoint, or the drop target
   under the finger can never be found. */
.page-card.dragging { opacity: .45; pointer-events: none; }
.page-card.dragging .page-cover { transform: scale(.97); box-shadow: 0 12px 30px rgba(35, 39, 42, .22); }

.library-empty { min-height: 60vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; padding: 40px 24px; }
.library-empty strong { font-size: 18px; font-weight: 700; }
.library-empty p { font-size: 13px; color: var(--ink-3); max-width: 340px; line-height: 1.6; }
.library-empty .big-button { margin-top: 16px; }

/* ---------- iPad 竖屏：谱面在上，控制面板收成底部抽屉 ---------- */

@media (max-width: 1080px) and (orientation: portrait) {
  .shell { flex-direction: column; }
  .sheet-panel { flex: 1 1 auto; }
  .practice-panel {
    width: auto; max-height: 46dvh;
    border-left: 0; border-top: 1px solid var(--line);
    box-shadow: 0 -6px 20px rgba(35, 39, 42, .07);
  }
  .panel-head { padding: 12px 16px 8px; }
  .panel-heading h1 { font-size: 17px; }
  .panel-statusline { padding: 0 16px 10px; }
  .practice-scroll { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; padding: 12px 16px 18px; }
  .practice-block { padding: 12px 0; }
  .practice-block:nth-child(1) { grid-column: 1 / -1; }
  .score-data { grid-column: 1 / -1; }
  .status { padding: 9px 16px 10px; }
  .piano-key.white { height: 64px; padding-top: 46px; }
  .piano-key.black { height: 40px; }
  .piano-keyboard { height: 64px; }
}

/* ---------- 小屏 / 手机 ---------- */

@media (max-width: 720px) {
  :root { --topbar: 54px; }
  /* Too narrow for a side-by-side layout: stack the panel under the sheet. */
  .shell { flex-direction: column; }
  .practice-panel {
    width: auto; max-height: 52dvh;
    border-left: 0; border-top: 1px solid var(--line);
    box-shadow: 0 -6px 20px rgba(35, 39, 42, .07);
  }
  .topbar { padding: 0 14px; }
  .brand-name { font-size: 15px; }
  .pill-button > span:not(.pill-count) { display: none; }
  .pill-button > .pill-count { display: grid; }
  .pill-button { padding: 0 13px; min-height: 38px; }
  .topbar-actions { gap: 8px; }
  .panel-head { padding: 10px 14px 6px; }
  .panel-heading h1 { font-size: 16px; }
  .panel-heading p { font-size: 11.5px; }
  .panel-statusline { padding: 0 14px 8px; }
  .practice-scroll { display: block; padding: 10px 14px 14px; }
  .practice-block { padding: 12px 0; }
  .empty-actions .big-button { min-height: 44px; padding: 0 16px; font-size: 13px; }
  .empty-state { padding: 28px 18px; }
  .album-grid { grid-template-columns: repeat(2, 1fr); gap: 16px 12px; }
  .page-grid { grid-template-columns: repeat(2, 1fr); gap: 14px 12px; }
  .library-bar { padding: 12px 14px 10px; gap: 8px; }
  .library-heading h2 { font-size: 16px; }
  .library-actions .pill-button span { display: inline; }
  .library-actions { gap: 6px; }
  .library-body { padding: 16px 14px calc(28px + env(safe-area-inset-bottom)); }
}

/* 窄屏：乐谱库顶栏只留图标，避免挤压标题 */
@media (max-width: 520px) {
  .library-bar { padding: 10px 12px 8px; }
  .library-actions .pill-button { padding: 0 11px; min-height: 36px; }
  .library-actions .pill-button span { display: none; }
  .library-actions .icon-button { width: 36px; height: 36px; }
}

#homework-dialog { width: min(660px, calc(100vw - 32px)); max-height: calc(100dvh - 40px); padding: 0; border: 1px solid var(--line); border-radius: 22px; background: var(--paper); color: var(--ink); box-shadow: 0 24px 80px #0003; }
#homework-dialog::backdrop { background: #202a3855; backdrop-filter: blur(5px); }
.homework-header { display: flex; align-items: center; justify-content: space-between; padding: 22px 24px 12px; }
.homework-header h2 { margin: 0; font-size: 23px; }
.homework-header p { margin: 6px 0 0; font-size: 13px; color: var(--ink-3); }
.homework-week { display: flex; gap: 8px; padding: 0 24px 16px; border-bottom: 1px solid var(--line); }
.homework-week button, #homework-active button { border: 1px solid var(--line); border-radius: 10px; background: transparent; color: inherit; padding: 9px 14px; min-height: 40px; cursor: pointer; }
.homework-content { padding: 18px 24px 24px; }
.homework-item { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.homework-item input { width: 23px; height: 23px; flex: none; accent-color: var(--accent); cursor: pointer; }
.homework-open { flex: 1; min-width: 0; text-align: left; background: transparent; border: 0; padding: 5px 0; color: inherit; cursor: pointer; }
.homework-open strong, .homework-open span { display: block; overflow-wrap: anywhere; }
.homework-open span { font-size: 13px; color: var(--ink-3); margin-top: 6px; }
.homework-item.completed .homework-open strong { color: var(--ink-3); }
#homework-form { display: grid; gap: 14px; padding-top: 24px; }
#homework-form h3 { margin: 0; font-size: 16px; }
#homework-form label { display: grid; gap: 7px; font-size: 13px; min-width: 0; }
#homework-form select { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--paper); color: inherit; font: inherit; }
.homework-range { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
#homework-error { color: #b64035; margin: 0; font-size: 13px; }
#homework-active { margin: 8px 16px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #e5eee7; font-size: 13px; }
#homework-active > div { display: flex; gap: 8px; margin-top: 8px; }
#homework-add-selection { min-height: 32px; padding: 4px 10px; font-size: 12px; }
@media(max-width: 600px) { .topbar { gap: 8px; } .topbar-actions { gap: 5px; } #homework-button { padding: 0 10px; } #homework-button svg { display: none; } .homework-header, .homework-content { padding-left: 16px; padding-right: 16px; } }
.settings-dialog { width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 40px); padding: 24px; border: 1px solid var(--line); border-radius: 20px; background: var(--paper); color: var(--ink); box-shadow: var(--shadow-lg); }
.settings-dialog::backdrop { background: #202a3855; backdrop-filter: blur(5px); }
.settings-dialog h2 { font-size: 21px; margin-bottom: 12px; }
.settings-dialog p { font-size: 14px; color: var(--ink-2); line-height: 1.7; margin: 12px 0; }
.settings-dialog select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: var(--card); margin-top: 8px; }
#line-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 16px 0; }
#line-list label { display: flex; align-items: center; gap: 10px; min-height: 44px; }
#line-list input { width: 22px; height: 22px; accent-color: var(--accent); }
.settings-dialog .dialog-actions button { padding: 10px 20px; min-height: 44px; border-radius: 10px; background: var(--accent-soft); }
#line-error, #merge-error { color: var(--danger); }

#merge-pages { display: grid; gap: 10px; margin: 16px 0; }
#merge-pages label { display:flex; gap:12px; align-items:center; min-height:44px; }
#merge-pages input { width:22px; height:22px; accent-color:var(--accent); }
