/* ───────── Токены (палитра «Круга ритма») ───────── */
:root {
  --bg: #e7e1d7;
  --bg2: #dcd4c7;
  --card: #f5f1ea;
  --text: #231c16;
  --muted: #6c6155;
  --faint: #948878;
  --line: #c6bcab;
  --accent: #0d6f78;
  --accent-2: #11838d;
  --accent-text: #f5f1ea;
  --accent-soft: #b9d7d6;
  --chip: #dcd4c7;
  --good: #2f7d4f;
  --good-bg: rgba(47, 125, 79, 0.14);
  --bad: #b0801a;
  --danger: #b33f22;
  --now: rgba(13, 111, 120, 0.18);
  --alt: rgba(60, 45, 30, 0.04);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.6), 0 2px 10px rgba(60, 45, 30, 0.1);

  /* голоса, как в «Круге ритма»: low / mid / high / metal / air */
  --v-low: #b33f22;
  --v-mid: #b0801a;
  --v-high: #0d6f78;
  --v-metal: #4f6f92;
  --v-air: #7e7364;

  --st-O: var(--v-mid);
  --st-S: var(--v-low);
  --st-M: var(--v-metal);
  --st-T: var(--v-high);
  --st-P: #6d5a8c;
  --st-H: #7a4b26;
  --st-perc: var(--v-air);
  --st-bell: var(--v-metal);
  --st-bell-hi: #86a3c2;
  --voice-a: var(--v-mid);
  --voice-b: var(--v-high);

  --radius: 10px;
  --tabs-h: 57px;
  --cell: 30px;
  --lw: 96px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131110;
    --bg2: #272220;
    --card: #1d1a18;
    --text: #efe8dd;
    --muted: #9c9083;
    --faint: #6e645a;
    --line: #39322d;
    --accent: #3cb8b0;
    --accent-2: #5cc8c1;
    --accent-text: #131110;
    --accent-soft: #1e4a4c;
    --chip: #272220;
    --good: #5bbf7f;
    --good-bg: rgba(91, 191, 127, 0.15);
    --bad: #dca83b;
    --danger: #e0714d;
    --now: rgba(60, 184, 176, 0.24);
    --alt: rgba(255, 255, 255, 0.025);
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.04), 0 2px 14px rgba(0, 0, 0, 0.45);
    --v-low: #e0714d;
    --v-mid: #dca83b;
    --v-high: #3cb8b0;
    --v-metal: #88a8c8;
    --v-air: #a2968a;
    --st-P: #a08cc8;
    --st-H: #c0834f;
    --st-bell-hi: #b5cbe0;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
    --bg: #131110;
    --bg2: #272220;
    --card: #1d1a18;
    --text: #efe8dd;
    --muted: #9c9083;
    --faint: #6e645a;
    --line: #39322d;
    --accent: #3cb8b0;
    --accent-2: #5cc8c1;
    --accent-text: #131110;
    --accent-soft: #1e4a4c;
    --chip: #272220;
    --good: #5bbf7f;
    --good-bg: rgba(91, 191, 127, 0.15);
    --bad: #dca83b;
    --danger: #e0714d;
    --now: rgba(60, 184, 176, 0.24);
    --alt: rgba(255, 255, 255, 0.025);
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.04), 0 2px 14px rgba(0, 0, 0, 0.45);
    --v-low: #e0714d;
    --v-mid: #dca83b;
    --v-high: #3cb8b0;
    --v-metal: #88a8c8;
    --v-air: #a2968a;
    --st-P: #a08cc8;
    --st-H: #c0834f;
    --st-bell-hi: #b5cbe0;
    color-scheme: dark;
}

/* ───────── База ───────── */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; margin-top: 1.2em; }
p { margin: 0 0 0.8em; }
kbd {
  font: 600 0.8em ui-monospace, monospace;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg2);
}
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; justify-content: center; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ───────── Шапка и навигация ───────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.brand-logo {
  width: 30px;
  height: 22px;
  background:
    radial-gradient(circle at 30% 50%, var(--v-low) 0 7px, transparent 7.5px),
    radial-gradient(circle at 72% 50%, var(--v-mid) 0 10px, transparent 10.5px);
}
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs a {
  padding: 7px 12px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}
.tabs a:hover { color: var(--text); background: var(--chip); }
.tabs a.active { background: var(--accent); color: var(--accent-text); }
.lang { display: flex; align-items: center; gap: 4px; margin-left: auto; color: var(--muted); }
.lang select { font: inherit; font-size: 0.85rem; color: var(--text); background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; cursor: pointer; }
.volume { display: flex; align-items: center; gap: 6px; }
.volume input { width: 100px; accent-color: var(--accent); }

.bottom-tabs {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--card);
  border-top: 1px solid var(--line);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}
.bottom-tabs a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  color: var(--muted);
  text-decoration: none;
  padding: 2px 0;
  border-radius: 10px;
  min-width: 0;
}
.bottom-tabs a span { font-size: 1.2rem; line-height: 1.3; }
.bottom-tabs a.active { color: var(--accent); background: var(--accent-soft); }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }
.page { display: none; }
.player, .lesson, .card { scroll-margin-top: 76px; }
.rgrid.editing { --lw: 132px; }
.page.active { display: block; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}

/* ───────── Кнопки и поля ───────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: var(--chip); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.small { padding: 5px 10px; font-size: 0.88rem; border-radius: 8px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-2); }
.btn.ok { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.btn.danger { color: var(--danger); }
.btn.play { min-width: 130px; font-size: 1.05rem; background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.play.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn.play.big { min-width: 170px; padding: 13px 22px; font-size: 1.2rem; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

input[type="number"], input[type="text"], input[type="search"], select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
}
input[type="number"] { width: 64px; }
input[type="range"] { accent-color: var(--accent); }
textarea { width: 100%; resize: vertical; }
.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 14px 0; }
.controls.options { font-size: 0.95rem; }
.center-row { display: flex; justify-content: center; }

.bpm-control { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.bpm-label { font-weight: 600; color: var(--muted); }
.bpm-num { width: 70px !important; text-align: center; font-weight: 700; }
.bpm-range { width: 160px; }
.bpm-unit { color: var(--muted); font-size: 0.85rem; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--bg2); }
.seg.wrap { flex-wrap: wrap; }
.seg button {
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 7px 12px;
  cursor: pointer;
}
.seg button.sel { background: var(--accent); color: var(--accent-text); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--chip); padding: 3px 10px; border-radius: 999px; font-size: 0.85rem; }
.chip.ok { background: var(--good-bg); color: var(--good); }
.chip-btn {
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.chip-btn.sel { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.note {
  background: var(--chip);
  border-left: 4px solid var(--accent);
  padding: 10px 14px;
  border-radius: 8px;
  margin: 12px 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(140px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s;
  z-index: 50;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ───────── Клетки ударов ───────── */
.cell { color: var(--card); }
.cell.st-O { background: var(--st-O); }
.cell.st-S { background: var(--st-S); }
.cell.st-M { background: var(--st-M); }
.cell.st-T { background: var(--st-T); }
.cell.st-P { background: var(--st-P); }
.cell.st-H { background: var(--st-H); }
.cell.st-perc { background: var(--st-perc); }
.cell.st-perc.accent { background: var(--text); color: var(--bg); }
.cell.st-bell { background: var(--st-bell); }
.cell.st-bell-hi { background: var(--st-bell-hi); color: #073b47; }
.cell.ghost { opacity: 0.45; }

/* ───────── Старт ───────── */
.hero {
  display: flex;
  align-items: center;
  gap: 24px;
  justify-content: space-between;
  background:
    radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 55%),
    var(--card);
}
.hero h1 { font-size: 2rem; }
.lead { font-size: 1.08rem; color: var(--muted); max-width: 640px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.progress-ring {
  --p: 0;
  flex: none;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--chip) 0);
}
.progress-ring span {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--card);
  display: grid;
  place-content: center;
  text-align: center;
}
.progress-ring b { font-size: 1.7rem; }
.progress-ring small { color: var(--muted); }

.start-grid { display: grid; grid-template-columns: 1fr 340px; gap: 20px; margin-top: 20px; align-items: start; }
.side-col { display: grid; gap: 20px; }
.path { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.path-step { border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.path-step.complete { border-color: var(--good); background: var(--good-bg); }
.path-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.path-head .muted { margin-left: auto; font-size: 0.85rem; }
.path-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  font-size: 0.9rem;
}
.complete .path-num { background: var(--good); color: var(--card); }
.path-items { display: flex; flex-wrap: wrap; gap: 6px; }
.path-item {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}
.path-item:hover { border-color: var(--accent); }
.path-item.done { color: var(--muted); }
.feature-list, .keys { padding-left: 0; list-style: none; margin: 0; display: grid; gap: 8px; }
.feature-list a { text-decoration: none; }

/* ───────── Две колонки ───────── */
.two-col { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
.list-col { position: sticky; top: 76px; max-height: calc(100vh - 100px); overflow: auto; padding: 16px; }

/* ───────── Уроки ───────── */
.lesson-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.lesson-list a {
  display: flex;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}
.lesson-list a:hover { background: var(--bg2); }
.lesson-list a.active { background: var(--accent-soft); }
.lesson-list small { display: block; color: var(--muted); font-size: 0.8rem; line-height: 1.3; }
.lesson-list .ln {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
}
.lesson-list a.done .ln { background: var(--good); border-color: var(--good); color: var(--card); }
.lesson { max-width: 820px; }
.lesson-kicker { color: var(--accent); font-weight: 700; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }
.lesson-body { font-size: 1.03rem; }
.lesson-body li { margin-bottom: 0.35em; }
.lesson-foot { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }
.go {
  font: inherit;
  font-weight: 600;
  padding: 6px 12px;
  margin: 2px 0;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}
.go:hover { background: var(--accent); color: var(--accent-text); }
.stroke-table { display: grid; gap: 10px; margin: 12px 0; }
.stroke-row { display: flex; gap: 12px; align-items: flex-start; }
.stroke-row .cell, .mini-grid .cell, .legend .cell {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  font-weight: 800;
  flex: none;
}
table.simple { border-collapse: collapse; margin: 10px 0; width: 100%; }
table.simple th, table.simple td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
table.simple th { background: var(--bg2); }
.mini-grid { display: grid; gap: 4px; margin: 14px 0; overflow-x: auto; }
.mg-row { display: grid; grid-template-columns: 90px repeat(8, 34px); gap: 4px; align-items: center; }
.mini-grid.six .mg-row { grid-template-columns: 110px repeat(6, 34px); }
.mg-row > span { font-weight: 600; font-size: 0.9rem; }
.mg-row > b, .mg-row > i { text-align: center; font-style: normal; }
.mg-row > i { color: var(--muted); }
.mg-row em { font-style: normal; height: 30px; border-radius: 7px; background: var(--bg2); display: grid; place-items: center; font-weight: 800; }
.mg-hands em { background: transparent; color: var(--muted); }
.bongo-svg { width: 100%; max-width: 380px; display: block; margin: 12px auto; }
.svg-wood { fill: #8b5a2b; }
.svg-rim { fill: #6b3f1d; }
.svg-skin { fill: #ecdcc0; }
.svg-zone { fill: none; stroke: var(--accent); stroke-width: 7; stroke-opacity: 0.45; }
.svg-label { font: 800 14px system-ui, sans-serif; text-anchor: middle; fill: #3b2410; }
.svg-sub { font: 11px system-ui, sans-serif; text-anchor: middle; fill: #6b4b2b; }
text.svg-sub[y="162"] { fill: var(--muted); }

/* ───────── Ритмы ───────── */
.rlist-top { display: grid; gap: 8px; margin-bottom: 8px; position: sticky; top: -16px; background: var(--card); padding: 4px 0 8px; z-index: 2; }
.rlist-top input { width: 100%; }
.rlist-btns { display: flex; gap: 6px; }
.rcat h3 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 14px 0 6px; }
.ritem {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.93rem;
}
.ritem:hover { background: var(--bg2); }
.ritem.active { background: var(--accent-soft); }
.ritem.done .rname { color: var(--good); }
.rmeta { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }

.player-head h1 { margin-bottom: 8px; }
.r-stage { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: 22px; align-items: start; margin-top: 14px; }
.r-wheelbox { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
#r-wheel { display: block; max-width: 100%; height: auto; aspect-ratio: 1; }
.r-cycle { font: 0.72rem ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted); text-align: center; }
.r-text .desc { margin-top: 0; }
.r-wheelhint { font-size: 0.82rem; color: var(--faint); border-left: 2px solid var(--line); padding-left: 8px; margin: 8px 0 0; max-width: 60ch; }
.desc { margin-top: 12px; font-size: 1.02rem; }
.tips { margin: 0 0 8px; padding-left: 20px; color: var(--muted); }
.speed-opts { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.speed-opts input { width: 56px; }
.speed-opts.dim { opacity: 0.45; }
.countin { font-weight: 800; color: var(--accent); min-width: 90px; }

.grid-wrap { overflow-x: auto; padding: 4px 0 10px; margin: 8px 0; -webkit-overflow-scrolling: touch; }
.rgrid {
  --cols: 8;
  display: grid;
  grid-template-columns: var(--lw) repeat(var(--cols), minmax(var(--cell), 1fr));
  gap: 3px;
  min-width: min-content;
}
.gl {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.88rem;
  padding-right: 6px;
  position: sticky;
  left: 0;
  background: var(--card);
  z-index: 1;
  min-width: 0;
}
.gl span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gl.gh { color: var(--muted); font-weight: 600; font-size: 0.8rem; }
.gc {
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  font-weight: 800;
  font-size: 0.95rem;
  background: var(--bg2);
  user-select: none;
  position: relative;
  transition: box-shadow 0.05s;
}
.gc.alt:not(.cell[class*="st-"]) { background: color-mix(in srgb, var(--bg2) 70%, var(--line)); }
.gc.gs { margin-left: 4px; }
.gc.bar { margin-left: 12px; }
.gc.gh { background: transparent; height: 24px; color: var(--muted); font-weight: 600; font-size: 0.8rem; }
.gc.gh.strong { color: var(--text); font-weight: 800; }
.gc.gh.alt { background: transparent; }
.gc.cell { cursor: pointer; }
.gc.muted { opacity: 0.25; }
.gc.hand { background: transparent; color: var(--muted); font-size: 0.85rem; height: 26px; }
.gc.hand.h-R { color: var(--accent); }
.gc.hand.h-B { color: var(--text); }
.gl.hands-l { color: var(--muted); font-weight: 600; }
.gc.now { box-shadow: 0 0 0 3px var(--accent) inset; }
.gc.gh.now { color: var(--accent); background: var(--now); }
.gc.cell.now[class*="st-"] { box-shadow: 0 0 0 3px var(--text) inset; transform: scale(1.08); }
.gc.cell.now:not([class*="st-"]) { background: var(--now); box-shadow: none; }
.gc.hand.now { box-shadow: none; background: var(--now); }
.lname {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
  padding: 4px 2px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lname .spk {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--accent);
}
.lname.off { opacity: 0.45; text-decoration: line-through; }
.lname.off .spk { background: var(--faint); }
.del { border: 0; background: none; color: var(--danger); cursor: pointer; font-size: 0.8rem; padding: 0 2px; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 0.88rem; color: var(--muted); }
.legend .lg { display: inline-flex; align-items: center; gap: 6px; }
.legend .cell { width: 22px; height: 22px; font-size: 0.75rem; border-radius: 5px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); align-items: center; }

.edit-panel { border: 1px dashed var(--accent); border-radius: 12px; padding: 12px; margin: 10px 0; background: var(--bg); }
.edit-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tool {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 2px solid transparent;
  font-weight: 800;
  cursor: pointer;
  font-size: 1rem;
}
.tool.sel { border-color: var(--text); transform: scale(1.1); }
.tool.eraser { background: var(--bg2); color: var(--text); }
.edit-form { display: flex; flex-wrap: wrap; gap: 10px 16px; margin: 10px 0; }
.edit-form label, label.full { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); }
label.full { display: grid; }

/* ───────── Полиритмы ───────── */
.poly-layout { display: grid; grid-template-columns: 1fr 360px; gap: 20px; align-items: start; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.poly-controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.ab { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.1rem; }
.ab select { font-size: 1.1rem; font-weight: 800; }
.ab .vs { color: var(--muted); font-weight: 600; font-size: 0.95rem; }
.voice-a > span, label.voice-a, .ca { color: var(--voice-a); }
.voice-b > span, label.voice-b, .cb { color: var(--voice-b); }
#p-canvas { width: 100%; display: block; margin: 8px 0; }
.explain p { margin-bottom: 0.6em; }
.resultant { font: 800 1.15rem ui-monospace, monospace; letter-spacing: 0.08em; background: var(--bg2); padding: 8px 12px; border-radius: 8px; }
.voice-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 8px 0; }
.voice-row label:first-child { display: flex; gap: 8px; align-items: center; font-weight: 700; }
.poly-side .btn { margin-top: 10px; }

/* ───────── Метроном ───────── */
.metro-layout { display: grid; grid-template-columns: 1fr 380px; gap: 20px; align-items: start; }
.metro-display {
  text-align: center;
  padding: 18px 10px;
  border-radius: 14px;
  background: var(--bg2);
  transition: background 0.3s;
}
.metro-display.silent { background: color-mix(in srgb, var(--st-M) 14%, var(--bg2)); }
.metro-display.flash { animation: flash 0.18s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 45%, var(--bg2)); } to { background: var(--bg2); } }
.metro-bpm b { font-size: 4.4rem; line-height: 1; font-variant-numeric: tabular-nums; }
.metro-bpm span { color: var(--muted); font-weight: 700; margin-left: 6px; }
.metro-tempo { color: var(--muted); margin-bottom: 16px; }
.metro-status { color: var(--muted); font-size: 0.9rem; margin-top: 14px; min-height: 1.4em; }
.beat-dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.beat-dot {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 3px solid var(--line);
  background: var(--card);
  color: var(--text);
  font: 800 1.05rem system-ui, sans-serif;
  cursor: pointer;
  position: relative;
  display: grid;
  place-items: center;
  transition: transform 0.06s, background 0.06s;
}
.beat-dot.lvl2 { border-color: var(--accent); }
.beat-dot.lvl0 { opacity: 0.35; border-style: dashed; }
.beat-dot.now { background: var(--accent); color: var(--accent-text); transform: scale(1.12); }
.beat-dot.lvl1.now { background: var(--text); color: var(--bg); }
.beat-dot .subs { position: absolute; bottom: -12px; left: 50%; transform: translateX(-50%); display: flex; gap: 3px; }
.beat-dot .subs em { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.beat-dot .subs em.now { background: var(--accent); }
.metro-main .controls { margin-top: 22px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-weight: 600; font-size: 0.9rem; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper b { font-size: 1.4rem; min-width: 30px; text-align: center; }
.trainer-box { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.trainer-box p { margin: 6px 0 0; }
.sub-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 6px; font-size: 0.92rem; }
.sub-opts input { width: 56px; }

/* ───────── Тренажёр ───────── */
.eyebrow {
  font: 600 0.68rem/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.eyebrow b { color: var(--text); }
.tbtn {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 11px;
  font: 600 0.82rem system-ui, sans-serif;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  touch-action: manipulation;
}
.tbtn:hover { border-color: var(--accent); color: var(--text); }
a.tbtn { text-decoration: none; }
.tbtn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.tbtn .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.tbtn .sw.st-O { background: var(--st-O); }
.tbtn .sw.st-S { background: var(--st-S); }
.tbtn .sw.st-M { background: var(--st-M); }
.tbtn .sw.st-T { background: var(--st-T); }

.tr { display: grid; gap: 14px; }
.tr-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; }
.tr-title { font-size: clamp(1.3rem, 3.4vw, 1.8rem); letter-spacing: -0.02em; margin: 2px 0 0; }
.tr-head .seg button { padding: 8px 14px; }

.tr-transport {
  position: sticky;
  top: 66px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px 16px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.tr-play {
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.tr-play:hover { filter: brightness(1.08); }
.tr-tempo { display: flex; align-items: center; gap: 12px; flex: 1 1 220px; min-width: 200px; }
.tr-tempo input { flex: 1; min-width: 80px; }
.tr-bpm { display: flex; flex-direction: column; line-height: 1; min-width: 3.4ch; text-align: right; }
.tr-bpm b { font: 700 1.35rem ui-monospace, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }
.tr-bpm span { font-size: 0.62rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.tr-tgroup { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tr-dots { display: flex; gap: 6px; margin-left: auto; }
.tr-dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--bg2); border: 1px solid var(--line); display: block; }
.tr-dots i.on { background: var(--accent); border-color: var(--accent); }
.tr-dots i.one.on { background: var(--st-S); border-color: var(--st-S); }

.tr-stage { display: grid; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: 22px; align-items: start; }
.tr-wheelbox { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#tr-wheel { display: block; max-width: 100%; height: auto; aspect-ratio: 1; touch-action: manipulation; }
.tr-cycle { font: 0.72rem ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted); text-align: center; }
.tr-side { display: grid; gap: 14px; align-content: start; min-width: 0; }
.tr-h2 { font-size: 1.3rem; letter-spacing: -0.01em; margin: 2px 0 4px; }
.tr-note { color: var(--muted); font-size: 0.93rem; margin: 0; max-width: 62ch; }
.tr-note a { font-weight: 600; }
.tr-fields { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 10px; }
.tr-fields label { display: grid; gap: 4px; }
.tr-fields label.wide { flex: 1 1 200px; }
.tr-fields select { width: 100%; }
.tr-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 0.8rem; color: var(--muted); }
.tr-legend span { display: inline-flex; align-items: center; gap: 6px; }
.tr-legend .dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.tr-legend .dot.hollow { border: 2px solid var(--accent); }
.tr-legend .dot.good { background: var(--good); }
.tr-legend .dot.warn { background: var(--bad); }
.tr-legend .dot.bad { background: var(--danger); }

.tr-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 8px; }
.tr-stat {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tr-stat b { font: 700 1.35rem ui-monospace, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }
.tr-stat span { font-size: 0.72rem; color: var(--muted); }
.tr-stat.good b { color: var(--good); }
.tr-stat.warn b { color: var(--bad); }
.tr-stat.bad b { color: var(--danger); }
.tr-advice { margin: 0; padding-left: 10px; border-left: 3px solid var(--accent); font-size: 0.93rem; min-height: 1.5em; }
.tr-calib { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }

.tr-pads { display: grid; gap: 6px; }
.tr-strokes { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.pad kbd { font-size: 0.7rem; padding: 0 4px; background: rgba(255, 255, 255, 0.5); color: #3b2410; }

.tr-ear { max-width: 720px; display: grid; gap: 12px; }
.ear-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.ear-opt {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 14px;
  text-align: left;
  font: 600 0.95rem system-ui, sans-serif;
  color: var(--text);
  cursor: pointer;
}
.ear-opt:hover:not(:disabled) { border-color: var(--accent); }
.ear-opt:disabled { cursor: default; opacity: 0.75; }
.ear-opt.right { background: var(--good); border-color: var(--good); color: var(--card); opacity: 1; }
.ear-opt.wrong { background: var(--danger); border-color: var(--danger); color: var(--card); opacity: 1; }
.ear-score { display: flex; flex-wrap: wrap; gap: 18px; font: 0.85rem ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted); }
.ear-score b { color: var(--text); font-size: 1.1rem; }
.pads { display: flex; justify-content: center; align-items: center; gap: 18px; flex-wrap: wrap; padding: 10px 0; }
.pad {
  border-radius: 50%;
  border: 10px solid #6b3f1d;
  background: radial-gradient(circle, #f3e6cf 0 55%, #e2cda8 100%);
  color: #3b2410;
  display: grid;
  place-content: center;
  text-align: center;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: var(--shadow);
  font: inherit;
}
.pad b { font-size: 1.2rem; }
.pad small { font-size: 0.75rem; opacity: 0.7; }
.pad-macho { width: 170px; height: 170px; }
.pad-hembra { width: 220px; height: 220px; }
.pad.hit { animation: padhit 0.15s ease-out; }
@keyframes padhit { from { transform: scale(0.94); filter: brightness(1.15); } to { transform: none; filter: none; } }

/* ───────── Металлофон ───────── */
:root {
  --n-c: #c8453b; --n-d: #d9812e; --n-e: #d4ae2d; --n-f: #5e9a4b;
  --n-g: #3a9c9c; --n-a: #3f6eae; --n-b: #7a5aa3; --n-sharp: #3b3531;
}
.nc-c { --nc: var(--n-c); } .nc-d { --nc: var(--n-d); } .nc-e { --nc: var(--n-e); } .nc-f { --nc: var(--n-f); }
.nc-g { --nc: var(--n-g); } .nc-a { --nc: var(--n-a); } .nc-b { --nc: var(--n-b); } .nc-sharp { --nc: var(--n-sharp); }

.ml { display: grid; gap: 14px; }
.ml-inst-card { padding: 14px 16px 12px; }
.ml-inst-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.ml-inst { position: relative; height: 200px; }
.ml-inst.chromatic { height: 270px; }
.ml-naturals { display: flex; align-items: center; gap: 4px; height: 100%; }
.ml-inst.chromatic .ml-naturals { position: absolute; left: 0; right: 0; bottom: 0; height: 60%; }
.ml-sharps { position: absolute; left: 0; right: 0; top: 0; height: 40%; }
.ml-sharps .ml-bar { position: absolute; top: 50%; transform: translateY(-50%); }
.ml-bar {
  flex: 1;
  min-width: 0;
  position: relative;
  border: 0;
  border-radius: 6px;
  padding: 0 0 8px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--nc) 78%, #fff) 0%, var(--nc) 45%, color-mix(in srgb, var(--nc) 80%, #000) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  font: 700 0.8rem system-ui, sans-serif;
  line-height: 1.1;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: filter 0.08s, transform 0.08s;
}
.ml-bar.nc-e { color: #3a2c05; }
.ml-bar small { font-size: 0.62rem; opacity: 0.8; }
/* заклёпки, на которых висит пластина */
.ml-bar::before, .ml-bar::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 6px;
  height: 6px;
  margin-left: -3px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.ml-bar::before { top: 9%; }
.ml-bar::after { bottom: 34%; }
.ml-bar.hit { filter: brightness(1.25); transform: translateY(1px) scale(0.98); }
.ml-sharps .ml-bar.hit { transform: translateY(-50%) scale(0.97); }
.ml-bar.lit { filter: brightness(1.3) saturate(1.2); box-shadow: 0 0 0 3px var(--card), 0 0 0 6px var(--accent), 0 0 18px var(--accent); z-index: 2; }
.ml-bar.next:not(.lit) { box-shadow: 0 0 0 3px var(--card), 0 0 0 6px var(--accent); animation: nextpulse 1s ease-in-out infinite; z-index: 1; }
.ml-bar.bad { box-shadow: 0 0 0 3px var(--card), 0 0 0 6px var(--danger); animation: shake 0.3s; }
@keyframes nextpulse { 50% { box-shadow: 0 0 0 3px var(--card), 0 0 0 6px transparent; } }
@keyframes shake { 25% { translate: -3px 0; } 75% { translate: 3px 0; } }
.ml-rotate { display: none; margin: 8px 0 0; }

.ml-player { display: grid; gap: 10px; }
.ml-top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px; }
.ml-pick { display: grid; gap: 4px; flex: 1 1 240px; }
.ml-pick select { width: 100%; font-weight: 600; }
.ml-modes { justify-self: start; }
.ml-ribbon-wrap { overflow-x: auto; margin: 0 -4px; padding: 8px 4px 4px; -webkit-overflow-scrolling: touch; }
.ml-ribbon { display: flex; align-items: flex-end; gap: 4px; min-width: max-content; }
.ml-chip {
  width: calc(var(--d) * 46px);
  min-width: 40px;
  height: 50px;
  flex: none;
  border: 0;
  border-radius: 8px;
  background: var(--nc);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font: 700 0.82rem system-ui, sans-serif;
  cursor: pointer;
  position: relative;
  transition: transform 0.1s, opacity 0.2s;
}
.ml-chip.nc-e { color: #3a2c05; }
.ml-chip small { font: 600 0.6rem ui-monospace, monospace; opacity: 0.75; }
.ml-chip sup { font-size: 0.6rem; }
.ml-chip.rest { background: var(--bg2); color: var(--muted); font-size: 1.1rem; }
.ml-chip.cur { transform: translateY(-5px); box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--text); }
.ml-chip.ok { opacity: 0.4; }
.ml-chip::after { content: ""; position: absolute; left: 6px; right: 6px; bottom: -6px; height: 3px; border-radius: 2px; }
.ml-chip.hit::after { background: var(--good); }
.ml-chip.off::after { background: var(--bad); }
.ml-chip.wrong::after, .ml-chip.miss::after, .ml-chip.bad::after { background: var(--danger); }
.ml-chip.bad { animation: shake 0.3s; }
.ml-barline { width: 2px; height: 56px; flex: none; background: var(--line); border-radius: 1px; margin: 0 2px; }
.ml-stats { display: flex; flex-wrap: wrap; gap: 6px 18px; font: 0.85rem ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted); min-height: 1.5em; align-items: baseline; }
.ml-stats b { color: var(--text); font-size: 1.05rem; }
.ml-stats .good b { color: var(--good); }
.ml-stats .warn b { color: var(--bad); }
.ml-stats .bad b { color: var(--danger); }
.ml-stats .muted { font-family: system-ui, sans-serif; }
.ml-rec { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
.btn.on-rec { background: var(--danger); border-color: var(--danger); color: var(--card); animation: recpulse 1.2s ease-in-out infinite; }
@keyframes recpulse { 50% { opacity: 0.75; } }
.ml-warn { margin: 0; padding: 8px 12px; border-radius: 8px; background: color-mix(in srgb, var(--bad) 16%, var(--card)); border-left: 3px solid var(--bad); font-size: 0.9rem; }
.ml-warn .tbtn { margin: 0 4px; }
.ml-err { color: var(--danger); font-size: 0.85rem; min-height: 1.2em; margin: 4px 0; }
#me-notes { font: 0.9rem ui-monospace, "SF Mono", Menlo, monospace; }
.ml-keys kbd { margin: 0 1px; }

/* ───────── Флейта ───────── */
.inst-switch a { display: inline-flex; align-items: center; padding: 7px 12px; font-weight: 600; font-size: 0.9rem; color: var(--text); text-decoration: none; }
.inst-switch a.sel { background: var(--accent); color: var(--accent-text); }
.fing { display: block; }
.fing .fb { fill: color-mix(in srgb, var(--st-O) 22%, var(--card)); stroke: var(--line); stroke-width: 1.5; }
.fing .fl { stroke: var(--line); stroke-width: 1.2; }
.fing .fl.sep { stroke-dasharray: 3 3; }
.fing .fh-c { fill: var(--text); }
.fing .fh-o { fill: var(--card); stroke: var(--text); stroke-width: 1.6; }
.fing .ft { font: 600 7px system-ui, sans-serif; fill: var(--muted); text-anchor: middle; }
.fing.big { width: 92px; }
.fing.small { width: 52px; opacity: 0.8; }
.fing.mini { width: 40px; margin: 4px auto 0; }
.fing.mid { width: 80px; }
.fing-none { font-size: 0.8rem; color: var(--muted); }
.fl-mic { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.fl-heard { font: 0.9rem ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted); }
.fl-heard b { color: var(--text); }
.fl-level { flex: 1 1 80px; max-width: 160px; height: 8px; border-radius: 4px; background: var(--bg2); overflow: hidden; }
.fl-level i { display: block; height: 100%; width: 0; background: var(--good); transition: width 0.08s; }
.fl-stage { display: flex; align-items: flex-end; justify-content: center; gap: 28px; padding: 6px 0; }
.fl-now, .fl-next { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.fl-now #fl-now-f { cursor: pointer; }
.fl-note { font: 800 1.6rem system-ui, sans-serif; line-height: 1.1; }
.fl-note.small { font-size: 1.05rem; color: var(--muted); }
.fl-note.big { font-size: 3rem; }
.fl-manual { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.fing-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; margin-top: 12px; }
.fing-card { border: 1px solid var(--line); border-radius: 10px; background: var(--bg2); padding: 6px 2px 8px; cursor: pointer; color: var(--text); font: inherit; }
.fing-card:hover { border-color: var(--accent); }
.fing-card b { display: inline-block; padding: 1px 6px; border-radius: 6px; background: var(--nc); color: #fff; font-size: 0.8rem; }
.fing-card b.nc-e { color: #3a2c05; }
.fl-tuner-row { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; justify-content: space-between; }
.fl-tuner-row > div:first-child { flex: 1 1 260px; display: grid; gap: 8px; }
.tn-meter { position: relative; height: 26px; border-radius: 13px; background: linear-gradient(90deg, var(--bad), var(--good-bg) 40%, var(--good-bg) 60%, var(--bad)); }
.tn-zero { position: absolute; left: 50%; top: 3px; bottom: 3px; width: 2px; background: var(--text); opacity: 0.35; }
.tn-needle { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 4px; margin-left: -2px; border-radius: 2px; background: var(--danger); transition: left 0.1s; }
.tn-needle.good { background: var(--good); }
.tn-labels { display: flex; justify-content: space-between; font: 0.8rem ui-monospace, monospace; color: var(--muted); }
.fl-tuner { margin-top: 14px; }

/* ───────── Касания ───────── */
button, a, input, select, label, summary { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.pad, .gc, .beat-dot { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.lib-toggle { display: none; }

/* ───────── Адаптивность ───────── */
@media (max-width: 560px) and (orientation: portrait) { .ml-rotate { display: block; } }
@media (max-width: 1100px) {
  .tabs a { padding: 6px 9px; font-size: 0.9rem; }
  .poly-layout, .metro-layout { grid-template-columns: 1fr; }
  .start-grid { grid-template-columns: 1fr; }
}
@media (max-width: 1000px) {
  .topbar { gap: 10px; }
  .tabs { gap: 2px; min-width: 0; }
  .tabs a { padding: 6px 7px; font-size: 0.85rem; }
  .volume input { width: 70px; }
}
@media (max-width: 900px) {
  .tabs, .volume { display: none; }
  .bottom-tabs { display: flex; }
  .topbar { padding: 10px 16px; }
  main { padding: 16px; }
  .two-col { grid-template-columns: 1fr; }
  .r-stage { grid-template-columns: 1fr; }
  .r-wheelbox { max-width: 300px; margin: 0 auto; width: 100%; }
  /* телефон: колесо → барабаны → статистика, чтобы видеть круг во время игры */
  #tr-play-sec { display: flex; flex-direction: column; gap: 14px; }
  .tr-stage { display: contents; }
  .tr-wheelbox, .tr-side {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
  }
  .tr-wheelbox { order: 1; }
  .tr-pads { order: 2; }
  .tr-side { order: 3; }
  .tr-transport { top: 58px; }
  .tr-dots { display: none; }
  /* списки ритмов и уроков сворачиваются в одну кнопку */
  .list-col { position: static; max-height: none; overflow: visible; padding: 0; }
  .lib-toggle {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px;
    border: 0;
    background: none;
    color: var(--text);
    font: 700 1rem system-ui, sans-serif;
    text-align: left;
    cursor: pointer;
  }
  .lib-toggle small { color: var(--muted); font-weight: 500; }
  .lib-toggle b { transition: transform 0.2s; color: var(--muted); }
  .list-col.open .lib-toggle b { transform: rotate(180deg); }
  .list-col:not(.open) > :not(.lib-toggle) { display: none; }
  .list-col.open > :not(.lib-toggle) { padding-left: 14px; padding-right: 14px; }
  .list-col.open { padding-bottom: 12px; }
  .list-col .list-title { display: none; }
  .rlist-top { position: static; }

  /* панель «Играть / темп» прилипает над нижним меню */
  .dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
    z-index: 19;
    flex-wrap: nowrap;
    gap: 8px;
    margin: 0;
    padding: 8px 16px;
    background: var(--card);
    border-top: 1px solid var(--line);
    box-shadow: 0 -6px 16px rgba(40, 30, 20, 0.1);
  }
  #page-rhythms, #page-poly, #page-mallet, #page-flute { padding-bottom: 72px; }
  .fing.big { width: 76px; }
  .fl-stage { gap: 18px; }
  /* в мелодиях инструмент прилипает к низу экрана — лента нот и пластины видны вместе */
  .ml.view-melody .ml-inst-card, .ml.view-free .ml-inst-card {
    position: sticky;
    bottom: calc(var(--tabs-h) + 64px + env(safe-area-inset-bottom));
    z-index: 5;
    box-shadow: 0 -6px 18px rgba(40, 30, 20, 0.12);
  }
  .ml.view-free .ml-inst-card, .ml.view-melody.mode-wait .ml-inst-card { bottom: calc(var(--tabs-h) + 6px + env(safe-area-inset-bottom)); }
  #ml-desc, #fl-desc { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
  #ml-desc.open, #fl-desc.open { display: block; }
  .ml-inst-head { margin-bottom: 8px; }
  .ml-inst-head .seg button { padding: 5px 9px; font-size: 0.78rem; }
  .dock .btn.play { min-width: 0; flex: none; padding: 11px 18px; }
  .dock .bpm-control { flex: 1; width: auto; flex-wrap: nowrap; justify-content: flex-end; }
  .dock .bpm-label, .dock .bpm-range, .dock .bpm-unit,
  .dock [data-d="-1"], .dock [data-d="1"] { display: none; }
  .dock .bpm-num { width: 64px !important; }
  .dock .bpm-control .btn.small { padding: 9px 12px; }

  /* поля: 16px, чтобы iPhone не увеличивал страницу при нажатии */
  input, select, textarea { font-size: 16px; }
  .speed-opts.dim { display: none; }
  .r-wheelhint { display: none; }
  .tbtn { min-height: 36px; }
  .mg-row { grid-template-columns: 62px repeat(8, minmax(0, 1fr)); gap: 3px; }
  .mini-grid.six .mg-row { grid-template-columns: 78px repeat(6, minmax(0, 1fr)); }
  .mg-row > span { font-size: 0.78rem; }
  .lesson-foot .btn { flex: 1 1 100%; }
  .lesson-foot .spacer { display: none; }
  .hero { flex-direction: column-reverse; align-items: flex-start; }
}
@media (max-width: 560px) {
  :root { --cell: 26px; --lw: 74px; }
  table.simple { font-size: 0.86rem; }
  table.simple th, table.simple td { padding: 5px 6px; }
  .ml-inst { height: 180px; }
  .ml-inst.chromatic { height: 240px; }
  .ml-naturals { gap: 2px; }
  .ml-bar { border-radius: 4px; padding-bottom: 6px; font-size: 0.66rem; }
  .ml-bar { justify-content: center; padding: 0; }
  .ml-bar span { writing-mode: vertical-rl; text-orientation: upright; letter-spacing: -0.14em; font-size: 0.62rem; }
  .ml-bar small { display: none; }
  .ml-bar::before, .ml-bar::after { width: 4px; height: 4px; margin-left: -2px; }
  .ml-bar::before { top: 5%; }
  .ml-bar::after { bottom: 5%; }
  .ml-inst-card { padding: 12px 8px 10px; }
  .ml-chip { width: calc(var(--d) * 40px); min-width: 36px; height: 46px; }
  main { padding: 12px; }
  .topbar { padding: 8px 14px; }
  .bottom-tabs a { font-size: 0.62rem; letter-spacing: -0.01em; }
  .bottom-tabs a { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .tr-transport { padding: 8px 10px; gap: 8px 10px; }
  .tr-play { width: 44px; height: 44px; }
  .controls { gap: 8px 12px; }
  h1 { font-size: 1.35rem; }
  .hero h1 { font-size: 1.5rem; }
  .card { padding: 14px; border-radius: 12px; }
  .gc { height: 32px; font-size: 0.85rem; }
  .bpm-range { width: 100%; order: 10; }
  .bpm-control { width: 100%; }
  .bpm-control [data-d="-1"], .bpm-control [data-d="1"], .bpm-unit { display: none; }
  .pad-macho { width: 130px; height: 130px; }
  .pad-hembra { width: 165px; height: 165px; }
  .tr-pads .pad-macho { width: 120px; height: 120px; border-width: 8px; }
  .tr-pads .pad-hembra { width: 150px; height: 150px; border-width: 8px; }
  .tr-strokes .tbtn { padding: 6px 9px; font-size: 0.76rem; }
  .beat-dot { width: 46px; height: 46px; }
  .metro-bpm b { font-size: 3.4rem; }
  .btn.play.big { min-width: 140px; }
  .progress-ring { width: 100px; height: 100px; }
  .progress-ring span { width: 76px; height: 76px; }
}

/* ───────── Клавиши ───────── */
.kb-midi { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 12px 16px; }
.kb-status { flex: 1 1 220px; color: var(--muted); font-size: 0.9rem; }
.kb-status.ok { color: var(--good); font-weight: 600; }
.kb-piano { position: relative; height: 190px; user-select: none; -webkit-user-select: none; touch-action: none; }
.kb-whites { display: flex; height: 100%; gap: 2px; }
.kb-key { font: inherit; cursor: pointer; padding: 0; -webkit-tap-highlight-color: transparent; transition: background 0.08s, transform 0.08s; }
.kb-key.white {
  flex: 1 1 0; min-width: 0; display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: 10px; border: 1px solid var(--line); border-radius: 0 0 8px 8px;
  background: linear-gradient(#fff, #f4f1ea); color: #5b5348; font-size: 0.72rem; font-weight: 600;
  box-shadow: inset 0 -5px 0 var(--nc, transparent), 0 2px 3px rgba(40, 30, 20, 0.12);
}
.kb-key.white sup { font-size: 0.6em; }
.kb-key.black {
  position: absolute; top: 0; height: 60%; z-index: 2; border: 1px solid #111; border-radius: 0 0 6px 6px;
  background: linear-gradient(#3a3632, #16140f); box-shadow: 0 3px 4px rgba(0, 0, 0, 0.35);
}
.kb-key.down { transform: translateY(2px); }
.kb-key.white.down { background: linear-gradient(#e9e4d8, #ddd6c6); }
.kb-key.black.down { background: linear-gradient(#57514a, #2c2924); }
.kb-key.next { outline: 3px solid var(--accent); outline-offset: -3px; animation: kbnext 1.1s ease-in-out infinite; }
.kb-key.white.next { background: linear-gradient(#fff, color-mix(in srgb, var(--accent) 22%, #fff)); }
.kb-key.black.next { background: linear-gradient(color-mix(in srgb, var(--accent) 70%, #333), #16140f); }
.kb-key.lit, .kb-key.white.lit { background: var(--accent); color: var(--accent-text); outline: none; animation: none; }
.kb-key.bad, .kb-key.white.bad { background: var(--danger); color: #fff; }
@keyframes kbnext { 50% { outline-color: transparent; } }
.kb-chordrow { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 8px; }
.kb-chip {
  font: inherit; font-weight: 700; min-width: 48px; padding: 8px 10px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg2); color: var(--text);
}
.kb-chip.cur { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.kb-chip.ok { box-shadow: inset 0 -3px 0 var(--good); }
.kb-bigchord { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 14px; margin: 6px 0 10px; }
.kb-bigchord b { font-size: 2.4rem; line-height: 1.1; color: var(--accent); }
.kb-bigchord span { color: var(--muted); }
@media (max-width: 900px) {
  #page-keys { padding-bottom: 72px; }
  .ml.view-chords .ml-inst-card {
    position: sticky; bottom: calc(var(--tabs-h) + 64px + env(safe-area-inset-bottom)); z-index: 5;
    box-shadow: 0 -6px 18px rgba(40, 30, 20, 0.12);
  }
  .ml.view-chords.mode-wait .ml-inst-card { bottom: calc(var(--tabs-h) + 6px + env(safe-area-inset-bottom)); }
  #kb-desc { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
  #kb-desc.open { display: block; }
  .kb-midi { padding: 10px 12px; font-size: 0.9rem; }
  .kb #kb-views, .kb .inst-switch { display: flex; width: 100%; }
  .kb #kb-views button, .kb .inst-switch a { flex: 1 1 0; justify-content: center; padding: 8px 4px; font-size: 0.84rem; }
  .kb-status { font-size: 0.82rem; }
}
@media (max-width: 560px) {
  .kb-piano { height: 150px; }
  .kb-whites { gap: 1px; }
  .kb-key.white { font-size: 0.56rem; padding-bottom: 7px; border-radius: 0 0 5px 5px; }
  .kb-key.white span { writing-mode: vertical-rl; text-orientation: upright; letter-spacing: -0.14em; }
  .kb-key.white sup { display: none; }
  .kb-bigchord b { font-size: 1.9rem; }
}
