:root {
  --bg: #fafaf9;
  --fg: #171717;
  --muted: #737373;
  --line: #e5e5e5;
  --card: #ffffff;
  --accent: #171717;
  --accent-fg: #ffffff;
  --danger: #b42318;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f0f;
    --fg: #ededed;
    --muted: #8f8f8f;
    --line: #2a2a2a;
    --card: #181818;
    --accent: #ededed;
    --accent-fg: #0f0f0f;
    --danger: #f97066;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.top, main, footer {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 16px;
}
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}
.brand {
  color: inherit;
  text-decoration: none;
  font-weight: 650;
  letter-spacing: -0.01em;
}
main { flex: 1; padding-bottom: 32px; }
footer {
  padding-top: 16px;
  padding-bottom: 24px;
  color: var(--muted);
  font-size: 13px;
}
footer a { color: inherit; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* кнопки */
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--card);
  height: 36px;
  padding: 0 12px;
  white-space: nowrap;
}
button:disabled { opacity: 0.4; cursor: default; }
button:focus-visible, .drop:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
button.ghost { background: transparent; }
button.ghost:hover:not(:disabled) { background: var(--card); }
button.icon, button.play {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}
button.play { border-radius: 50%; }

/* экран загрузки */
.upload { padding-top: 6vh; text-align: center; }
.modes {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  margin-bottom: 16px;
}
.modes input { position: absolute; opacity: 0; pointer-events: none; }
.modes span {
  display: block;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
}
.modes input:checked + span { background: var(--accent); color: var(--accent-fg); }
.modes input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 260px;
  padding: 24px 16px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  background: var(--card);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop strong { font-size: 20px; letter-spacing: -0.01em; }
.drop span { color: var(--muted); }
.drop .pick { text-decoration: underline; text-underline-offset: 3px; }
.drop:hover, .drop.over { border-color: var(--accent); }
kbd {
  font: inherit;
  font-size: 13px;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--fg);
}

/* распознавание и ошибка */
.busy, .fail { padding-top: 6vh; text-align: center; }
.busy img {
  display: block;
  max-width: 100%;
  max-height: 220px;
  margin: 0 auto 24px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}
.busy p { margin: 12px 0 0; }
#busyTime { color: var(--muted); font-variant-numeric: tabular-nums; }
.spinner {
  width: 26px;
  height: 26px;
  margin: 0 auto;
  border-radius: 50%;
  border: 2.5px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.fail p { color: var(--danger); margin: 0 0 16px; font-size: 16px; }

/* плеер */
.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 10px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.tempo { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.tempo input[type="number"] {
  width: 62px;
  height: 36px;
  padding: 0 6px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.tempo input[type="range"] { width: 130px; accent-color: var(--accent); }
.toggle { display: inline-flex; align-items: center; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle span {
  height: 36px;
  line-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--muted);
}
.toggle input:checked + span { color: var(--fg); border-color: var(--accent); background: var(--card); }
.toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.orig { margin-top: 12px; }
.orig summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.orig img {
  display: block;
  max-width: 100%;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

/* ноты всегда на белой «бумаге», даже в тёмной теме */
.paper {
  margin-top: 12px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: #000;
  overflow-x: auto;
}
.at-cursor-bar { background: rgba(255, 196, 0, 0.18); }
.at-cursor-beat { background: #e8590c; width: 3px; }
.at-selection div { background: rgba(64, 120, 255, 0.12); }
.at-highlight * { fill: #e8590c; stroke: #e8590c; }

@media (max-width: 640px) {
  .tempo input[type="range"] { width: 90px; }
  .grow { display: none; }
  .drop { min-height: 200px; }
  .drop strong { font-size: 18px; }
}
