:root {
  --bg: #0f0f10;
  --panel: #1b1b1d;
  --line: #2c2c30;
  --text: #ececec;
  --muted: #9a9aa2;
  --accent: #ff8af0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  /* на тач-экранах касания клавиш не должны выделять текст или открывать меню */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
button, select, summary, label { touch-action: manipulation; }

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 800; color: var(--accent); letter-spacing: .02em; }
.field { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.field span { min-width: 3.5em; color: var(--text); }
.spacer { flex: 1; }
.group { display: contents; }
.group[hidden], .field[hidden] { display: none; }

select, button, .settings summary {
  font: inherit;
  color: var(--text);
  background: #2a2a2e;
  border: 1px solid #3a3a40;
  border-radius: 8px;
  padding: 6px 10px;
}
button, .settings summary { cursor: pointer; }
button:hover, .settings summary:hover { background: #333338; }
button.primary { background: var(--accent); color: #2a0b25; border-color: transparent; font-weight: 700; }
button.on { background: #1d3a29; border-color: #2f7a4a; color: #9ff0bd; }
input[type=range] { accent-color: var(--accent); }

.settings { position: relative; }
.settings summary { list-style: none; }
.settings summary::-webkit-details-marker { display: none; }
.settings .menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 10;
  width: 320px;
  display: grid;
  gap: 8px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.hint { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.7; }
kbd { font: 12px ui-monospace, monospace; color: var(--text); }

main { position: relative; flex: 1; min-height: 0; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 10, 12, .6);
  backdrop-filter: blur(2px);
}
.overlay[hidden] { display: none; }
.card {
  max-width: 520px;
  margin: 16px;
  padding: 24px 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.card h2 { margin: 0 0 10px; }
.card p, .card li { color: var(--muted); }
.card ul { padding-left: 20px; margin: 8px 0; }
.card .actions { display: flex; gap: 10px; margin-top: 18px; }
.card .big { font-size: 34px; font-weight: 800; color: var(--accent); }

.mic-panel {
  position: absolute;
  left: 12px;
  top: 16px;
  width: 250px;
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  font-size: 13px;
  background: rgba(27, 27, 29, .92);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.mic-panel[hidden] { display: none; }
.row { display: flex; align-items: center; gap: 8px; }
.row span { width: 78px; color: var(--muted); }
.row input { flex: 1; }
.meter { position: relative; flex: 1; height: 8px; background: #2a2a2e; border-radius: 4px; overflow: hidden; }
#level { height: 100%; width: 0; background: linear-gradient(90deg, #3ad07a, #f3d14b 70%, #ff5a5a); }
#gateMark { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; }

/* Плавающая кнопка старт/пауза — только в компактном режиме */
.fab {
  display: none;
  position: absolute;
  left: 10px;
  top: 12px;
  z-index: 5;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 15px;
  color: #fff;
  background: rgba(0, 0, 0, .35);
  border: 1px solid rgba(255, 255, 255, .25);
  opacity: .55;
  -webkit-tap-highlight-color: transparent;
}
.fab:hover, .fab:active { opacity: 1; background: rgba(0, 0, 0, .55); }

/* Компактный режим: телефон в горизонтальной ориентации */
body.compact main {
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
body.compact .fab { display: block; left: calc(10px + env(safe-area-inset-left)); }
body.compact.playing .bar { display: none; }
body.compact .bar { padding: 6px 10px; gap: 6px 10px; }
body.compact .brand { display: none; }
body.compact .mic-panel { left: 64px; top: 10px; }
body.compact .card { max-height: calc(100% - 24px); overflow: auto; padding: 16px 20px; }

/* Окна входа и библиотеки */
.dialog {
  width: min(420px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 20px 22px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
  -webkit-user-select: text;
  user-select: text;
}
.dialog.wide { width: min(720px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog h2 { margin: 0; font-size: 20px; }
.dialog h3 { margin: 18px 0 8px; font-size: 15px; color: var(--muted); font-weight: 600; }
.dialog-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.dialog-head h2 { flex: 1; }
.account-line { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; min-width: 0; }
.account-line span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
button.icon { padding: 4px 8px; background: transparent; border-color: transparent; }
button.icon:hover { background: #333338; }
button.fav { color: #ffd65c; }
button:disabled { opacity: .5; cursor: default; }

.auth { display: grid; gap: 12px; }
.auth label { display: grid; gap: 6px; color: var(--muted); }
.auth input {
  font: inherit;
  font-size: 16px; /* меньше 16px — iOS зумит страницу при фокусе */
  color: var(--text);
  background: #111113;
  border: 1px solid #3a3a40;
  border-radius: 8px;
  padding: 9px 10px;
}
.auth input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-message { min-height: 1.4em; margin: 0; color: #ff9a9a; }
.dialog .actions { display: flex; gap: 10px; flex-wrap: wrap; }

table.lib { width: 100%; border-collapse: collapse; font-size: 14px; }
table.lib th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 4px 6px; }
table.lib td { padding: 6px; border-top: 1px solid var(--line); vertical-align: middle; }
table.lib td.title { width: 100%; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions button { padding: 4px 8px; }
.card a { color: var(--accent); }
@media (max-width: 560px) {
  table.lib th:nth-child(5), table.lib td:nth-child(5) { display: none; }
}

.settings .menu.narrow { width: 240px; }
.account-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Импорт MIDI */
.upload-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 6px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 14px 0 4px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.check input { margin-top: 3px; }
.check b { color: var(--text); font-weight: 600; }
#importTracks select { font-size: 13px; padding: 4px 6px; }
#importDialog .auth { margin-bottom: 6px; }
.version-choice { border: 1px solid var(--line); border-radius: 10px; padding: 4px 12px 10px; margin: 14px 0 4px; }
.version-choice[hidden] { display: none; }
.version-choice legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
.version-choice .check { margin: 8px 0 0; }
.badge { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 6px; font-size: 11px; color: #c9d6ff; background: #26304a; vertical-align: 1px; }
.legend { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 8px 0 0; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; }
.swatch.right { background: #ff8af0; }
.swatch.left { background: #a9cf5e; margin-left: 8px; }
