:root {
  --paper: #f6f1e7;
  --card: #fffdf8;
  --ink: #1f1c18;
  --muted: #6e665b;
  --line: #e2d9c8;
  --accent: #9c2b22;
  --accent-ink: #fff;
  --soft: #efe6d4;
  --play: #c0392b;
  --start: #1f5fa8;
  --shadow: 0 1px 2px rgba(60, 40, 10, .08), 0 4px 16px rgba(60, 40, 10, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body { font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 22px; margin: 0; flex: 1; letter-spacing: -.01em; }
.top .title { flex: 1; min-width: 0; font-weight: 600; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: none; border: 0; text-align: left; padding: 6px 0; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; display: grid; place-items: center; flex: none; }
.icon-btn:active { background: var(--soft); }
.icon-btn svg { width: 24px; height: 24px; }

.wrap { padding: 16px; max-width: 760px; margin: 0 auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 20px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; box-shadow: var(--shadow);
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .5; }
.btn svg { width: 22px; height: 22px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.hint { background: var(--soft); border-radius: 12px; padding: 12px 14px; font-size: 15px; color: var(--muted); }
.warn { background: #fbecd6; color: #6b4300; border-radius: 12px; padding: 10px 14px; font-size: 15px; margin: 10px 16px 0; }
.err { background: #f8dcd8; color: #7a1c13; border-radius: 12px; padding: 12px 14px; }

/* библиотека */
.list { display: grid; gap: 12px; margin-top: 16px; }
.item {
  display: flex; gap: 14px; align-items: center; padding: 10px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); text-decoration: none; color: inherit;
}
.item .thumb { width: 64px; height: 84px; border-radius: 8px; background: var(--soft) center/cover no-repeat; flex: none; display: grid; place-items: center; color: var(--muted); }
.item .meta { min-width: 0; }
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item.busy .thumb::after { content: ""; width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
.empty { text-align: center; padding: 48px 16px 24px; color: var(--muted); }
.empty svg { width: 72px; height: 72px; opacity: .5; }
.fab-row { position: sticky; bottom: 0; padding: 12px 16px calc(12px + var(--safe-b)); background: linear-gradient(transparent, var(--paper) 30%); max-width: 760px; margin: 0 auto; }

/* новый скан */
.sources { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.sources .btn { flex-direction: column; min-height: 92px; gap: 6px; font-size: 15px; }
.sources .btn.camera { grid-column: 1 / -1; min-height: 64px; flex-direction: row; font-size: 17px; }
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; margin: 12px 0; }
.pg { position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; background: var(--soft); border: 1px solid var(--line); display: grid; place-items: center; text-align: center; font-size: 13px; color: var(--muted); padding: 4px; }
.pg img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pg .no { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.6); color: #fff; border-radius: 8px; padding: 1px 7px; font-size: 13px; }
.pg .x { position: absolute; right: 4px; top: 4px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 18px; line-height: 1; }
.pg .mv { position: absolute; bottom: 4px; display: flex; gap: 4px; left: 4px; right: 4px; justify-content: space-between; }
.pg .mv button { width: 32px; height: 28px; border-radius: 8px; border: 0; background: rgba(0,0,0,.55); color: #fff; }
label.field { display: block; margin: 12px 0; }
label.field span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], select {
  width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); padding: 0 12px;
}
details { margin: 12px 0; }
summary { color: var(--muted); padding: 8px 0; }

/* ожидание */
.wait { text-align: center; padding: 40px 16px; }
.spinner { width: 56px; height: 56px; margin: 0 auto 18px; border: 5px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.upbar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 16px auto; max-width: 320px; }
.upbar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* ноты */
.score { padding: 8px 0 calc(190px + var(--safe-b)); background: #fff; min-height: 60vh; }
.score .page { max-width: 1100px; margin: 0 auto; }
.score svg { display: block; width: 100%; height: auto; }
.score g.measure { cursor: pointer; }
.score rect.cursor { fill: #3a8ee6; fill-opacity: 0; pointer-events: none; transition: x .18s ease-out, y .18s ease-out, width .18s ease-out, height .18s ease-out, fill-opacity .15s; }
.score rect.cursor.on { fill-opacity: .2; }
.score g.note.playing, .score g.note.playing * , .score g.chord.playing * { fill: var(--play); stroke: var(--play); color: var(--play); }
.score g.measure.start g.note, .score g.measure.start g.note * { fill: var(--start); color: var(--start); }
.loading-score { padding: 60px 16px; text-align: center; color: var(--muted); }

.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -6px 24px rgba(60, 40, 10, .10);
  padding: 10px 14px calc(10px + var(--safe-b));
}
.player .row { display: flex; align-items: center; gap: 10px; max-width: 760px; margin: 0 auto; }
.player .row + .row { margin-top: 10px; }
.play { width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; box-shadow: var(--shadow); }
.play svg { width: 30px; height: 30px; }
.play:active { transform: scale(.96); }
.tempo { flex: 1; min-width: 0; }
.tempo .val { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; font-size: 15px; }
.tempo .val b { font-size: 19px; }
.tempo .val button { border: 0; background: none; color: var(--accent); font-size: 14px; padding: 4px 0; }
.tempo .ctl { display: flex; align-items: center; gap: 6px; }
.round { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper); font-size: 22px; line-height: 1; flex: none; }
input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); height: 32px; }
.player select { flex: 1; min-height: 44px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; background: #e3ecf7; color: var(--start); padding: 6px 6px 6px 12px; font-size: 14px; border: 0; }
.chip b { font-weight: 600; }
.chip i { font-style: normal; width: 24px; height: 24px; border-radius: 50%; background: rgba(31,95,168,.15); display: grid; place-items: center; }
.parts-btn { min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--paper); font-weight: 600; white-space: nowrap; }

/* нижняя шторка */
.sheet-bg { position: fixed; inset: 0; background: rgba(20, 14, 6, .35); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 640px; max-height: 85vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + var(--safe-b)); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { font-size: 19px; margin: 4px 0 12px; }
.staff-row { padding: 12px 0; border-top: 1px solid var(--line); }
.staff-row .head { display: flex; align-items: center; gap: 10px; }
.staff-row .head b { flex: 1; font-weight: 600; }
.staff-row .ctl { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.staff-row select { flex: 1; min-height: 40px; font-size: 15px; }
.toggle { position: relative; width: 52px; height: 32px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle span { position: absolute; inset: 0; background: var(--line); border-radius: 16px; transition: .15s; }
.toggle span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: .15s; }
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(20px); }
.solo { min-height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); font-size: 14px; font-weight: 600; }
.solo.on { background: var(--start); color: #fff; border-color: var(--start); }
.menu-item { display: flex; width: 100%; text-align: left; align-items: center; gap: 12px; min-height: 54px; border: 0; border-top: 1px solid var(--line); background: none; padding: 0 4px; font-size: 17px; }
.menu-item.danger { color: var(--accent); }

#toast { position: fixed; left: 50%; bottom: calc(210px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }

.login { max-width: 380px; margin: 0 auto; padding: 80px 20px; text-align: center; }
.login .logo { width: 84px; height: 84px; border-radius: 20px; margin: 0 auto 16px; display: block; }

@media (min-width: 700px) {
  .sources { grid-template-columns: 1fr 1fr 1fr; }
  .sources .btn.camera { grid-column: auto; flex-direction: column; min-height: 92px; }
}
