:root {
  --ink: #211d18;
  --paper: #fbf9f3;
  --workspace: #e6e1d8;
  --panel: #f6f2ea;
  --panel-2: #ede7dc;
  --line: #d9d1c2;
  --line-strong: #c4b9a6;
  --muted: #776d5f;
  --muted-2: #988c7a;
  --accent: #8e3a32;
  --accent-dark: #6d2a24;
  --accent-soft: #f2e4df;
  --gold: #b18b4d;
  --topbar: #29241f;
  --topbar-2: #342d26;
  --radius: 8px;
  --shadow: 0 12px 34px rgba(48, 38, 26, .14), 0 2px 6px rgba(48, 38, 26, .08);
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--workspace);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-size: 13px;
}
button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; }
svg { -webkit-user-select: none; user-select: none; }

.app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- верхняя панель ---------- */
.topbar {
  flex: 0 0 58px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: var(--topbar);
  color: #efe6d6;
  border-bottom: 1px solid #1b1713;
  z-index: 20;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 9px; flex: 0 0 auto; }
.mark {
  width: 31px; height: 31px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: linear-gradient(150deg, #f6ecd8, #e6d4b4);
  color: #5a2b24;
  font-family: var(--font-serif);
  font-size: 21px;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(90, 43, 36, .22), 0 1px 2px rgba(0,0,0,.25);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { display: flex; align-items: baseline; gap: 8px; font-family: var(--font-serif); font-size: 18px; letter-spacing: .02em; }
.brand-by { position: relative; padding-left: 9px; font-family: var(--font-serif); font-size: 10.5px; font-style: italic; font-weight: 400; letter-spacing: .01em; color: #c3b096; white-space: nowrap; text-decoration: none; }
.brand-by:hover { color: #f3ead8; text-decoration: underline; text-underline-offset: 2px; }
.brand-by::before { content: ""; position: absolute; left: 0; top: 50%; width: 1px; height: 11px; background: rgba(255,255,255,.17); transform: translateY(-50%); }
.brand-sub { font-size: 9px; letter-spacing: .09em; text-transform: uppercase; color: #b7a68f; margin-top: 2px; }

.project-chip {
  display: flex; align-items: center; gap: 8px;
  min-width: 0; max-width: 300px;
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 8px;
  background: rgba(255, 255, 255, .035);
}
.project-label { font-size: 8px; letter-spacing: .12em; text-transform: uppercase; color: #a3937d; }
.project-name {
  border: none; background: transparent; color: #f3ebdc;
  font-size: 13px; padding: 0; max-width: 170px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-bottom: 1px dashed transparent;
}
.project-name:hover { border-bottom-color: rgba(243, 235, 220, .35); }
.save-state { font-size: 9.5px; color: #8fa085; white-space: nowrap; }
.save-state.dirty { color: #c7a26c; }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 7px; min-width: 0; }
.btn-group { display: flex; align-items: center; gap: 3px; }
.btn-group + .btn-group { margin-left: 2px; padding-left: 8px; border-left: 1px solid rgba(255,255,255,.1); }
.icon-btn {
  width: 31px; height: 31px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: #d8ccb8;
  padding: 0;
  flex: 0 0 auto;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .fill { fill: currentColor; stroke: none; }
.icon-btn:hover { background: rgba(255,255,255,.08); color: #fff7e8; }
.icon-btn:active { background: rgba(255,255,255,.13); }
.icon-btn[disabled] { opacity: .3; cursor: default; }
.icon-btn[disabled]:hover { background: transparent; }
.icon-btn.help-btn { font-family: var(--font-serif); font-size: 16px; border-color: rgba(255,255,255,.14); border-radius: 50%; width: 28px; height: 28px; }
.btn {
  height: 31px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 9px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 7px;
  background: transparent;
  color: #e9dfcf;
  font-size: 12px;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.btn:hover { background: rgba(255,255,255,.07); }
.btn-play { background: var(--accent); border-color: transparent; color: #fff6e8; padding: 0 13px; box-shadow: 0 1px 0 rgba(255,255,255,.14) inset; }
.btn-play:hover { background: #a1453b; }
.btn-play svg { width: 14px; height: 14px; fill: currentColor; stroke: none; }
.btn-play.playing { background: #3f5a4a; }
.btn-play.playing svg { fill: none; stroke: currentColor; stroke-width: 2.2; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 38px;
  width: 246px;
  background: #fbf8f1;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 44px rgba(30, 22, 14, .28);
  padding: 6px;
  z-index: 50;
}
.menu button {
  display: block; width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: none; background: transparent;
  border-radius: 6px;
  color: var(--ink);
  font-size: 12.5px;
}
.menu button:hover { background: var(--accent-soft); color: var(--accent-dark); }
.menu-sep { height: 1px; background: var(--line); margin: 5px 4px; }

/* ---------- рабочая область ---------- */
.main { flex: 1; display: flex; min-height: 0; min-width: 0; }

.rail {
  flex: 0 0 70px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; justify-content: flex-start;
  padding: 7px 5px 8px;
  overflow-y: auto;
  overflow-x: hidden;
}
.rail-tools { display: flex; flex-direction: column; gap: 1px; }
.tool {
  width: 100%;
  border: none; background: transparent;
  border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 5px 1px 4px;
  color: var(--muted);
  transition: background .12s, color .12s;
}
.tool .ico { width: 27px; height: 26px; display: grid; place-items: center; }
.tool .ico svg { width: 26px; height: 26px; overflow: visible; }
.tool .lbl { font-size: 8.5px; letter-spacing: .01em; }
.tool:hover { background: var(--panel-2); color: var(--ink); }
.tool.active { background: var(--accent-soft); color: var(--accent-dark); }
.tool.active .ico { color: var(--accent); }

.rail-durations { border-top: 1px solid var(--line); padding-top: 5px; margin-top: 14px; }
.rail-label { text-align: center; font-size: 7.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted-2); margin: 1px 0 5px; }
.dur-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
.dur-btn {
  height: 27px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  background: #fffdf8;
  border-radius: 5px;
  color: var(--ink);
  padding: 0;
}
.dur-btn svg { width: 22px; height: 22px; overflow: visible; }
.dur-btn:hover { border-color: var(--line-strong); background: #fff; }
.dur-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.rail-dot {
  width: 100%; height: 25px; margin-top: 4px;
  border: 1px solid var(--line); border-radius: 5px;
  background: #fffdf8; color: var(--ink);
  font-size: 17px; line-height: 1; padding: 0 0 5px;
}
.rail-dot.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }

.workspace {
  flex: 1; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  background-color: var(--workspace);
  background-image: radial-gradient(circle at 18% 0%, rgba(255,255,255,.42), transparent 55%);
  position: relative;
}
.scroll { flex: 1; overflow: auto; overscroll-behavior: contain; }
.sheet-wrap {
  display: flex; justify-content: center;
  min-width: max-content;
  padding: 26px 24px 74px;
}
.sheet {
  background: var(--paper);
  box-shadow: var(--shadow);
  border: 1px solid rgba(96, 76, 47, .12);
  min-height: min(66vh, 620px);
  position: relative;
}
.sheet svg { display: block; }
#score { touch-action: none; cursor: default; }
#score.tool-note, #score.tool-rest, #score.tool-bar, #score.tool-clef,
#score.tool-key, #score.tool-time, #score.tool-lyric, #score.tool-tie, #score.tool-text, #score.tool-lamp { cursor: crosshair; }
#score.tool-select { cursor: default; }
#score.dragging { cursor: grabbing; }

.statusbar {
  flex: 0 0 37px;
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px;
  background: #f4efe5;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  min-width: 0;
}
.status-hint { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-hint .k {
  display: inline-block;
  padding: 0 4px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #fffdf8;
  font-size: 10px;
  color: var(--ink);
  margin: 0 1px;
}
.status-hint .accent { color: var(--accent-dark); font-weight: 600; }
.status-right { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.status-info { color: var(--muted-2); font-size: 10.5px; }
.zoom { display: flex; align-items: center; gap: 3px; border-left: 1px solid var(--line); padding-left: 10px; font-size: 10.5px; color: var(--muted-2); }
.zoom-btn { width: 21px; height: 21px; border: 1px solid var(--line); background: #fffdf8; border-radius: 4px; padding: 0; color: var(--muted); font-size: 13px; line-height: 1; }
.zoom-btn:hover { border-color: var(--line-strong); color: var(--ink); }
#zoomLabel { min-width: 36px; text-align: center; }
.zoom-label { border: none; background: transparent; padding: 0 2px; font-size: 10.5px; color: var(--muted-2); }
.zoom-label:hover { color: var(--accent-dark); }

/* ---------- инспектор ---------- */
.inspector {
  flex: 0 0 312px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 14px 13px 28px;
}
.insp-head { padding: 2px 3px 10px; }
.insp-head h2 { font-family: var(--font-serif); font-size: 20px; font-weight: 600; margin: 0 0 3px; letter-spacing: .01em; }
.insp-head p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.panel {
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 11px 12px;
  margin-bottom: 10px;
  box-shadow: 0 1px 0 rgba(255,255,255,.7) inset;
}
.panel h3 {
  margin: 0 0 8px;
  font-size: 9px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted-2);
  font-weight: 600;
}
.field { display: block; margin-bottom: 8px; font-size: 10.5px; color: var(--muted); }
.field:last-child { margin-bottom: 0; }
.field > span { display: block; margin-bottom: 3px; }
.field input[type=text], .field input[type=number], .field select, .field textarea {
  width: 100%;
  height: 29px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  outline: none;
}
.field textarea { height: auto; min-height: 62px; padding: 6px 8px; resize: vertical; line-height: 1.35; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(142, 58, 50, .12); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.row3 { display: grid; grid-template-columns: 1.15fr 1.15fr .95fr; gap: 7px; }
@media (max-width: 640px) { .row3 { grid-template-columns: 1fr; } }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 5px; }
.hint { color: var(--muted); font-size: 10.5px; line-height: 1.45; margin: 7px 0 0; }
.hint b { color: var(--ink); font-weight: 600; }
.kbd {
  display: inline-block; padding: 1px 5px 0; margin: 0 1px;
  border: 1px solid var(--line-strong); border-bottom-width: 2px;
  border-radius: 4px; background: #fff; font-size: 10px; line-height: 1.3; color: var(--ink);
  font-family: var(--font-ui);
}
.stat-line { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--line); font-size: 11px; }
.stat-line:last-child { border-bottom: none; }
.stat-line span:last-child { color: var(--ink); font-weight: 600; }

.seg { display: flex; gap: 2px; padding: 2px; background: var(--panel-2); border-radius: 7px; margin-bottom: 8px; }
.seg button {
  flex: 1; height: 26px; border: none; background: transparent; border-radius: 5px;
  color: var(--muted); font-size: 11px; padding: 0 4px; white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg button.active { background: #fff; color: var(--accent-dark); box-shadow: 0 1px 3px rgba(60,45,25,.13); font-weight: 600; }

.dur-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; margin-bottom: 7px; }
.dur-pick button {
  height: 38px; border: 1px solid var(--line); background: #fff; border-radius: 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  padding: 1px 0; color: var(--ink);
}
.dur-pick button small { font-size: 7.5px; color: var(--muted-2); line-height: 1; }
.dur-pick button svg { width: 19px; height: 19px; overflow: visible; }
.dur-pick button:hover { border-color: var(--line-strong); }
.dur-pick button.active { border-color: var(--accent); background: var(--accent-soft); }
.dur-pick button.active small { color: var(--accent-dark); }

.acc-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.acc-row button {
  height: 30px; border: 1px solid var(--line); background: #fff; border-radius: 6px;
  font-family: var(--font-serif); font-size: 16px; color: var(--ink); padding: 0;
}
.acc-row button:hover { border-color: var(--line-strong); }
.acc-row button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }

.btn-wide {
  width: 100%; height: 32px; border: 1px solid var(--line-strong); background: #fff;
  border-radius: 7px; color: var(--ink); font-size: 11.5px; margin-top: 6px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-wide:hover { border-color: var(--accent); color: var(--accent-dark); }
.btn-wide.primary { background: var(--accent); border-color: var(--accent); color: #fff6e9; }
.btn-wide.primary:hover { background: var(--accent-dark); color: #fff; }
.btn-wide.danger { color: #a04036; border-color: #e0c9c3; }
.btn-wide.danger:hover { background: #fbeeea; border-color: #c98d82; }
.btn-wide[disabled] { opacity: .4; cursor: default; }
.btn-mini {
  height: 26px; border: 1px solid var(--line); background: #fff; border-radius: 5px;
  font-size: 11px; color: var(--ink); padding: 0 8px;
}
.btn-mini:hover { border-color: var(--accent); color: var(--accent-dark); }
.btn-mini.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.stem-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.stem-btn { width: 100%; }
.stem-btn.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.nudge-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 6px; }
.nudge-grid button { height: 28px; border: 1px solid var(--line); background: #fff; border-radius: 5px; font-size: 12px; }
.nudge-grid button:hover { border-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 7px; border-radius: 20px; background: var(--panel-2); font-size: 10px; color: var(--muted); }
.chip b { color: var(--ink); font-weight: 600; }
.empty-note { color: var(--muted); font-size: 11px; line-height: 1.5; }

/* ---------- язык ---------- */
.lang-choose { display: block; }
.lang-btn { text-align: left; padding: 14px 15px; border: 1px solid var(--line-strong); background: #fff; border-radius: 9px; color: var(--ink); }
.lang-btn b { display: block; font-family: var(--font-serif); font-size: 17px; font-weight: 500; }
.lang-btn span { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.lang-btn:hover { border-color: var(--accent); background: #fffaf2; }
.lang-btn.active { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- модальные окна ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(34, 27, 19, .46);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 22px;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: min(590px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: #fbf8f1;
  border: 1px solid #e4dac7;
  border-radius: 14px;
  box-shadow: 0 32px 90px rgba(20, 14, 8, .4);
  animation: modalIn .18s cubic-bezier(.2,.8,.3,1);
}
.modal.wide { width: min(760px, 100%); }
@keyframes modalIn { from { transform: translateY(8px) scale(.99); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { padding: 20px 22px 0; position: relative; }
.modal-head h2 { font-family: var(--font-serif); font-size: 25px; font-weight: 600; margin: 0 0 5px; letter-spacing: .005em; }
.modal-head p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.modal-close {
  position: absolute; top: 14px; right: 14px;
  width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 50%;
  background: #fff; color: var(--muted); font-size: 16px; line-height: 1;
}
.modal-close:hover { color: var(--ink); border-color: var(--line-strong); }
.modal-body { padding: 16px 22px 4px; }
.modal-foot { padding: 14px 22px 20px; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal-foot .btn-cancel, .modal-foot .btn-primary, .modal-foot .btn-ghost {
  height: 34px; padding: 0 15px; border-radius: 7px; font-size: 12px; border: 1px solid var(--line-strong); background: #fff; color: var(--ink);
}
.modal-foot .btn-primary { background: var(--accent); border-color: var(--accent); color: #fff6e9; }
.modal-foot .btn-primary:hover { background: var(--accent-dark); }
.modal-foot .btn-ghost:hover, .modal-foot .btn-cancel:hover { border-color: var(--accent); color: var(--accent-dark); }
.modal .field { font-size: 11px; }
.modal .field input, .modal .field select { height: 33px; font-size: 13px; }
.modal-sep { height: 1px; background: var(--line); margin: 14px 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }
.note-box { background: #f4eee2; border: 1px solid #e5dac5; border-radius: 8px; padding: 10px 12px; font-size: 11.5px; color: #6d6152; line-height: 1.5; }

.check-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.check-table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.check-table td { padding: 7px 8px; border-bottom: 1px solid #eee6d8; vertical-align: top; }
.check-table tr.bad td { background: #fbefeb; }
.check-table .num { font-variant-numeric: tabular-nums; }
.check-table .bad-text { color: #a03a30; font-weight: 600; }

.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.help-grid h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted-2); margin: 0 0 7px; }
.help-grid p, .help-grid li { font-size: 11.5px; line-height: 1.5; color: #51483c; }
.help-grid ul { margin: 0; padding-left: 16px; }
.help-grid li { margin-bottom: 4px; }
.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: 5px 10px; font-size: 11px; align-items: center; }
.shortcuts .keys { white-space: nowrap; }
.help-note { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted-2); font-size: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 56px;
  transform: translate(-50%, 12px);
  background: #2b2620; color: #f6eddd;
  padding: 9px 16px; border-radius: 8px;
  font-size: 12px; max-width: 80vw;
  opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 200;
  box-shadow: 0 10px 28px rgba(0,0,0,.24);
  border-left: 3px solid var(--gold);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-left-color: #c25a4e; }
.toast.ok { border-left-color: #6b8a63; }

/* ---------- SVG-наложения ---------- */
.sel-box { fill: rgba(156, 59, 50, .07); stroke: rgba(156, 59, 50, .7); stroke-width: 0.09; stroke-dasharray: 0.34 0.26; }
.marquee { fill: rgba(156, 59, 50, .05); stroke: rgba(156, 59, 50, .75); stroke-width: 0.10; stroke-dasharray: 0.30 0.22; }
#score.selecting { cursor: crosshair; }
.snap-ring { fill: none; stroke: #9c3b32; stroke-width: 0.12; stroke-dasharray: 0.3 0.2; opacity: .85; }
.tie-from { fill: none; stroke: #9c3b32; stroke-width: 0.14; stroke-dasharray: 0.3 0.2; }
.ghost-note { opacity: .5; }
.ghost-halo { fill: rgba(156, 59, 50, .08); stroke: rgba(156, 59, 50, .45); stroke-width: 0.09; stroke-dasharray: 0.3 0.22; }
.ghost-label rect { fill: #fffaf0; stroke: #cfc2ab; stroke-width: 0.06; opacity: .95; }
.ghost-label text { fill: #7d6e5a; font-family: -apple-system, "Segoe UI", sans-serif; }
.ghost-bar { stroke: #9c3b32; stroke-dasharray: 0.35 0.25; opacity: .55; }
.playhead { stroke: #9c3b32; stroke-width: 0.13; opacity: .85; }
.sounding { fill: rgba(156, 59, 50, .13); stroke: rgba(156, 59, 50, .5); stroke-width: 0.08; }
.check-mark rect { fill: rgba(166, 60, 48, .07); stroke: rgba(166, 60, 48, .5); stroke-width: 0.08; stroke-dasharray: 0.35 0.25; }
.check-mark text { fill: #9c3b32; font-family: -apple-system, "Segoe UI", sans-serif; }
.staff-line { stroke: #2a251f; opacity: .82; }
.lyric-hyphen { stroke: #211d18; }

/* ---------- печать ---------- */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; overflow: visible; font-size: 11px; }
  .topbar, .rail, .inspector, .statusbar, #modalRoot, .toast, .update-bar, .inspector-backdrop { display: none !important; }
  .app, .main, .workspace, .scroll, .sheet-wrap { display: block; height: auto; overflow: visible; background: #fff !important; }
  .sheet-wrap { padding: 0; min-width: 0; }
  .sheet { box-shadow: none; border: none; min-height: 0; width: 100% !important; background: #fff; }
  #score { width: 100% !important; height: auto !important; }
}

@media (max-width: 1220px) {
  .btn span { display: none; }
  .btn { padding: 0 8px; }
  .btn-play { padding: 0 11px; }
  .project-chip { max-width: 230px; }
  .inspector { flex-basis: 288px; }
}
@media (max-width: 980px) {
  .brand-sub { display: none; }
  .brand-by { display: none; }
  .project-chip { display: none; }
  .rail { flex-basis: 62px; }
  .inspector { flex-basis: 265px; }
}

.pending-box { fill: none; stroke: #9c3b32; stroke-width: 0.11; stroke-dasharray: 0.32 0.24; }
.ghost-halo.pending { animation: pendingPulse 1.5s ease-in-out infinite; }
@keyframes pendingPulse {
  0%, 100% { fill-opacity: .35; stroke-opacity: .55; }
  50% { fill-opacity: .08; stroke-opacity: .95; }
}
@media print { #overlayLayer { display: none !important; } }

/* ================= Android / touch ================= */
/* SystemBars Capacitor кладёт --safe-area-inset-*; в браузере работает env(). */
:root {
  --sai-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --sai-right: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
  --sai-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --sai-left: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
}
html, body { overscroll-behavior: none; }
.app { height: 100vh; height: 100dvh; }
.topbar {
  flex: 0 0 auto;
  min-height: 58px;
  padding-top: var(--sai-top);
  padding-left: calc(14px + var(--sai-left));
  padding-right: calc(14px + var(--sai-right));
}
.only-mobile { display: none !important; }
.inspector-backdrop { position: fixed; inset: 0; background: rgba(33, 29, 24, .42); z-index: 65; }
.inspector-backdrop[hidden] { display: none; }

/* полоса обновления (только Android) */
.update-bar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: calc(7px + var(--sai-top)) max(12px, var(--sai-right)) 7px max(12px, var(--sai-left));
  background: #3f5a4a; color: #f3ead8;
  font-size: 12.5px; line-height: 1.3;
}
.update-bar[hidden] { display: none; }
.app:has(.update-bar:not([hidden])) .topbar { padding-top: 0; }
.update-text { flex: 1; min-width: 0; }
.update-actions { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.update-bar .btn-mini {
  height: 32px; padding: 0 14px; border: 0; border-radius: 6px;
  background: #f3ead8; color: #2b332c; font-size: 12.5px;
}
.update-later {
  width: 34px; height: 34px; border: 0; border-radius: 6px;
  background: transparent; color: #f3ead8; font-size: 20px; line-height: 1;
}

@media (max-width: 1023px) {
  .brand-text { display: none; }
  .project-chip { display: flex; max-width: 210px; }
  .project-label, .save-state { display: none; }
  .project-name { max-width: 150px; }

  .only-mobile { display: grid !important; }

  .rail { flex-basis: 58px; padding: 6px 3px calc(8px + var(--sai-bottom)); }
  .rail-label { display: none; }
  .tool { min-height: 46px; padding: 4px 0 3px; }
  .dur-btn { height: 40px; }
  .rail-dot { height: 38px; }

  .statusbar { flex-basis: 44px; }
  .zoom-btn { width: 38px; height: 38px; font-size: 17px; }
  .zoom-label { min-width: 48px; font-size: 12px; }

  .inspector {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: auto; max-height: min(56vh, 560px);
    flex-basis: auto;
    z-index: 70;
    transform: translateY(105%);
    transition: transform .24s ease;
    border-radius: 16px 16px 0 0;
    border-left: 0; border-top: 1px solid var(--line-strong);
    box-shadow: 0 -18px 44px rgba(33, 29, 24, .3);
    padding: 6px 14px calc(18px + var(--sai-bottom));
    overscroll-behavior: contain;
  }
  .inspector.open { transform: none; }
  .insp-close-row {
    position: sticky; top: 0; z-index: 2;
    display: flex; justify-content: flex-end; align-items: center;
    min-height: 28px;
    margin: -2px 0 2px;
    padding-top: 6px;
    background: linear-gradient(var(--panel) 70%, rgba(246, 242, 234, 0));
  }
  .insp-close-row::before {
    content: ""; position: absolute; left: 50%; top: 4px;
    width: 40px; height: 4px; border-radius: 2px;
    background: var(--line-strong); transform: translateX(-50%);
  }
  .insp-close {
    width: 44px; height: 44px; padding: 0 0 4px;
    border: 1px solid var(--line); border-radius: 50%;
    background: #fffdf8; color: var(--muted);
    font-size: 26px; line-height: 1;
  }
}

@media (max-width: 760px) {
  .topbar-actions > .btn-group:first-child,
  .topbar-actions > .btn-group.wide,
  .help-btn { display: none; }
  .btn-play span { display: none; }
  .btn-play { padding: 0 12px; }
  .status-hint { display: none; }
  .topbar { gap: 7px; padding-left: calc(8px + var(--sai-left)); padding-right: calc(8px + var(--sai-right)); }
  .project-chip { max-width: 150px; }
  .project-name { max-width: 140px; }
}

@media (max-width: 600px), (max-height: 500px) {
  .brand { display: none; }
  .project-chip { max-width: 120px; }
  .project-name { max-width: 116px; font-size: 12px; }
  .topbar { min-height: 50px; }
  .icon-btn { width: 38px; height: 38px; }
  .topbar-actions { gap: 4px; }
  .btn-play { height: 38px; padding: 0 11px; }

  .main { padding-bottom: calc(104px + var(--sai-bottom)); }
  .rail {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: auto; height: calc(104px + var(--sai-bottom));
    flex: 0 0 auto;
    flex-direction: column; justify-content: flex-start;
    background: var(--panel);
    border-right: 0; border-top: 1px solid var(--line);
    padding: 4px 6px calc(4px + var(--sai-bottom));
    z-index: 60;
    overflow: hidden;
  }
  .rail-tools {
    flex-direction: row; gap: 2px;
    flex: 0 0 46px;
    overflow-x: auto; overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .rail-tools::-webkit-scrollbar { display: none; }
  .rail-tools .tool { flex: 0 0 44px; width: 44px; min-height: 44px; }
  .rail-durations {
    display: flex; align-items: center; gap: 5px;
    flex: 0 0 44px; margin: 3px 0 0; padding: 3px 0 0;
    border-top: 1px solid var(--line);
  }
  .rail-label { display: none; }
  .dur-grid { display: flex; gap: 4px; flex: 1; }
  .dur-btn { flex: 1 1 0; height: 44px; }
  .rail-dot { flex: 0 0 44px; width: 44px; height: 44px; margin: 0; }

  .statusbar { flex-basis: 42px; padding: 0 8px; gap: 8px; }
  .statusbar .status-info { font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sheet-wrap { padding: 10px 8px 46px; }
  .toast { bottom: calc(120px + var(--sai-bottom)); max-width: 92vw; }
  .inspector { bottom: calc(104px + var(--sai-bottom)); max-height: min(52vh, 460px); }

  .update-bar { font-size: 12px; gap: 6px; }
  .update-bar .btn-mini { padding: 0 10px; height: 30px; }
}

@media (hover: none) and (pointer: coarse) {
  .status-hint { display: none; }
}

/* ---------- панель выделения нескольких нот (тач) ---------- */
.multi-bar {
  position: fixed; left: 50%; bottom: calc(112px + var(--sai-bottom));
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px;
  max-width: calc(100vw - 16px);
  padding: 6px; border-radius: 12px;
  background: #29241f; color: #f3ead8;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .35);
  z-index: 90;
}
.multi-bar[hidden] { display: none; }
.multi-count { font-size: 12px; padding: 0 8px; white-space: nowrap; }
.multi-btn {
  height: 40px; padding: 0 12px;
  border: 0; border-radius: 8px;
  background: rgba(255, 255, 255, .12); color: #f3ead8;
  font-size: 12.5px; white-space: nowrap;
}
.multi-btn.primary { background: var(--accent); }
@media (max-width: 600px), (max-height: 500px) {
  .multi-bar { bottom: calc(186px + var(--sai-bottom)); gap: 2px; padding: 5px; }
  .multi-btn { height: 38px; padding: 0 10px; font-size: 12px; }
  .multi-count { padding: 0 5px; }
}

.help-desktop { margin: 2px 0 0; }
.help-desktop > summary {
  cursor: pointer; padding: 7px 0;
  font-size: 10px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted-2);
}
.help-desktop[open] > summary { margin-bottom: 8px; }
.help-desktop > summary::marker { color: var(--accent); }

.multi-bar .multi-btn[hidden] { display: none; }
