:root {
  --bg: #eef0f4;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #667085;
  --line: #d9dde5;
  --accent: #2a55c9;
  --accent-ink: #ffffff;
  --rec: #d23b3b;
  --sel: #e0662b;
  --play: #d23b3b;
  --radius: 10px;
  font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
/* 上の帯の高さが折り返しで変わっても画面全体がはみ出さないよう、縦の flex で残りを楽譜側に渡す */
body { margin: 0; background: var(--bg); font-size: 14px; display: flex; flex-direction: column; height: 100vh; }
button, select, input { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: #f7f8fa; border-radius: 8px; padding: 6px 10px; cursor: pointer;
  min-height: 34px; touch-action: manipulation;
}
button:hover { background: #eceff4; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.08); }
button.rec { background: #fff; border-color: var(--rec); color: var(--rec); font-weight: 700; }
button.rec.on { background: var(--rec); color: #fff; }
input[type=text], input[type=number], input[type=search], select {
  border: 1px solid var(--line); border-radius: 7px; padding: 5px 7px; background: #fff; min-height: 32px;
}
input[type=number] { width: 70px; }
input[type=file] { max-width: 100%; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center;
  padding: 8px 16px; background: #1d2433; color: #fff;
}
.topbar button { background: #2d3548; border-color: #3d465b; color: #fff; }
.topbar button.primary { background: var(--accent); border-color: var(--accent); }
.topbar select, .topbar input { background: #2d3548; border-color: #3d465b; color: #fff; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: .02em; }
.brand .ver { font-weight: 400; font-size: 11px; color: #9aa6bd; margin-left: 4px; }
.update-banner { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 60; background: #fff3cd; color: #5c4400; border: 1px solid #f0c36d; border-radius: 8px; padding: 8px 12px; display: flex; gap: 10px; align-items: center; box-shadow: 0 4px 16px rgba(0,0,0,.15); max-width: calc(100% - 32px); }
.transport, .undo { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.undo { margin-left: auto; }
.field { display: inline-flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.topbar .field { flex-direction: row; align-items: center; gap: 6px; color: #c9d1e0; }
.field.wide { display: flex; width: 100%; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }

.layout { display: grid; grid-template-columns: 370px 1fr; flex: 1; min-height: 0; }
.side { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 8px 8px 0; position: sticky; top: 0; background: var(--panel); z-index: 2; border-bottom: 1px solid var(--line); }
.tab { border: none; background: none; border-radius: 8px 8px 0 0; padding: 8px 10px; color: var(--muted); }
.tab.active { background: var(--bg); color: var(--ink); font-weight: 700; }
.panel { display: none; padding: 10px; }
.panel.active { display: block; }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.card h3 { margin: 0; font-size: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.preview { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.meter { height: 8px; background: #edf0f5; border-radius: 4px; overflow: hidden; }
.meter div { height: 100%; width: 0; background: linear-gradient(90deg, #3cb371, #e0b000 70%, #d23b3b); transition: width .05s linear; }
.live { display: flex; justify-content: space-between; font-size: 20px; font-weight: 700; min-height: 28px; }
.live #liveTime { font-size: 14px; color: var(--muted); font-weight: 400; }
.roll { width: 100%; height: 110px; background: #10151f; border-radius: 6px; }
.selinfo { font-size: 13px; background: #f4f6fa; border-radius: 6px; padding: 6px 8px; min-height: 32px; }
.durs { display: flex; flex-wrap: wrap; gap: 4px; }
.durs button { font-family: "Noto Music", "Segoe UI Symbol", serif; font-size: 20px; min-width: 42px; line-height: 1; }
.durs button.active, .seg button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
#btnDot { font-family: inherit; font-size: 13px; }
.seg { display: flex; }
.seg.compact button { min-height: 30px; padding: 4px 9px; font-size: 13px; white-space: nowrap; }
.topbar .seg button.active { background: #e0a526; border-color: #e0a526; color: #1d2433; font-weight: 700; }
.seg button { border-radius: 0; flex: 1; }
.seg button:first-child { border-radius: 8px 0 0 8px; }
.seg button:last-child { border-radius: 0 8px 8px 0; }

.keyboard { position: relative; height: 110px; user-select: none; touch-action: none; }
.keyboard .wk, .keyboard .bk { position: absolute; top: 0; border: 1px solid #8c93a3; border-radius: 0 0 5px 5px; cursor: pointer; }
.keyboard .wk { background: #fff; height: 100%; z-index: 1; display: flex; align-items: flex-end; justify-content: center; font-size: 10px; color: #8a90a0; padding-bottom: 4px; }
.keyboard .bk { background: #252a35; height: 62%; z-index: 2; }
.keyboard .wk:active, .keyboard .wk.down { background: #cfdcff; }
.keyboard .bk:active, .keyboard .bk.down { background: #4a64b8; }

.liblist { display: flex; flex-direction: column; gap: 8px; }
.libitem { border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: grid; grid-template-columns: 64px 1fr; gap: 8px; }
.libitem img { width: 64px; height: 90px; object-fit: cover; object-position: top; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
.libitem .t { font-weight: 700; word-break: break-all; }
.libitem .m { color: var(--muted); font-size: 12px; }
.libitem .a { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.libitem .a button { padding: 3px 7px; min-height: 28px; font-size: 12px; }

.viewer { overflow: auto; padding: 18px 16px 60px; position: relative; }
.status { position: sticky; top: 0; z-index: 5; margin: 0 auto 12px; max-width: 794px; background: #fff8e1; border: 1px solid #f1d58a; border-radius: 8px; padding: 8px 12px; }
.status.error { background: #fdecec; border-color: #f2b4b4; }
.status progress { width: 100%; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.page { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.12), 0 6px 20px rgba(0,0,0,.06); width: 794px; max-width: 100%; }
.page svg { display: block; width: 100%; height: auto; }
.page .ev { cursor: pointer; }
.page .ev.sel :not(.hit):not(.bg) { fill: var(--sel); stroke: var(--sel); }
.page .ev.sel .hit { fill: rgba(224, 102, 43, .10); }
.page .ev.playing :not(.hit):not(.bg) { fill: var(--play); stroke: var(--play); }
.page .chord { cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.25); }

.btnlike { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #f7f8fa; border-radius: 8px; padding: 8px 12px; cursor: pointer; min-height: 40px; font-size: 14px; }
.btnlike.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.zoombar { position: sticky; top: 0; z-index: 4; display: flex; gap: 6px; align-items: center; justify-content: center; margin: 0 auto 10px; width: max-content; max-width: 100%; background: rgba(238,240,244,.92); padding: 4px 8px; border-radius: 999px; }
.zoombar button { min-height: 32px; min-width: 36px; padding: 2px 10px; }
.zoombar span { font-size: 12px; color: var(--muted); min-width: 64px; text-align: center; }
.pages.zoomed { align-items: flex-start; }
.pages.zoomed .page { width: calc(794px * var(--zoom, 1)); max-width: none; flex: none; }
.mobilenav { display: none; }

@media (max-width: 900px) {
  body { height: auto; display: block; padding-bottom: 64px; }
  .topbar { position: static; padding: 8px 10px; gap: 8px 10px; }
  .brand { font-size: 15px; }
  .transport { gap: 6px; }
  .topbar .field { font-size: 12px; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .side { border-right: none; border-bottom: 1px solid var(--line); max-height: none; }
  /* min-width:0 が無いと、1列の grid の中で楽譜の元の幅（794px）まで広がり、携帯の画面が縮小表示になった */
  .viewer { padding: 12px 8px 40px; overflow: visible; min-width: 0; }
  .side { min-width: 0; }
  .undo { margin-left: 0; }
  .pages.zoomed { overflow-x: auto; display: flex; }
  .mobilenav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: #1d2433; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); gap: 8px; }
  .mobilenav button { flex: 1; min-height: 44px; background: #2d3548; border-color: #3d465b; color: #fff; font-size: 15px; }
  .toast { bottom: 76px; }
  .update-banner { top: 8px; }
}
@media print {
  .zoombar, .mobilenav { display: none !important; }
  body { padding-bottom: 0; }
  .pages.zoomed .page { width: 210mm; }
}

/* 印刷：楽譜のページだけを A4 に1枚ずつ */
@page { size: A4; margin: 0; }
@media print {
  body { background: #fff; display: block; height: auto; }
  .topbar, .side, .status, .toast { display: none !important; }
  .layout { display: block; height: auto; }
  .viewer { overflow: visible; padding: 0; }
  .pages { gap: 0; display: block; }
  .page { box-shadow: none; width: 210mm; height: 297mm; page-break-after: always; break-after: page; overflow: hidden; }
  .page:last-child { page-break-after: auto; break-after: auto; }
  .page svg { width: 210mm; height: 297mm; }
  .page .ev.sel :not(.hit):not(.bg), .page .ev.playing :not(.hit):not(.bg) { fill: #000; stroke: #000; }
  .page .ev .hit { fill: transparent !important; }
}
