*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f5f4f0;
  --surface:   #ffffff;
  --text:      #18181b;
  --muted:     #71717a;
  --border:    #e4e4e7;
  --hover:     #efeeea;
  --accent:    #18181b;
  --accent-fg: #ffffff;
  --orange:    #FF8904;
  --r:         8px;
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  display: flex;
  justify-content: center;
  min-height: 100dvh;
  min-height: 100vh;
}

#app {
  width: 100%;
  max-width: 420px;
  height: 100dvh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

/* ── Header ── */
#header {
  flex-shrink: 0;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

#header h1 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.header-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 7px;
  color: var(--muted);
  display: flex;
  align-items: center;
  border-radius: 50%;
  transition: background .12s, color .12s;
}
.header-btn:hover { background: var(--hover); color: var(--text); }
.header-btn.active { color: var(--accent); }

/* ── Tooltips ── */
/* Добавьте data-tooltip="текст" к любому элементу — подсказка появится снизу при наведении. */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(24,24,27,.88);
  color: #fff;
  font-size: 11px;
  font-family: var(--font);
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  z-index: 300;
}
[data-tooltip]:hover::after { opacity: 1; }
/* Крайняя правая кнопка — прижимаем тултип к правому краю кнопки, чтобы не выходил за экран */
#settingsBtn::after { left: auto; right: 0; transform: none; }

/* ── Notes navigation ── */
/* Список нот теперь находится ПОД флейтой и НАД нотным станом/клавишами.
   border-top отделяет его от SVG флейты, border-bottom — от bottomPanel.   */
#notesNav {
  flex-shrink: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
}
#notesNav::-webkit-scrollbar { display: none; }

#notesList {
  display: flex;
  gap: 2px;
  list-style: none;
}

.note-item { flex-shrink: 0; }

/* ── Размер кнопок нот ────────────────────────────────────────────────────────
   min-width определяет сколько нот видно без скролла.
   При ширине контейнера 420px (8px padding с каждой стороны = 404px рабочих):
     min-width: 48px → ~8 нот (8×48 + 7×2 = 398 px)
     min-width: 38px → ~10 нот (10×38 + 9×2 = 398 px)
   Нотный стан синхронизируется автоматически через getNoteButtonCenters().
   ─────────────────────────────────────────────────────────────────────────── */
.note-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 10px;
  min-width: 48px;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background .1s;
  font-family: var(--font);
}
.note-btn:hover  { background: var(--hover); }
.note-btn.active { background: var(--accent); }

.note-btn .note-primary {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
  white-space: nowrap;
}
.note-btn .note-secondary {
  font-size: 10px;
  color: var(--muted);
  line-height: 1;
  white-space: nowrap;
}
.note-btn.active .note-primary  { color: var(--accent-fg); }
.note-btn.active .note-secondary { color: rgba(255,255,255,.6); }

/* Hide secondary (EN) label when interface language is already English */
.lang-en .note-secondary { display: none; }

/* ── Fingering section ── */
#fingeringSection {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 4px 0;
  overflow: hidden;
}

#fingeringSvg {
  height: 100%;
  width: auto;
  display: block;
}

/* ── Bottom panel (staff / piano) ── */
#bottomPanel {
  flex-shrink: 0;
  background: var(--surface);
}

/* height совпадает с STAFF_H в app.js и с height #pianoContainer —
   чтобы bottomPanel не менял высоту при переключении режима отображения. */
#staffContainer {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  height: 90px;
}
#staffContainer::-webkit-scrollbar { display: none; }
#staffContainer svg { display: block; }

#pianoContainer {
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  overflow: hidden;
}
#pianoContainer svg { display: block; }

/* ── Settings modal (bottom sheet) ── */
#settingsModal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}
#settingsModal[hidden] { display: none; }

#settingsOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.38);
}

#settingsPanel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 20px 20px 36px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-height: 85vh;
  overflow-y: auto;
}

.s-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.s-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

#settingsClose {
  background: var(--hover);
  border: none;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--muted);
  transition: background .1s;
}
#settingsClose:hover { background: var(--border); color: var(--text); }

.s-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: opacity .2s;
}

/* Неактивное состояние: блок затухает и не реагирует на клики.
   Применяется к «Тоника» и «Тип гаммы» когда «Только ноты гаммы» выключен. */
.s-group--disabled {
  opacity: 0.35;
  pointer-events: none;
}

.s-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Segmented control */
.segmented {
  display: flex;
  background: var(--bg);
  border-radius: var(--r);
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  flex: 1;
  padding: 7px 10px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  transition: background .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
}
.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}

/* Pill row */
.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pill-btn {
  padding: 6px 14px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: background .1s, color .1s, border-color .1s;
}
.pill-btn.active {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

/* Settings divider */
.s-divider {
  height: 1px;
  background: var(--border);
  margin: 0 -4px;
}

/* Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.toggle-row span {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

/* custom toggle switch */
.toggle-row input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: var(--border);
  cursor: pointer;
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}
.toggle-row input[type="checkbox"]::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  top: 3px;
  left: 3px;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-row input[type="checkbox"]:checked {
  background: var(--accent);
}
.toggle-row input[type="checkbox"]:checked::after {
  transform: translateX(18px);
}

/* ── Landscape orientation ── */
/* max-width in landscape is set dynamically by JS (applySvgOrientationTransform)
   to match the visual width of the rotated flute image. */

.landscape #header {
  height: 40px;
}

/* fingeringSection: fixed height so the rotated SVG doesn't push other elements */
.landscape #fingeringSection {
  flex: none;
  height: 180px;
  overflow: visible;
}

/* SVG transform is applied by JS (applySvgOrientationTransform) */

/* In landscape the list uses 16 equal slots across the app width.
   Short scale lists are spread across the whole row; longer lists keep horizontal scrolling.
   Staff note positions are still derived from actual .note-btn centers in app.js. */
.landscape #notesList {
  min-width: 100%;
  justify-content: space-between;
}

.landscape .note-item {
  flex: 0 0 calc((100% - 30px) / 16);
}

.landscape .note-btn {
  width: 100%;
  min-width: 0;
  padding: 4px 2px;
}

.landscape .note-btn .note-primary {
  font-size: 13px;
}

.landscape .note-secondary {
  display: block;
  font-size: 10px;
}

.landscape.lang-en .note-secondary { display: none; }
