:root {
  color-scheme: light dark;
  --bg: #f6f7f4;
  --text: #17201b;
  --muted: #69756f;
  --panel: #ffffff;
  --line: #dce3dd;
  --accent: #0b7f6a;
  --accent-strong: #075d4d;
  --soft: #eef4f1;
}

* {
  box-sizing: border-box;
}

.tabs,
.tabs *,
.tab,
.tool-card,
.tool-card *,
button,
.wheel-picker,
.wheel-picker * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-drag: none;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--tg-theme-bg-color, var(--bg));
  color: var(--tg-theme-text-color, var(--text));
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 14px;
}

.topbar {
  display: grid;
  gap: 3px;
  padding: 6px 0 10px;
}

.eyebrow {
  margin: 0;
  color: var(--tg-theme-hint-color, var(--muted));
  font-size: 13px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 14px;
  font-size: 20px;
  line-height: 1.2;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.tab,
button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tg-theme-secondary-bg-color, var(--panel));
  color: var(--tg-theme-text-color, var(--text));
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}

.tab.active {
  border-color: var(--accent);
  background: var(--soft);
  color: var(--accent-strong);
}

.panel,
.result {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tg-theme-secondary-bg-color, var(--panel));
  padding: 14px;
}

.result {
  margin-top: 12px;
}

form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span {
  color: var(--tg-theme-hint-color, var(--muted));
  font-size: 13px;
}

select,
input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--tg-theme-bg-color, #ffffff);
  color: var(--tg-theme-text-color, var(--text));
  font: inherit;
}

form button {
  grid-column: 1 / -1;
  border: 0;
  background: var(--tg-theme-button-color, var(--accent));
  color: var(--tg-theme-button-text-color, #ffffff);
}

form button:active {
  background: var(--accent-strong);
}

.result p {
  margin: 0 0 12px;
  line-height: 1.45;
}

.result p:last-child {
  margin-bottom: 0;
}

.result img {
  display: block;
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-drag: none;
  touch-action: pan-y;
  pointer-events: auto;
}

.empty {
  color: var(--tg-theme-hint-color, var(--muted));
}

.code {
  color: var(--tg-theme-hint-color, var(--muted));
  font-size: 12px;
}

.auth-panel {
  display: grid;
  gap: 14px;
}

.auth-panel h2 {
  margin-bottom: 0;
}

.auth-form {
  grid-template-columns: 1fr;
}

#vkLoginContainer {
  min-height: 44px;
}

.auth-form button,
.auth-panel > button {
  border: 0;
  background: var(--accent);
  color: #ffffff;
}

.admin-app {
  width: min(1040px, 100%);
}

.admin-panel {
  display: grid;
  gap: 14px;
}

.admin-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(260px, 1.2fr) auto;
  gap: 10px;
  align-items: end;
}

.admin-all-form {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
  gap: 10px;
}

.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px;
  text-align: left;
  vertical-align: middle;
}

.admin-table th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.admin-table tr:last-child td {
  border-bottom: 0;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.admin-actions button,
.admin-toolbar > button,
.admin-all-form button {
  min-height: 36px;
  padding: 0 10px;
}

@media (min-width: 680px) {
  .tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 460px) {
  .app {
    padding: 12px;
  }

  h1 {
    font-size: 23px;
  }

  form {
    grid-template-columns: 1fr;
  }

  .admin-toolbar,
  .admin-all-form {
    grid-template-columns: 1fr;
  }
}

.picker-label {
  display: block;
}

.wheel-picker {
  height: 68px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  background: linear-gradient(180deg, rgba(246, 247, 244, 0.55), rgba(255, 255, 255, 0.15));
  border: 1px solid rgba(11, 127, 106, 0.08);
  border-radius: 8px;
  padding: 22px 0;
  scrollbar-width: none;
  overflow-x: hidden;
  overflow-y: auto;
  touch-action: pan-y;
}

.wheel-picker::-webkit-scrollbar {
  display: none;
}

.wheel-item {
  height: 22px;
  line-height: 22px;
  text-align: center;
  font-size: 15.5px;
  opacity: 0.34;
  transition: transform 0.16s ease, opacity 0.16s ease, color 0.16s ease;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  z-index: 1;
}

.wheel-item.selected {
  opacity: 1;
  color: var(--accent-strong);
  transform: scale(1.08);
  font-weight: 700;
}

.wheel-picker.dragging .wheel-item.selected {
  opacity: 0.34;
  color: inherit;
  transform: none;
  font-weight: inherit;
}

.compact-picker {
  display: block;
}

.picker-button {
  width: 100%;
  min-height: 56px;
  border-radius: 14px;
  border: 1px solid rgba(80, 110, 100, 0.25);
  background: #fff;
  font-size: 22px;
  font-weight: 700;
}

.picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 9999;
  display: flex;
  align-items: flex-end;
}

.picker-sheet {
  width: 100%;
  background: #fff;
  border-radius: 24px 24px 0 0;
  padding: 18px 24px 28px;
}

.picker-wheel {
  height: 210px;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  padding: 84px 0;
  scrollbar-width: none;
}

.picker-wheel::-webkit-scrollbar {
  display: none;
}

.picker-wheel-item {
  height: 42px;
  line-height: 42px;
  text-align: center;
  font-size: 11px;
  opacity: 0.35;
  scroll-snap-align: center;
}

.picker-wheel-item.selected {
  opacity: 1;
  font-weight: 800;
  transform: scale(1.12);
}

.picker-done {
  width: 100%;
  height: 52px;
  border: none;
  border-radius: 14px;
  background: #11866f;
  color: white;
  font-size: 20px;
  font-weight: 600;
}

.picker-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: start;
}

.wheel-picker::after {
    content: "";
    position: absolute;
    left: 8px;
    right: 8px;
    top: 50%;
    height: 30px;
    transform: translateY(-50%);
    background: rgba(11, 127, 106, 0.06);
    border-top: 1px solid rgba(11, 127, 106, 0.16);
    border-bottom: 1px solid rgba(11, 127, 106, 0.16);
    border-radius: 8px;
    pointer-events: none;
    z-index: 0;
}

.wheel-picker::before {
    content:"";
    position:absolute;
    left:0;
    right:0;
    top:0;
    height:24px;
    background:linear-gradient(
        to bottom,
        var(--panel),
        transparent
    );
    pointer-events:none;
    z-index:2;
}

.wheel-picker .wheel-item:first-child {
  margin-top: 0;
}

.tool-card {
  display: grid;
  gap: 16px;
}

.tool-main {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 10px 0;
}

.tool-controls,
.metro-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metro-controls {
  grid-template-columns: 52px 1fr 1fr 52px;
}

.metro-settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.tool-controls button,
.metro-controls button {
  min-width: 0;
}

.tool-value {
  font-size: 44px;
  font-weight: 800;
  line-height: 1;
}

.tool-caption {
  margin: 0;
  color: var(--tg-theme-hint-color, var(--muted));
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}

.tool-volume {
  display: grid;
  gap: 8px;
  margin: 4px 0;
}

.tool-volume span {
  color: var(--tg-theme-hint-color, var(--muted));
  font-size: 14px;
  opacity: 0.72;
}

.tool-volume input[type="range"],
.metro-range {
  width: 100%;
  accent-color: #11866f;
}

.tuner-note {
  font-size: 64px;
  font-weight: 850;
  line-height: 1;
}

.tuner-frequency {
  color: var(--tg-theme-hint-color, var(--muted));
  font-size: 18px;
}

.tuner-cents {
  font-size: 15px;
  font-weight: 650;
}

.tuner-arc {
  position: relative;
  height: 72px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--tg-theme-bg-color, var(--soft));
}

.tuner-scale {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 50%;
  height: 2px;
  background: linear-gradient(90deg, #c66 0%, var(--accent) 50%, #c66 100%);
  opacity: 0.55;
}

.tuner-center-line {
  position: absolute;
  left: 50%;
  top: 12px;
  bottom: 12px;
  width: 2px;
  background: var(--accent);
  transform: translateX(-50%);
}

.tuner-needle {
  position: absolute;
  left: 50%;
  top: 16px;
  width: 14px;
  height: 42px;
  border-radius: 999px;
  background: var(--accent-strong);
  transform: translateX(0);
  transition: transform 0.08s linear;
  margin-left: -7px;
}

.tuner-status {
  justify-self: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--tg-theme-hint-color, var(--muted));
  font-weight: 700;
}

.tuner-status.is-tuned {
  border-color: var(--accent);
  background: var(--soft);
  color: var(--accent-strong);
}

.tuner-status.is-low,
.tuner-status.is-high {
  border-color: rgba(180, 120, 40, 0.35);
  background: rgba(180, 120, 40, 0.08);
  color: #8a5d1f;
}

.dictation-tool {
  gap: 12px;
}

.dictation-canvas {
  display: block;
  width: 100%;
  height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  touch-action: pan-y;
}

.dictation-speed {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.dictation-speed-button {
  min-height: 38px;
  font-size: 13px;
}

.dictation-speed-button.active {
  border-color: var(--accent);
  background: var(--soft);
  color: var(--accent-strong);
}

.dictation-status {
  justify-self: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--tg-theme-hint-color, var(--muted));
  font-weight: 700;
}

.dictation-tool .tool-controls {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metro-bpm {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  padding-top: 4px;
}

.metro-bpm span:first-child {
  font-size: 58px;
  font-weight: 850;
  line-height: 1;
}

.metro-bpm span:last-child {
  color: var(--tg-theme-hint-color, var(--muted));
  font-size: 15px;
  font-weight: 800;
}

.metro-range {
  padding: 0;
  accent-color: var(--accent);
}

.beat-dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  min-height: 28px;
  padding: 2px 0 6px;
}

.beat-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--line);
  transition: transform 0.12s ease, background 0.12s ease;
}

.beat-dot.strong {
  width: 19px;
  height: 19px;
}

.beat-dot.active {
  background: var(--accent);
  transform: scale(1.35);
}

.piano-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}

.piano-tool,
.piano-tool *,
.piano-keyboard,
.piano-white-key,
.piano-black-key {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-drag: none;
}

.piano-keyboard {
  position: relative;
  height: 180px;
  min-width: 420px;
}

.piano-white-key,
.piano-black-key {
  font: inherit;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.piano-white-key {
  position: relative;
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  width: 48px;
  height: 170px;
  min-height: 0;
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 0 0 10px 10px;
  background: #fff;
  color: #17201b;
  font-size: 0;
  padding: 0;
}

.piano-white-key.active {
  background: #d8f3ec;
}

.piano-black-key {
  position: absolute;
  top: 0;
  width: 30px;
  height: 105px;
  min-height: 0;
  border: 0;
  border-radius: 0 0 8px 8px;
  background: #111;
  color: #fff;
  z-index: 2;
}

.piano-black-key.active {
  background: #11866f;
}

@media (max-width: 460px) {
  .metro-controls {
    grid-template-columns: 44px 1fr 1fr 44px;
  }

  .tuner-note {
    font-size: 56px;
  }
}
