:root {
  --bg: #15181e;
  --board-bg: #1c2027;
  --pressed: #232a35;
  --line: #3a4250;
  --string: #8a93a5;
  --text: #e8ebf0;
  --dim: #5d6675;
  --accent: #e8a33d;
  --note-text: #ffffff;
  --c-root: #e8a33d;
  --c-third: #3fae6a;
  --c-fifth: #3f8cff;
  --c-seventh: #a06ce8;
  --c-tension: #49536a;
  --header-h: 182px;
  /* ~11 рядов на экран под шапкой */
  --fret-h: clamp(38px, calc((100dvh - var(--header-h) - 16px) / 11.3), 64px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* ── Шапка ───────────────────────────────────── */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 520px;
  margin: 0 auto;
}

.carousel {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--board-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 2px;
}

.car-btn {
  flex: 0 0 44px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--accent);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.car-btn:active { background: var(--pressed); }

.car-label {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  user-select: none;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px;
}

.status {
  flex: 1;
  text-align: center;
  font-size: 14px;
  color: var(--dim);
  min-height: 18px;
  /* центрируем относительно всей строки, кнопка языка не сдвигает текст */
  margin-left: 38px;
}
.status b { color: var(--accent); font-size: 15px; }

.lang-btn {
  flex: 0 0 38px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--board-bg);
  color: var(--dim);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  touch-action: manipulation;
}
.lang-btn:active { color: var(--text); }

.legend {
  display: flex;
  justify-content: center;
  gap: 12px;
  font-size: 11px;
  color: var(--dim);
  user-select: none;
}

.leg-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.leg-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}
.leg-dot.g-root    { background: var(--c-root); }
.leg-dot.g-third   { background: var(--c-third); }
.leg-dot.g-fifth   { background: var(--c-fifth); }
.leg-dot.g-seventh { background: var(--c-seventh); }
.leg-dot.g-tension { background: var(--c-tension); }

/* ── Гриф ────────────────────────────────────── */

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 12px 24px;
}

.board {
  background: var(--board-bg);
  border-radius: 14px;
  overflow: hidden;
  margin-top: 8px;
}

.fret-row {
  display: grid;
  grid-template-columns: 40px repeat(var(--strings), 1fr);
  height: var(--fret-h);
  border-bottom: 1px solid var(--line);
}

.fret-row.open {
  border-bottom: 4px solid var(--string); /* порожек */
  height: calc(var(--fret-h) * 0.85);
}

.fret-num {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--dim);
  user-select: none;
  gap: 3px;
}
.fret-row.marker .fret-num { color: var(--text); font-weight: 700; }
.fret-num .dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--dim);
}

.cell {
  position: relative;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

/* струна — вертикальная линия сквозь ячейку */
.cell::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: var(--string-w, 2px);
  transform: translateX(-50%);
  background: var(--string);
  opacity: 0.55;
}
.fret-row.open .cell::before { display: none; }

.note {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(calc(var(--fret-h) * 0.8), 46px);
  height: min(calc(var(--fret-h) * 0.8), 46px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  color: var(--dim);
  pointer-events: none;
  background: var(--board-bg); /* прячет струну под текстом ноты */
}

.cell.in-scale .note {
  color: var(--note-text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  gap: 2px;
}

.cell.g-root .note {
  background: var(--c-root);
  color: #1a1206;
}
.cell.g-third .note   { background: var(--c-third); }
.cell.g-fifth .note   { background: var(--c-fifth); }
.cell.g-seventh .note { background: var(--c-seventh); }

/* проходящие ступени приглушены, чтобы арпеджио выступало вперёд */
.cell.g-tension .note {
  background: var(--c-tension);
  color: #c6cdda;
}

.note .deg { font-size: 15px; }

.note .sub {
  font-size: 9px;
  font-weight: 500;
  opacity: 0.8;
}

.cell.g-root .note .deg { font-weight: 800; }
.cell.g-root .note .sub { opacity: 0.7; }

/* нажатая тоника — кольцо, остальные «1» просто оранжевые */
.cell.tonic .note {
  box-shadow: 0 0 0 2.5px var(--text), 0 1px 4px rgba(0, 0, 0, 0.4);
}

@media (min-width: 600px) {
  .car-label { font-size: 17px; }
}
