:root {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --surface-2: #f1ece4;
  --text: #22201c;
  --muted: #7a736a;
  --line: #e6e0d6;
  --accent: #a4264f;
  --accent-soft: #f6e3ea;
  --plus: #a4264f;
  --plus-soft: #f8e6ec;
  --minus: #2d5f8b;
  --minus-soft: #e3edf6;
  --orig: #5b6b3a;
  --orig-soft: #ebf0df;
  --shadow: 0 1px 2px rgb(40 30 20 / .06), 0 4px 16px rgb(40 30 20 / .05);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171513;
    --surface: #211e1b;
    --surface-2: #2b2723;
    --text: #efe9e1;
    --muted: #a49b90;
    --line: #36312b;
    --accent: #f07fa3;
    --accent-soft: #3c2330;
    --plus: #f58bab;
    --plus-soft: #3b2029;
    --minus: #8ec0ec;
    --minus-soft: #1e2d3b;
    --orig: #b9cf86;
    --orig-soft: #283020;
    --shadow: 0 1px 2px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 820px;
  margin: 0 auto;
  padding: 32px 16px 48px;
}
body.has-player main { padding-bottom: 190px; }

h1 { font-size: clamp(28px, 6vw, 40px); line-height: 1.1; margin: 0 0 6px; letter-spacing: -.02em; }
h2 { font-size: 18px; margin: 0; line-height: 1.3; }
p { margin: 0; }
.muted { color: var(--muted); }
.eyebrow { color: var(--accent); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }

button, input, select { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  text-decoration: none; cursor: pointer; font-weight: 500;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #1b1215; } }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 14px; }

.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 16px; flex-wrap: wrap; margin-bottom: 24px;
}
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.toolbar { display: flex; gap: 8px; margin-bottom: 16px; }
.search {
  flex: 1; min-width: 0; width: 100%;
  padding: 11px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
  margin-bottom: 16px;
}
.toolbar .search { margin-bottom: 0; }
.search:focus, .sort:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.sort {
  padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
}

/* Ученики */
.students { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.student {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px;
}
.student-name { font-weight: 650; font-size: 17px; color: var(--text); text-decoration: none; }
.student-name:hover { color: var(--accent); }
.student-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.badge {
  display: inline-block; margin-left: 8px;
  padding: 1px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 600; vertical-align: 2px;
}

/* Песни */
.songs { display: flex; flex-direction: column; gap: 10px; }
.song {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.song-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 4px; margin-bottom: 10px; }
.song-head .badge { margin-left: 4px; }
.owner { color: var(--muted); font-size: 14px; margin-left: auto; }

.variants { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid transparent; font-size: 15px; font-weight: 500;
  transition: transform .1s, box-shadow .15s;
}
.chip::before {
  content: ""; width: 0; height: 0;
  border-left: 7px solid currentColor; border-top: 5px solid transparent; border-bottom: 5px solid transparent;
}
.chip:active { transform: scale(.97); }
.chip.plus { background: var(--plus-soft); color: var(--plus); }
.chip.minus { background: var(--minus-soft); color: var(--minus); }
.chip.orig { background: var(--orig-soft); color: var(--orig); }
.chip.active { border-color: currentColor; box-shadow: 0 0 0 3px var(--surface), 0 0 0 4px currentColor; }
.chip.active::before {
  border: 0; width: 8px; height: 10px;
  background: linear-gradient(90deg, currentColor 0 3px, transparent 3px 5px, currentColor 5px);
}

.link-btn {
  background: none; border: 0; padding: 0; margin-top: 12px;
  color: var(--accent); cursor: pointer; font-size: 15px; font-weight: 500;
}
.link-btn:hover { text-decoration: underline; }
.lyrics {
  margin-top: 10px; padding: 14px 16px; border-radius: 10px;
  background: var(--surface-2); white-space: pre-wrap; line-height: 1.65;
}

/* Состояния */
.state { text-align: center; padding: 64px 16px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.state .btn { margin-top: 8px; }
.landing { padding-top: 18vh; }
.landing-mark {
  width: 72px; height: 72px; border-radius: 50%;
  display: grid; place-items: center; font-size: 34px;
  background: var(--accent-soft); color: var(--accent); margin-bottom: 8px;
}
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Плеер */
.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 24px rgb(0 0 0 / .08);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: grid; gap: 6px 16px; align-items: center;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas: "info controls extra" "time time time";
}
.player[hidden] { display: none; }
.p-info { grid-area: info; min-width: 0; }
.p-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-controls { grid-area: controls; display: flex; align-items: center; gap: 6px; }
.p-extra { grid-area: extra; display: flex; align-items: center; gap: 4px; }
.p-timeline { grid-area: time; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.p-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: transparent; color: var(--text); cursor: pointer;
  display: grid; place-items: center; text-decoration: none;
}
.p-btn:hover { background: var(--surface-2); }
.p-btn svg { width: 24px; height: 24px; fill: currentColor; }
.p-btn text { fill: currentColor; }
.p-btn.small { width: 36px; height: 36px; }
.p-btn.small svg { width: 20px; height: 20px; }
.p-play { width: 48px; height: 48px; background: var(--accent); color: #fff; }
.p-play:hover { background: var(--accent); filter: brightness(1.08); }
@media (prefers-color-scheme: dark) { .p-play { color: #1b1215; } }
.p-play .i-pause, .p-play.playing .i-play { display: none; }
.p-play.playing .i-pause { display: block; }
.p-play .i-play  { transform: translateX(-1px); }  /* треугольник: центр был на 1,5px правее */
.p-play .i-pause { transform: translateX(0); }     /* точка для подгонки паузы, если понадобится */
.busy .p-play { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.p-loop[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.p-speed {
  height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); padding: 0 6px; font-size: 14px;
}

.p-seek {
  --p: 0%;
  flex: 1; min-width: 0; height: 20px; margin: 0; background: transparent;
  -webkit-appearance: none; appearance: none; cursor: pointer;
}
.p-seek::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--p), var(--line) var(--p));
}
.p-seek::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
.p-seek::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
.p-seek::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px;
  border-radius: 50%; background: var(--accent); border: 0;
}
.p-seek::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 0; }

@media (max-width: 600px) {
  main { padding-top: 24px; }
  .player {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "info extra" "time time" "controls controls";
  }
  .p-controls { justify-content: center; gap: 20px; }
  .page-head { align-items: flex-start; }
  .owner { margin-left: 0; width: 100%; }
}

/* ---------- Редактирование ---------- */
.song-links { display: flex; gap: 18px; }
.teacher-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 18px; }
.more { position: relative; }
.more summary { list-style: none; }
.more summary::-webkit-details-marker { display: none; }
.more-menu {
  position: absolute; z-index: 5; top: calc(100% + 6px); left: 0;
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px; box-shadow: var(--shadow); min-width: 260px;
}
.btn.danger { color: #c0392b; }
@media (prefers-color-scheme: dark) { .btn.danger { color: #ff8a7a; } }

.editor { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 14px; }
.editor-inner { display: flex; flex-direction: column; gap: 18px; }
.editor-inner.card, .add-song .editor-inner {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); gap: 12px; margin-bottom: 16px;
}
.editor-inner h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.editor-inner.card h3 { margin: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row + .row { margin-top: 8px; }
.row.end { justify-content: flex-end; margin-top: 8px; }
.row .field { flex: 1; min-width: 140px; }
.field {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); font-size: 15px;
}
.field:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
select.field { flex: 0 0 auto; min-width: 0; width: auto; }
.lyrics-edit { resize: vertical; line-height: 1.6; font-family: inherit; }
.file-input { flex: 1; min-width: 0; font-size: 14px; }
.small { font-size: 13px; }

.variant-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.variant-row {
  display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto auto; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 10px; background: var(--surface-2);
}
.variant-row .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.variant-name { font-weight: 500; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.plus { background: var(--plus); } .dot.minus { background: var(--minus); } .dot.orig { background: var(--orig); }
@media (max-width: 600px) {
  .variant-row { grid-template-columns: auto minmax(0, 1fr) auto auto; }
  .variant-row .muted { display: none; }
}

.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 8px; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.hint { margin-top: 28px; font-size: 14px; }
body.saving, body.saving * { cursor: progress !important; }

.toasts {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%); top: 16px;
  display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100% - 32px));
}
.toast {
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  box-shadow: 0 6px 24px rgb(0 0 0 / .18); font-size: 15px; animation: toast-in .2s ease-out;
}
.toast.error { background: #c0392b; color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* ---------- Оформление текста песни ---------- */
.lyrics b, .lyrics-edit b { font-weight: 700; }
.lyrics mark, .lyrics-edit mark { background: #fff176; color: #22201c; border-radius: 3px; padding: 0 2px; }
.c-red { color: #c62828; } .c-blue { color: #1565c0; } .c-green { color: #2e7d32; } .c-purple { color: #7b1fa2; }
@media (prefers-color-scheme: dark) {
  .lyrics mark, .lyrics-edit mark { background: #6b5d12; color: #fff8d6; }
  .c-red { color: #ff8a80; } .c-blue { color: #82b1ff; } .c-green { color: #9ccc65; } .c-purple { color: #ce93d8; }
}
.lyrics-editor { border: 1px solid var(--line); border-radius: 10px; background: var(--bg); overflow: hidden; }
.lyrics-editor:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.lyrics-editor .lyrics-edit {
  border: 0; border-radius: 0; outline: none; min-height: 180px; max-height: 60vh; overflow-y: auto;
  white-space: pre-wrap; padding: 12px 14px;
}
.lyrics-edit:empty::before { content: attr(data-placeholder); color: var(--muted); }
.lyrics-edit.loading { color: var(--muted); }
.toolbar-fmt {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
  padding: 6px; border-bottom: 1px solid var(--line); background: var(--surface-2);
  position: sticky; top: 0;
}
.tool {
  min-width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent;
  cursor: pointer; font-size: 16px; display: grid; place-items: center; padding: 0 6px;
}
.tool:hover { background: var(--surface); }
.tool mark { background: #fff176; color: #22201c; padding: 0 3px; border-radius: 3px; }
.swatch { width: 18px; height: 18px; border-radius: 50%; background: currentColor; display: block; }
.tool.plain { font-weight: 700; }
.tool-sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

/* ---------- Редактор v2: черновик + «Сохранить всё» ---------- */
.song-links[hidden] { display: none; }
.lyrics .collapse { display: block; margin: 14px 0 0; }
.editor-title { font-size: 17px !important; color: var(--text) !important; text-transform: none !important; letter-spacing: 0 !important; margin: 0 !important; }

.variant-row {
  grid-template-columns: auto auto minmax(90px, 1fr) minmax(0, 1fr) auto;
}
.variant-row .field { padding: 6px 10px; font-size: 14px; background: var(--surface); }
.variant-row select.field { width: auto; }
.variant-row .file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.variant-row.removed { opacity: .55; }
.variant-row.removed .field, .variant-row.removed .file-name { text-decoration: line-through; }
.variant-row.new { background: var(--accent-soft); }
.dot.new { background: var(--accent); }
.row-progress { grid-column: 1 / -1; margin-top: 2px; height: 4px; }
.edit-section > .btn { margin-top: 4px; }
.edit-section > p.small { margin-top: 6px; }
.edit-section .row + .row { margin-top: 10px; }

.editor-footer {
  position: sticky; bottom: 0; z-index: 3;
  display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap;
  margin: 0 -16px -14px; padding: 12px 16px;
  background: var(--surface); border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
}
.editor-inner.card .editor-footer { margin: 0 -16px -16px; }
body.has-player .editor-footer { bottom: 118px; }
.save-status { margin-right: auto; }

@media (max-width: 600px) {
  .variant-row { grid-template-columns: auto auto minmax(0, 1fr) auto; }
  .variant-row .file-name { display: none; }
  body.has-player .editor-footer { bottom: 172px; }
}

/* ---------- Импульс ---------- */
.impulse {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px;
  margin: -2px 0 12px;
}
.impulse-label {
  font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent);
}
.impulse-word {
  font-size: 17px; font-weight: 650; padding: 2px 12px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.impulse.empty .impulse-word { background: transparent; color: var(--muted); font-weight: 400; font-size: 14px; padding: 0; }
.impulse-word.as-btn { border: 0; cursor: pointer; font: inherit; font-size: 17px; font-weight: 650; }
.impulse-input { width: 180px; flex: 0 1 180px; }
.impulse.required {
  padding: 10px 12px; border-radius: 12px; border: 2px dashed var(--accent); background: var(--accent-soft);
}
.impulse-hint { width: 100%; color: var(--accent); margin: 0; }

/* ---------- Заметки, текст и перевод ---------- */
.notes {
  margin-top: 12px; padding: 10px 14px; border-radius: 10px;
  background: var(--surface-2); border-left: 3px solid var(--accent);
  white-space: pre-wrap; font-size: 15px;
}
.pane-title { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.reading { display: grid; gap: 12px; }
.reading[hidden] { display: none; }
@media (min-width: 760px) {
  .reading.two { grid-template-columns: 1fr 1fr; }
}
.song-links { flex-wrap: wrap; }
.notes-edit { resize: vertical; line-height: 1.5; font-family: inherit; }

/* ---------- Плеер: импульс и метроном ---------- */
.p-impulse {
  display: inline-block; margin-bottom: 2px; padding: 1px 10px; border-radius: 999px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 15px;
}
@media (prefers-color-scheme: dark) { .p-impulse { color: #1b1215; } }
.p-impulse[hidden] { display: none; }
.p-metro-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.player { grid-template-areas: "info controls extra" "metro metro metro" "time time time"; }
.p-metro {
  grid-area: metro; display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px;
  padding: 6px 10px; border-radius: 12px; background: var(--surface-2);
}
.p-metro[hidden] { display: none; }
.m-bpm { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 64px; }
.m-status { flex: 1; min-width: 0; }
.m-tools { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.m-btn {
  min-width: 34px; height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; padding: 0 8px;
}
.m-btn:hover { border-color: var(--muted); }
.m-btn.wide { font-weight: 500; }
.m-vol { width: 90px; accent-color: var(--accent); }
.m-tempo { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.m-bpm-input { width: 70px; height: 32px; border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; background: var(--surface); color: var(--text); font: inherit; }
.m-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.m-dot.beat { animation: beat .18s ease-out; }
@keyframes beat { from { background: var(--accent); transform: scale(1.35); } to { background: var(--line); transform: scale(1); } }
body.has-player:has(.player.with-metro) main { padding-bottom: 250px; }
body.has-player:has(.player.with-metro) .editor-footer { bottom: 170px; }

@media (max-width: 600px) {
  .player { grid-template-areas: "info extra" "metro metro" "time time" "controls controls"; }
  .m-status { flex-basis: 100%; order: 5; }
  body.has-player:has(.player.with-metro) .editor-footer { bottom: 250px; }
}
.m-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Постоянный метроном преподавателя */
.standalone-widget { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: var(--shadow); padding-top: env(safe-area-inset-top); }
.standalone-widget[hidden] { display: none; }
.standalone-inner { max-width: 820px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; }
.standalone-title, .standalone-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.standalone-title strong { font-size: 15px; }
.standalone-bpm { width: 72px; height: 32px; padding: 0 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); font-variant-numeric: tabular-nums; }
.standalone-controls .btn { min-width: 100px; }
.standalone-pattern { max-width: 165px; height: 32px; padding: 0 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); font-size: 14px; }
@media (max-width: 430px) {
  .standalone-inner { gap: 6px; padding: 8px 12px; }
  .standalone-controls { gap: 5px; }
  .standalone-controls .m-vol { width: 62px; }
}
