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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --accent: #e94560;
  --accent2: #53c0f0;
  --text: #e0e0e0;
  --text-dim: #888;
  --degree-cell-h: 26px;
  --nondeg-cell-h: 12px;
  --ladder-w: 160px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#app-header {
  background: var(--surface2);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

#app-header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--accent2);
}

#mobile-tabs {
  display: none;
  background: #111a31;
  border-bottom: 1px solid #333;
  padding: 6px;
  gap: 6px;
  flex-shrink: 0;
  min-width: 0;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

.mobile-tab {
  min-width: 0;
  min-height: 34px;
  background: var(--bg);
  color: #c8d7e5;
  border: 1px solid #39475f;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  padding: 0 4px;
  touch-action: manipulation;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mobile-tab.active {
  background: var(--surface2);
  border-color: var(--accent2);
  color: var(--accent2);
}

.app-version {
  color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-btn {
  background: rgba(83, 192, 240, 0.08);
  color: var(--accent2);
  border: 1px solid rgba(83, 192, 240, 0.42);
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
  text-decoration: none;
  touch-action: manipulation;
}
.desktop-practice-toggle.active {
  border-color: var(--accent2);
  background: var(--surface2);
  color: var(--accent2);
}
.header-btn:hover { background: rgba(83, 192, 240, 0.16); }

button,
select,
input {
  touch-action: manipulation;
}

#app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Controls sidebar ────────────────────────────────────────── */
#controls-panel {
  width: 200px;
  background: var(--surface);
  border-right: 1px solid #333;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  flex-shrink: 0;
}

#controls-panel h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.control-group { display: flex; flex-direction: column; gap: 6px; }

.preset-btn {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #444;
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  text-align: left;
  font-size: 12px;
}
.preset-btn:hover { border-color: var(--accent2); }
.preset-btn.active { border-color: var(--accent2); background: var(--surface2); color: var(--accent2); }

label { font-size: 12px; color: var(--text-dim); }

.reference-ni-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.reference-ni-readout {
  flex: 1;
  min-width: 0;
}

.reference-note-display {
  display: block;
  color: var(--accent2);
  font-size: 12px;
  line-height: 1.25;
}

.reference-snap-buttons {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reference-snap-btn {
  width: 28px;
  height: 20px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid #444;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}
.reference-snap-btn:hover { border-color: var(--accent2); color: var(--accent2); }

input[type="range"] { width: 100%; accent-color: var(--accent2); }
input[type="number"] {
  background: var(--bg);
  border: 1px solid #444;
  border-radius: 3px;
  color: var(--text);
  padding: 2px 6px;
  width: 100%;
  font-size: 12px;
}
select {
  background: var(--bg);
  border: 1px solid #444;
  border-radius: 4px;
  color: var(--text);
  padding: 4px 6px;
  font-size: 12px;
  width: 100%;
}

#reset-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 12px;
}
#reset-btn:hover { opacity: 0.85; }

/* ── Exercise mode ───────────────────────────────────────────── */
.exercise-panel select {
  border-color: rgba(83, 192, 240, 0.35);
}
.exercise-setup-summary {
  color: #c8d7e5;
  font-size: 11px;
  line-height: 1.35;
  padding: 7px 8px;
  background: rgba(83, 192, 240, 0.07);
  border: 1px solid rgba(83, 192, 240, 0.18);
  border-radius: 6px;
}
.exercise-card {
  background:
    linear-gradient(145deg, rgba(83, 192, 240, 0.11), rgba(15, 52, 96, 0.12)),
    var(--bg);
  border: 1px solid rgba(83, 192, 240, 0.28);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.exercise-target-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.exercise-target {
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  line-height: 1;
}
.exercise-score {
  color: var(--accent2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 800;
}
.exercise-hint {
  color: #c8d7e5;
  font-size: 11px;
  line-height: 1.3;
  min-height: 28px;
}
.exercise-progress {
  height: 10px;
  background: rgba(0,0,0,0.34);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 999px;
  overflow: hidden;
}
.exercise-progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #53c0f0, #78f0ad);
  transition: width 80ms linear;
}
.exercise-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--text-dim);
  font-size: 10px;
  line-height: 1.25;
}
.exercise-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.exercise-actions button {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #444;
  border-radius: 4px;
  padding: 4px 5px;
  cursor: pointer;
  font-size: 11px;
}
.exercise-actions button:hover:not(:disabled) {
  border-color: var(--accent2);
  color: var(--accent2);
}
.exercise-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}
#exercise-copy-btn {
  grid-column: 1 / -1;
}

/* ── Recordings ──────────────────────────────────────────────── */
.recording-actions {
  display: grid;
  grid-template-columns: 1fr 0.8fr;
  gap: 4px;
}

.recording-import {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.recording-file-input,
.recording-url-form input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #444;
  border-radius: 4px;
  padding: 4px 5px;
  font-size: 11px;
  min-width: 0;
}

.recording-file-input::file-selector-button {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid #444;
  border-radius: 4px;
  padding: 3px 6px;
  margin-right: 6px;
  cursor: pointer;
  font-size: 11px;
}

.recording-url-form {
  display: grid;
  grid-template-columns: 1fr 0.55fr;
  gap: 4px;
}

.recording-actions button,
.recording-url-form button,
.recording-item-actions button,
.recording-download {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #444;
  border-radius: 4px;
  padding: 4px 5px;
  cursor: pointer;
  font-size: 11px;
  text-align: center;
  text-decoration: none;
}

.record-btn {
  border-color: rgba(255, 96, 96, 0.75);
  color: #ff8c8c;
}

.record-btn.recording {
  background: rgba(190, 40, 40, 0.36);
  border-color: #ff8c8c;
  color: #ffd0d0;
}

.recording-actions button:hover:not(:disabled),
.recording-url-form button:hover,
.recording-file-input::file-selector-button:hover,
.recording-item-actions button:hover,
.recording-download:hover {
  border-color: var(--accent2);
  color: var(--accent2);
}

.recording-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.recording-status,
.recordings-empty {
  color: #c8d7e5;
  font-size: 11px;
  line-height: 1.35;
}

.reference-player {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px;
  background: rgba(20, 38, 48, 0.46);
  border: 1px solid rgba(99, 184, 255, 0.28);
  border-radius: 6px;
}

.reference-player.hidden {
  display: none;
}

.reference-player-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.reference-player-title {
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-player-time,
.reference-pitch-readout {
  color: #c8d7e5;
  font-size: 10px;
  white-space: nowrap;
}

.reference-player-seek {
  width: 100%;
}

.reference-player-actions,
.reference-pitch-actions {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}

.reference-player-actions button,
.reference-pitch-actions button {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #444;
  border-radius: 4px;
  padding: 4px 3px;
  cursor: pointer;
  font-size: 10px;
  text-align: center;
}

.reference-player-actions button:hover:not(:disabled),
.reference-pitch-actions button:hover:not(:disabled) {
  border-color: var(--accent2);
  color: var(--accent2);
}

.reference-player-actions button:disabled,
.reference-pitch-actions button:disabled,
.recording-item-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.reference-player-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  color: var(--text-dim);
  font-size: 10px;
}

.reference-player-row select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #444;
  border-radius: 4px;
  padding: 3px 4px;
  font-size: 11px;
}

.reference-pitch-row {
  grid-template-columns: 44px minmax(0, 1fr) 42px;
}

.recordings-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.recording-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 6px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
}

.recording-item.active {
  border-color: rgba(99, 184, 255, 0.55);
  background: rgba(22, 55, 70, 0.38);
}

.recording-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}

.recording-name {
  color: var(--text);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recording-details {
  color: var(--text-dim);
  font-size: 10px;
}

.recording-item-actions {
  display: grid;
  grid-template-columns: 0.8fr 1fr 0.8fr;
  gap: 4px;
}

.recording-delete {
  color: #ff8c8c;
}

/* ── Preset save/load ────────────────────────────────────────── */
#preset-name-input {
  background: var(--bg);
  border: 1px solid #444;
  border-radius: 3px;
  color: var(--text);
  padding: 3px 6px;
  font-size: 12px;
  width: 100%;
}
#save-btn {
  background: var(--surface2);
  color: var(--accent2);
  border: 1px solid var(--accent2);
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
}
#save-btn:hover { background: var(--accent2); color: #000; }

#saved-presets-list { display: flex; flex-direction: column; gap: 4px; }
.saved-preset-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.saved-preset-item button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  padding: 2px 4px;
  border-radius: 3px;
}
.load-preset-btn { color: var(--accent2); }
.load-preset-btn:hover { background: var(--surface2); }
.del-preset-btn { color: var(--accent); }
.del-preset-btn:hover { background: #300; }
.saved-preset-name { flex: 1; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Main content area ───────────────────────────────────────── */
#main-content {
  flex: 1;
  display: flex;
  min-width: 0;
  overflow: hidden;
}

/* ── Scale ladder + singscope side-by-side ───────────────────── */
#main-view {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

/* ── Scale ladder ────────────────────────────────────────────── */
#ladder-container {
  width: var(--ladder-w);
  position: relative;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid #333;
}

.zoom-follow-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 3;
  background: rgba(83, 192, 240, 0.12);
  color: rgba(83, 192, 240, 0.7);
  border: 1px solid rgba(83, 192, 240, 0.25);
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.zoom-follow-btn:hover {
  background: rgba(83, 192, 240, 0.22);
  color: rgba(83, 192, 240, 0.9);
  border-color: rgba(83, 192, 240, 0.5);
}

body.zoom-follow-active .zoom-follow-btn,
.zoom-follow-btn.active {
  background: rgba(83, 192, 240, 0.28);
  color: #b8f0ff;
  border-color: var(--accent2);
  box-shadow: 0 0 6px rgba(83, 192, 240, 0.25);
}

#scale-ladder {
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}

/* ── Singscope ───────────────────────────────────────────────── */
#singscope {
  flex: 1;
  min-width: 0;
  display: block;
  background: #111;
}

.score-practice-layer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: var(--ladder-w);
  width: calc(100% - var(--ladder-w));
  height: 100%;
  display: none;
  pointer-events: none;
  z-index: 2;
}

.score-practice-status {
  position: absolute;
  top: 8px;
  right: 8px;
  max-width: min(520px, calc(100% - var(--ladder-w) - 24px));
  padding: 5px 8px;
  border: 1px solid rgba(120, 240, 173, 0.32);
  border-radius: 4px;
  background: rgba(8, 12, 18, 0.78);
  color: #dff8ec;
  font-size: 12px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
  z-index: 4;
  display: none;
}

body.score-practice-active .score-practice-layer,
body.score-practice-active .score-practice-status {
  display: block;
}

.score-practice-controls {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 5;
  display: none;
  align-items: center;
  gap: 6px;
  max-width: min(720px, calc(100% - var(--ladder-w) - 24px));
  padding: 6px;
  border: 1px solid rgba(120, 240, 173, 0.34);
  border-radius: 6px;
  background: rgba(8, 12, 18, 0.84);
  box-shadow: 0 8px 24px rgba(0,0,0,0.32);
  pointer-events: auto;
}

body.score-practice-active .score-practice-controls {
  display: flex;
}

.score-practice-controls.has-import {
  flex-wrap: wrap;
  align-items: stretch;
}

.score-practice-controls.import-collapsed .score-practice-import {
  display: none;
}

.score-practice-speed {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 150px;
  color: #dff8ec;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.score-practice-speed input {
  width: 110px;
  accent-color: #78f0ad;
}

.score-practice-speed-readout {
  min-width: 34px;
  color: #c8d7e5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  text-align: right;
}

.score-practice-controls-title {
  flex: 0 0 auto;
  color: #dff8ec;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.score-practice-controls select {
  min-width: 160px;
  max-width: 260px;
  min-height: 32px;
  color: #e7f4fb;
  background: #101827;
  border: 1px solid rgba(83, 192, 240, 0.42);
  border-radius: 4px;
}

.score-practice-controls button {
  min-height: 32px;
  padding: 0 10px;
  color: #dff8ec;
  background: #123044;
  border: 1px solid rgba(120, 240, 173, 0.44);
  border-radius: 4px;
  cursor: pointer;
  font-weight: 700;
}

.score-practice-controls button:hover {
  border-color: #78f0ad;
}

.score-practice-import-toggle {
  flex: 0 0 auto;
}

.score-practice-import {
  flex: 1 0 100%;
  display: grid;
  grid-template-columns: minmax(118px, 0.45fr) minmax(150px, 0.7fr) minmax(72px, auto) minmax(58px, auto) auto auto;
  gap: 6px;
  align-items: center;
  width: min(840px, calc(100vw - var(--ladder-w) - 24px));
}

.score-practice-import input[type="number"] {
  min-height: 32px;
  width: 64px;
  color: #e7f4fb;
  background: #101827;
  border: 1px solid rgba(83, 192, 240, 0.42);
  border-radius: 4px;
  text-align: center;
}

.score-practice-import textarea {
  grid-column: 1 / -1;
  min-height: 34px;
  max-height: 72px;
  resize: vertical;
  color: #e7f4fb;
  background: #101827;
  border: 1px solid rgba(83, 192, 240, 0.42);
  border-radius: 4px;
  font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.score-practice-glyph-preview {
  grid-column: 1 / -1;
  display: grid;
  gap: 2px;
  min-height: 82px;
  padding: 4px;
  overflow: hidden;
  background: rgba(10, 14, 22, 0.7);
  border: 1px solid rgba(83, 192, 240, 0.28);
  border-radius: 4px;
}

.score-practice-glyph-preview.has-errors {
  border-color: rgba(255, 172, 82, 0.5);
}

.score-practice-glyph-preview-strip {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 1px 0 3px;
  scrollbar-width: thin;
}

.score-practice-glyph-preview-empty {
  align-self: center;
  color: #7da0b7;
  font-size: 11px;
}

.score-practice-glyph-cluster {
  flex: 0 0 auto;
  position: relative;
  display: block;
  width: 56px;
  height: 68px;
  padding: 0;
  color: #e7f4fb;
  background: #111a2a;
  border: 1px solid rgba(83, 192, 240, 0.28);
  border-radius: 4px;
}

.score-practice-glyph-cluster:hover {
  border-color: rgba(120, 240, 173, 0.66);
}

.score-practice-glyph-cluster.unknown {
  border-color: rgba(255, 172, 82, 0.58);
}

.score-practice-glyph-slot {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  pointer-events: none;
}

.score-practice-glyph-slot.above {
  gap: 1px;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 24px;
  height: 20px;
  z-index: 2;
}

.score-practice-glyph-slot.main {
  gap: 2px;
  top: 28px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 34px;
  height: 28px;
  z-index: 1;
}

.score-practice-glyph-slot.below {
  top: 44px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 24px;
  height: 14px;
}

.score-practice-glyph-preview-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'Neanes', serif;
  font-size: 29px;
  line-height: 1;
  min-width: 18px;
}

.score-practice-glyph-preview-item.pthora,
.score-practice-glyph-preview-item.qualitative {
  font-size: 18px;
}

.score-practice-glyph-preview-item.duration {
  transform: translateY(9px);
  font-size: 19px;
}

.score-practice-glyph-preview-item.temporal {
  transform: translateY(12px);
  font-size: 23px;
}

.score-practice-glyph-preview-item.unknown {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #ffd6a6;
}

.score-practice-glyph-cluster-label,
.score-practice-glyph-preview-summary {
  max-width: 100%;
  color: #8caac0;
  font-size: 9px;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-practice-glyph-cluster-label {
  position: absolute;
  right: 3px;
  bottom: 3px;
  left: 3px;
  pointer-events: none;
}

.score-practice-glyph-preview-summary {
  font-size: 10px;
}

.score-practice-glyph-keyboard {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 1px 0 3px;
  scrollbar-width: thin;
}

.score-practice-glyph-keyboard-group {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.score-practice-glyph-keyboard-label {
  color: #7da0b7;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.score-practice-controls .score-practice-glyph-key {
  min-height: 28px;
  min-width: 0;
  padding: 0 7px;
  color: #dceaf5;
  background: #172033;
  border-color: rgba(83, 192, 240, 0.34);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.score-practice-glyph-editor-open {
  grid-column: auto;
}

.score-practice-import-status {
  min-width: 48px;
  color: #c8d7e5;
  font-size: 11px;
  text-align: right;
}

.score-practice-import-diagnostics {
  grid-column: 1 / -1;
  max-height: 72px;
  margin: 0;
  padding: 6px 8px;
  overflow: auto;
  color: #ffd6a6;
  background: rgba(24, 16, 10, 0.82);
  border: 1px solid rgba(255, 172, 82, 0.36);
  border-radius: 4px;
  font: 11px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

.glyph-score-editor-dialog {
  width: min(1180px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  height: min(820px, calc(100dvh - 24px));
  max-height: calc(100dvh - 24px);
  margin: auto;
  padding: 0;
  color: #e7f4fb;
  background: #0b111b;
  border: 1px solid rgba(83, 192, 240, 0.42);
  border-radius: 8px;
}

.glyph-score-editor-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.glyph-score-editor-shell {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
}

.glyph-score-editor-header,
.glyph-score-editor-toolbar,
.glyph-score-editor-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(83, 192, 240, 0.22);
}

.glyph-score-editor-header {
  justify-content: space-between;
}

.glyph-score-editor-header h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.glyph-score-editor-header p {
  max-width: 72ch;
  margin: 3px 0 0;
  color: #9fb5c6;
  font-size: 12px;
  line-height: 1.35;
}

.glyph-score-editor-close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  color: #e7f4fb;
  background: #101827;
  border: 1px solid rgba(83, 192, 240, 0.38);
  border-radius: 4px;
  font-size: 22px;
  line-height: 1;
}

.glyph-score-editor-toolbar {
  justify-content: space-between;
}

.glyph-score-editor-category {
  min-height: 34px;
  color: #e7f4fb;
  background: #101827;
  border: 1px solid rgba(83, 192, 240, 0.42);
  border-radius: 4px;
}

.glyph-score-editor-status {
  min-width: 0;
  color: #bfd2df;
  font-size: 12px;
  text-align: right;
}

.glyph-score-editor-composer {
  display: flex;
  gap: 7px;
  min-height: 112px;
  padding: 8px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  background: #0e1724;
  border-bottom: 1px solid rgba(83, 192, 240, 0.22);
  scrollbar-width: thin;
}

.glyph-score-editor-empty {
  align-self: center;
  color: #7da0b7;
  font-size: 12px;
}

.glyph-score-editor-group,
.glyph-score-editor-catalog-item {
  color: #e7f4fb;
  background: #101827;
  border: 1px solid rgba(83, 192, 240, 0.3);
  border-radius: 5px;
}

.glyph-score-editor-group {
  flex: 0 0 92px;
  display: grid;
  place-items: center;
  gap: 2px;
  min-width: 92px;
  padding: 4px;
}

.glyph-score-editor-group.selected {
  border-color: #78f0ad;
  box-shadow: inset 0 0 0 1px rgba(120, 240, 173, 0.28);
}

.glyph-score-editor-group-visual {
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
}

.glyph-score-editor-group-label {
  color: #8caac0;
  font: 10px/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.glyph-score-editor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
  gap: 8px;
  min-height: 0;
  padding: 10px 12px;
  overflow: auto;
  scrollbar-width: thin;
}

.glyph-score-editor-catalog-item {
  display: grid;
  grid-template-rows: 104px auto auto;
  gap: 4px;
  min-width: 0;
  padding: 7px;
  text-align: left;
}

.glyph-score-editor-catalog-item:hover,
.glyph-score-editor-close:hover,
.glyph-score-editor-footer button:hover {
  border-color: #78f0ad;
}

.glyph-score-editor-catalog-item.visual-only {
  opacity: 0.58;
}

.glyph-score-editor-catalog-visual {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(to right, transparent 49%, rgba(120, 240, 173, 0.18) 49%, rgba(120, 240, 173, 0.18) 51%, transparent 51%),
    linear-gradient(to bottom, transparent 49%, rgba(120, 240, 173, 0.12) 49%, rgba(120, 240, 173, 0.12) 51%, transparent 51%),
    #121f31;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.glyph-score-editor-catalog-label,
.glyph-score-editor-catalog-semantic {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.glyph-score-editor-catalog-label {
  font-size: 12px;
  font-weight: 700;
}

.glyph-score-editor-catalog-semantic {
  color: #8caac0;
  font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-transform: uppercase;
}

.glyph-score-editor-footer {
  justify-content: flex-end;
  border-top: 1px solid rgba(83, 192, 240, 0.22);
  border-bottom: 0;
}

.glyph-score-editor-footer button {
  min-height: 34px;
  padding: 0 12px;
  color: #e7f4fb;
  background: #101827;
  border: 1px solid rgba(83, 192, 240, 0.42);
  border-radius: 4px;
  font-weight: 700;
}

.glyph-score-editor-footer button:disabled {
  opacity: 0.48;
}

.glyph-cluster-render {
  position: relative;
  width: 104px;
  height: 104px;
  color: #eafff4;
}

.glyph-score-editor-group .glyph-cluster-render {
  transform: scale(0.8);
}

.glyph-cluster-render-slot {
  position: absolute;
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  transform: translateX(-50%);
  pointer-events: none;
}

.glyph-cluster-render-slot.above {
  top: 8px;
  height: 34px;
  z-index: 2;
}

.glyph-cluster-render-slot.main {
  top: 37px;
  height: 44px;
  z-index: 1;
}

.glyph-cluster-render-slot.below {
  top: 73px;
  height: 27px;
  z-index: 0;
}

.glyph-cluster-render.modifier-only .glyph-cluster-render-slot.above,
.glyph-cluster-render.modifier-only .glyph-cluster-render-slot.below {
  top: 8px;
  height: 88px;
}

.glyph-cluster-render-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  font-family: 'Neanes', serif;
  font-size: 34px;
  line-height: 1;
}

.glyph-cluster-render-item.precomposed-quantity,
.glyph-cluster-render-item.quantity,
.glyph-cluster-render-item.rest,
.glyph-cluster-render-item.martyria-note {
  font-size: 42px;
}

.glyph-cluster-render-item.temporal {
  transform: translateY(15px);
  font-size: 42px;
}

.glyph-cluster-render-item.duration {
  transform: translateY(10px);
  font-size: 36px;
}

.glyph-cluster-render-item.pthora,
.glyph-cluster-render-item.qualitative,
.glyph-cluster-render-item.martyria-sign {
  transform: translateY(7px);
  font-size: 38px;
}

.glyph-cluster-render.has-main .glyph-cluster-render-slot.above {
  top: 16px;
  height: 30px;
}

.glyph-cluster-render.has-main.has-above .glyph-cluster-render-slot.main {
  top: 30px;
}

.glyph-cluster-render.has-main.has-above .glyph-cluster-render-item.temporal {
  transform: translateY(26px);
  font-size: 40px;
}

.glyph-cluster-render.has-main.has-above .glyph-cluster-render-item.duration {
  transform: translateY(25px);
  font-size: 38px;
}

.glyph-cluster-render.has-main.has-above .glyph-cluster-render-item.pthora,
.glyph-cluster-render.has-main.has-above .glyph-cluster-render-item.qualitative,
.glyph-cluster-render.has-main.has-above .glyph-cluster-render-item.martyria-sign {
  transform: translateY(24px);
  font-size: 36px;
}

.glyph-cluster-render.kind-martyria .glyph-cluster-render-slot.above {
  top: 22px;
  height: 28px;
}

.glyph-cluster-render.kind-martyria .glyph-cluster-render-slot.main {
  top: 18px;
  height: 54px;
}

.glyph-cluster-render.kind-martyria .glyph-cluster-render-slot.below {
  top: 43px;
  height: 28px;
}

.glyph-cluster-render.kind-martyria .glyph-cluster-render-item.martyria-note {
  transform: translate(-5px, -4px);
}

.glyph-cluster-render.kind-martyria .glyph-cluster-render-item.martyria-sign {
  transform: none;
  font-size: 35px;
}

.glyph-cluster-render.modifier-only .glyph-cluster-render-item {
  transform: none;
  font-size: 62px;
  text-shadow: 0 0 12px rgba(234, 255, 244, 0.28);
}

.glyph-cluster-render.modifier-only .glyph-cluster-render-item.duration {
  font-size: 70px;
}

.glyph-cluster-render.modifier-only .glyph-cluster-render-item.pthora,
.glyph-cluster-render.modifier-only .glyph-cluster-render-item.qualitative,
.glyph-cluster-render.modifier-only .glyph-cluster-render-item.martyria-sign {
  font-size: 66px;
}

/* ── Sung note indicator ────────────────────────────────────── */
.note-indicator {
  position: absolute;
  left: calc(var(--ladder-w) + (100% - var(--ladder-w)) / 2);
  bottom: 14px;
  transform: translateX(-50%);
  width: clamp(220px, 34vw, 360px);
  min-height: 80px;
  padding: 9px 12px;
  border: 1px solid rgba(83, 192, 240, 0.32);
  border-radius: 8px;
  background: rgba(10, 14, 22, 0.86);
  box-shadow: 0 10px 26px rgba(0,0,0,0.38);
  display: grid;
  grid-template-columns: 66px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  pointer-events: none;
  opacity: 1;
  transition: opacity 120ms ease, transform 120ms ease, border-color 120ms ease;
  z-index: 5;
}
.note-indicator.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(6px);
}

.note-indicator.has-exercise {
  width: clamp(300px, 40vw, 520px);
  min-height: 118px;
  padding: 10px 12px;
  gap: 7px 10px;
}

.practice-hud-target,
.practice-hud-progress,
.practice-hud-footer,
.practice-hud-actions {
  grid-column: 1 / -1;
}

.note-indicator:not(.has-exercise) .practice-hud-target,
.note-indicator:not(.has-exercise) .practice-hud-progress,
.note-indicator:not(.has-exercise) .practice-hud-footer,
.note-indicator:not(.has-exercise) .practice-hud-actions {
  display: none;
}

.practice-hud-target {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

#practice-hud-target-label {
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#practice-hud-step,
#practice-hud-score {
  color: var(--accent2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.practice-hud-progress {
  height: 9px;
  background: rgba(0,0,0,0.34);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 999px;
  overflow: hidden;
}

.practice-hud-progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #53c0f0, #78f0ad);
  transition: width 80ms linear;
}

.practice-hud-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #c8d7e5;
  font-size: 11px;
  line-height: 1.25;
  min-width: 0;
}

#practice-hud-hint {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.practice-hud-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 6px;
  pointer-events: auto;
}

.practice-hud-actions button {
  min-height: 30px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid #444;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  touch-action: manipulation;
}
.practice-hud-actions button:hover:not(:disabled) {
  border-color: var(--accent2);
  color: var(--accent2);
}
.practice-hud-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.note-indicator-martyria {
  position: relative;
  width: 62px;
  height: 66px;
  justify-self: center;
  font-family: 'Neanes', serif;
  color: #e8fbff;
  overflow: visible;
}
.note-indicator-note-glyph,
.note-indicator-below-glyph {
  position: absolute;
  left: 50%;
  top: var(--glyph-top, 0);
  transform: translateX(calc(-50% + var(--glyph-dx, 0em)));
  display: block;
  line-height: 1;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0,0,0,0.42);
}
.note-indicator-note-glyph {
  font-size: 37px;
}
.note-indicator-below-glyph {
  font-size: 36px;
}
.note-indicator-western {
  display: none;
}
.note-indicator-martyria.western-mode {
  font-family: 'Segoe UI', system-ui, sans-serif;
  display: flex;
  height: 52px;
  border: 1px solid rgba(83, 192, 240, 0.26);
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  background: rgba(83, 192, 240, 0.08);
}
.note-indicator-martyria.western-mode .note-indicator-western {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: #e8fbff;
  font-size: 24px;
  font-weight: 800;
}

.note-indicator-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.note-indicator-topline {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.note-indicator-name {
  color: #ffffff;
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}
.note-indicator-score {
  color: #78f0ad;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.note-indicator-meter {
  position: relative;
  height: 14px;
  border-radius: 7px;
  overflow: hidden;
  background:
    linear-gradient(90deg,
      #e94560 0%,
      #f0c040 30%,
      #50c878 47%,
      #50c878 53%,
      #f0c040 70%,
      #e94560 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}
.note-indicator-center {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  background: rgba(255,255,255,0.7);
  transform: translateX(-50%);
}
.note-indicator-cursor {
  position: absolute;
  top: 2px;
  left: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 8px rgba(0,0,0,0.55);
  transform: translateX(-50%);
  transition: left 80ms linear;
}
.note-indicator-offset {
  color: #c8d7e5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-indicator.grade-perfect {
  border-color: rgba(80, 200, 120, 0.72);
}
.note-indicator.grade-perfect .note-indicator-score { color: #78f0ad; }
.note-indicator.grade-close {
  border-color: rgba(83, 192, 240, 0.68);
}
.note-indicator.grade-close .note-indicator-score { color: #7ee7ff; }
.note-indicator.grade-work {
  border-color: rgba(240, 192, 64, 0.72);
}
.note-indicator.grade-work .note-indicator-score { color: #ffd867; }
.note-indicator.grade-wide {
  border-color: rgba(233, 69, 96, 0.76);
}
.note-indicator.grade-wide .note-indicator-score { color: #ff7b91; }
.note-indicator.no-pitch {
  border-color: rgba(83, 192, 240, 0.26);
}
.note-indicator.no-pitch .note-indicator-martyria {
  opacity: 0.45;
}
.note-indicator.no-pitch .note-indicator-meter {
  opacity: 0.72;
}
.note-indicator.exercise-running {
  border-color: rgba(83, 192, 240, 0.58);
}
.note-indicator.exercise-finished {
  border-color: rgba(120, 240, 173, 0.72);
}

/* ── Quick mobile singing controls ──────────────────────────── */
.quick-pthora-panel {
  display: none;
}

.quick-pthora-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.quick-pthora-title {
  color: var(--accent2);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.quick-pthora-degrees,
.quick-shading-buttons {
  display: grid;
  gap: 5px;
}

.quick-pthora-btn,
.quick-shading-btn {
  min-width: 0;
  min-height: 38px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid rgba(83, 192, 240, 0.34);
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  touch-action: manipulation;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-pthora-btn:hover,
.quick-shading-btn:hover {
  border-color: var(--accent2);
  color: var(--accent2);
}

.quick-pthora-degrees.phase-options .quick-pthora-btn {
  flex-basis: 58px;
}

/* ── SBMuFL Neanes font (OFL, bundled) ─────────────────────────── */
@font-face {
  font-family: 'Neanes';
  src: url('fonts/neanes/Neanes.otf') format('opentype');
  font-display: swap;
}

/* ── Pthora / shading palettes ───────────────────────────────── */
#palettes {
  width: min(320px, 100%);
  background: var(--surface);
  border-right: 1px solid #333;
  overflow-y: auto;
  padding: 8px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#palettes h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.palette-section { display: flex; flex-direction: column; gap: 4px; }

.palette-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.scale-reset-btn {
  border-color: rgba(255, 96, 96, 0.75);
  background: rgba(160, 32, 32, 0.22);
  color: #ff8c8c;
  font-size: 10px;
  padding: 3px 7px;
  min-height: 0;
}

.scale-reset-btn:hover {
  border-color: #ff8c8c;
  background: rgba(190, 40, 40, 0.34);
  color: #ffd0d0;
}

/* Column header row above the 3×8 pthora grid — degree names. */
.pthora-column-labels,
.pthora-row {
  display: grid;
  grid-template-columns: 34px repeat(8, minmax(0, 1fr));
  gap: 2px;
  align-items: center;
}

.pthora-phase-row {
  grid-template-columns: 34px repeat(4, minmax(0, 1fr));
}
.pthora-column-labels > span,
.pthora-row-label {
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
  letter-spacing: 0.04em;
  user-select: none;
}
.pthora-row-label {
  text-align: right;
  padding-right: 4px;
}

/* Chroa row — flex wrap of the local modifiers. */
.shading-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.shading-row .shading-icon { flex: 1 1 42px; min-width: 42px; }

.pthora-icon, .shading-icon {
  background: var(--bg);
  border: 1px solid #444;
  border-radius: 4px;
  padding: 4px 2px;
  min-width: 0;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--accent2);
  min-height: 36px;
}
.pthora-icon:hover, .shading-icon:hover { border-color: var(--accent2); background: var(--surface2); }
.pthora-icon:active, .shading-icon:active { cursor: grabbing; }
.pthora-icon.selected, .shading-icon.selected {
  border-color: #78f0ad;
  background: rgba(80, 200, 120, 0.14);
  box-shadow: inset 0 0 0 1px rgba(120, 240, 173, 0.38);
}
.pthora-icon.dragging, .shading-icon.dragging {
  opacity: 0.4;
  border-color: var(--accent2);
}

.pointer-drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.85;
  border-color: var(--accent2) !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  background: var(--surface2) !important;
}

.palette-glyph {
  width: 24px;
  height: 24px;
  display: block;
  pointer-events: none;
}

/* SBMuFL-rendered glyph: a single Private Use Area codepoint set in Neanes. */
.palette-glyph-sbmufl {
  font-family: 'Neanes', serif;
  font-size: 22px;
  line-height: 1;
  color: var(--accent2);
  pointer-events: none;
  user-select: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 22px;
  overflow: visible;
  /* Neanes PUA symbols sit high in the em box; offset for visual centering. */
  transform: translateY(0.24em);
}

.palette-glyph-western {
  font-size: 11px;
  line-height: 1;
  color: var(--accent2);
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
}

.palette-label {
  font-size: 10px;
  line-height: 1.1;
  color: var(--text);
  pointer-events: none;
}

.palette-degree-label {
  display: none;
  color: #c8d7e5;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

/* ── Help / release notes ───────────────────────────────────── */
.help-dialog {
  width: min(720px, calc(100vw - 24px));
  max-height: min(760px, calc(100dvh - 24px));
  margin: auto;
  color: var(--text);
  background: transparent;
  border: 0;
  padding: 0;
}
.help-dialog::backdrop { background: rgba(0, 0, 0, 0.64); }
.help-dialog-shell {
  background: #12192b;
  border: 1px solid rgba(83, 192, 240, 0.32);
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.52);
  overflow: hidden;
}
.help-dialog-header,
.help-dialog-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(15, 52, 96, 0.62);
}
.help-dialog-header {
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.help-dialog-header h2 {
  color: #fff;
  font-size: 18px;
  line-height: 1.2;
  margin-bottom: 4px;
}
.help-version {
  color: var(--accent2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  margin-bottom: 6px;
}
.help-dialog-header p,
.help-dialog-body p,
.help-dialog-body li {
  color: #c8d7e5;
  line-height: 1.45;
}
.help-dialog-body a {
  color: var(--accent2);
}
.help-close-btn {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  background: var(--bg);
  color: var(--text);
  border: 1px solid #444;
  border-radius: 4px;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}
.help-close-btn:hover {
  border-color: var(--accent2);
  color: var(--accent2);
}
.help-dialog-body {
  max-height: min(560px, calc(100dvh - 168px));
  overflow-y: auto;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
}
.help-dialog-body h3 {
  color: var(--accent2);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.help-dialog-body ul,
.help-dialog-body ol {
  padding-left: 18px;
}
.help-dialog-body li + li,
.help-dialog-body p + p {
  margin-top: 5px;
}
.key-run {
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
}
.help-dialog-footer {
  justify-content: space-between;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.help-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #c8d7e5;
}
.help-check input { accent-color: var(--accent2); }
.help-done-btn {
  background: var(--accent2);
  color: #07111f;
  border: 0;
  border-radius: 4px;
  padding: 7px 11px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}
.help-done-btn:hover { filter: brightness(1.08); }

@media (max-width: 720px), (max-width: 980px) and (max-height: 520px) and (orientation: landscape) {
  :root {
    --ladder-w: 132px;
  }

  body {
    height: 100dvh;
    overflow: hidden;
    font-size: 14px;
    width: 100%;
    max-width: 100vw;
  }

  #app-header,
  #mobile-tabs,
  #app-body,
  #controls-panel,
  #main-content {
    width: 100%;
    max-width: 100vw;
    min-width: 0;
  }

  #app-header {
    padding: 6px 8px;
    gap: 8px;
  }

  #app-header h1 {
    font-size: 15px;
  }

  .app-version {
    display: none;
  }

  .header-actions {
    gap: 4px;
  }

  .desktop-practice-toggle {
    display: none;
  }

  .header-btn {
    min-height: 32px;
    padding: 6px 8px;
    font-size: 12px;
  }

  #mobile-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #app-body {
    flex: 1;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
  }

  .help-dialog-body {
    grid-template-columns: 1fr;
  }

  .help-dialog-header,
  .help-dialog-footer {
    align-items: flex-start;
  }

  .help-dialog-footer {
    flex-direction: column;
  }

  .help-done-btn {
    width: 100%;
  }

  select,
  input[type="text"],
  input[type="number"] {
    font-size: 16px;
  }

  #controls-panel {
    order: 1;
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    max-height: 24dvh;
    border-right: 0;
    border-bottom: 1px solid #333;
    padding: 8px;
    gap: 8px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  #controls-panel .control-group {
    display: none;
  }

  body[data-mobile-view="sing"] #controls-panel .mobile-sing,
  body[data-mobile-view="scale"] #controls-panel .mobile-scale,
  body[data-mobile-view="train"] #controls-panel .mobile-train,
  body[data-mobile-view="more"] #controls-panel .mobile-more {
    display: flex;
  }

  body[data-mobile-view="more"] #controls-panel {
    flex: 1 1 auto;
    max-height: none;
    border-bottom: 0;
  }

  body.score-practice-active[data-mobile-view="train"] #controls-panel {
    display: none;
  }

  body[data-mobile-view="sing"] #controls-panel {
    display: none;
  }

  body[data-mobile-view="scale"] #controls-panel {
    display: none;
  }

  #preset-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }

  .preset-btn {
    max-width: 100%;
  }

  #main-content {
    order: 2;
    flex: 1 1 auto;
    flex-direction: column;
    width: 100%;
    max-width: 100vw;
    min-height: 0;
    overflow: hidden;
  }

  #main-view {
    flex: 1 1 auto;
    min-height: 0;
  }

  body[data-mobile-view="more"] #main-content {
    display: none;
  }

  body[data-mobile-view="sing"] #palettes,
  body[data-mobile-view="train"] #palettes {
    display: none;
  }

  body[data-mobile-view="train"] #ladder-container {
    display: none;
  }

  body[data-mobile-view="sing"] #singscope,
  body[data-mobile-view="train"] #singscope {
    flex: 1 1 auto;
    width: 100%;
  }

  body[data-mobile-view="train"] .score-practice-layer {
    left: 0;
    width: 100%;
  }

  body[data-mobile-view="train"] .score-practice-status {
    left: 8px;
    max-width: calc(100% - 16px);
  }

  body.score-practice-active .score-practice-controls {
    top: 38px;
    right: 6px;
    bottom: auto;
    left: 6px;
    max-width: calc(100% - 12px);
    width: calc(100vw - 12px);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    padding: 5px;
  }

  body.score-practice-active:not([data-mobile-view="train"]) .score-practice-layer,
  body.score-practice-active:not([data-mobile-view="train"]) .score-practice-status,
  body.score-practice-active:not([data-mobile-view="train"]) .score-practice-controls {
    display: none;
  }

  .score-practice-controls-title {
    display: none;
  }

  .score-practice-controls select {
    min-width: 0;
    width: 100%;
    max-width: none;
    min-height: 30px;
    font-size: 12px;
  }

  body.score-practice-active .score-practice-controls > select {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .score-practice-controls button {
    min-width: 52px;
    min-height: 30px;
    padding: 0 7px;
    font-size: 12px;
  }

  .score-practice-restart {
    display: none;
  }

  .score-practice-play {
    grid-column: 1;
    grid-row: 3;
    width: 100%;
    min-width: 0;
  }

  .score-practice-import-toggle {
    grid-column: 2;
    grid-row: 3;
    width: 100%;
    min-width: 0;
  }

  .score-practice-speed {
    grid-column: 1 / -1;
    grid-row: 2;
    min-width: 0;
    width: auto;
    gap: 5px;
    font-size: 11px;
  }

  .score-practice-speed input {
    flex: 1 1 auto;
    width: auto;
    min-width: 72px;
  }

  .score-practice-speed-readout {
    min-width: 30px;
    font-size: 10px;
  }

  .score-practice-import {
    grid-column: 1 / -1;
    grid-row: 4;
    grid-template-columns: minmax(92px, 0.42fr) minmax(0, 1fr) minmax(56px, 0.25fr);
    gap: 4px;
    width: 100%;
    max-height: min(34dvh, 220px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-top: 2px;
  }

  .score-practice-import-source,
  .score-practice-import-sample,
  .score-practice-glyph-preview,
  .score-practice-import textarea,
  .score-practice-glyph-keyboard,
  .score-practice-import-diagnostics {
    grid-column: 1 / -1;
  }

  .score-practice-import-source {
    grid-column: 1;
    grid-row: 1;
  }

  .score-practice-import-sample {
    grid-column: 2 / 4;
    grid-row: 1;
  }

  .score-practice-import-start {
    grid-column: 1 / 3;
    grid-row: 2;
  }

  .score-practice-import-bpm {
    grid-column: 3;
    grid-row: 2;
  }

  .score-practice-glyph-preview {
    grid-row: 3;
  }

  .score-practice-import textarea {
    grid-row: 4;
  }

  .score-practice-glyph-keyboard {
    grid-row: 5;
  }

  .score-practice-import-apply,
  .score-practice-glyph-editor-open,
  .score-practice-import-status {
    grid-column: 1 / -1;
  }

  .score-practice-glyph-editor-open {
    grid-row: 6;
  }

  .score-practice-import-apply {
    grid-row: 7;
  }

  .score-practice-import-status {
    grid-row: 8;
  }

  .score-practice-import-diagnostics {
    grid-row: 9;
  }

  .score-practice-import input[type="number"] {
    min-height: 30px;
    width: 100%;
  }

  .score-practice-import textarea {
    min-height: 40px;
    max-height: 72px;
    font-size: 11px;
  }

  .score-practice-glyph-preview {
    min-height: 72px;
    padding: 3px;
  }

  .score-practice-glyph-cluster {
    width: 50px;
    height: 58px;
  }

  .score-practice-glyph-slot.above {
    top: 9px;
    height: 16px;
  }

  .score-practice-glyph-slot.main {
    top: 23px;
    height: 24px;
  }

  .score-practice-glyph-slot.below {
    top: 38px;
    height: 12px;
  }

  .score-practice-glyph-preview-item {
    font-size: 26px;
  }

  .score-practice-glyph-preview-item.pthora,
  .score-practice-glyph-preview-item.qualitative {
    font-size: 14px;
  }

  .score-practice-glyph-preview-item.duration {
    transform: translateY(7px);
    font-size: 17px;
  }

  .score-practice-glyph-preview-item.temporal {
    transform: translateY(15px);
    font-size: 22px;
  }

  .score-practice-glyph-cluster-label {
    display: none;
  }

  .score-practice-glyph-preview-summary {
    font-size: 9px;
  }

  .score-practice-glyph-keyboard {
    gap: 5px;
    padding-bottom: 4px;
  }

  .score-practice-glyph-keyboard-group {
    gap: 3px;
  }

  .score-practice-controls .score-practice-glyph-key {
    min-height: 26px;
    padding: 0 5px;
    font-size: 9px;
  }

  .score-practice-glyph-keyboard-label {
    display: none;
  }

  .score-practice-import-status {
    text-align: left;
    font-size: 10px;
  }

  .score-practice-import-diagnostics {
    max-height: 56px;
    font-size: 10px;
  }

  .glyph-score-editor-dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .glyph-score-editor-header,
  .glyph-score-editor-toolbar,
  .glyph-score-editor-footer {
    padding: 8px;
  }

  .glyph-score-editor-header h2 {
    font-size: 16px;
  }

  .glyph-score-editor-header p {
    font-size: 11px;
  }

  .glyph-score-editor-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 5px;
  }

  .glyph-score-editor-status {
    text-align: left;
  }

  .glyph-score-editor-composer {
    min-height: 96px;
    padding: 6px 8px;
  }

  .glyph-score-editor-group {
    flex-basis: 78px;
    min-width: 78px;
  }

  .glyph-score-editor-group-visual {
    width: 72px;
    height: 72px;
  }

  .glyph-score-editor-group .glyph-cluster-render {
    transform: scale(0.68);
  }

  .glyph-score-editor-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
  }

  .glyph-score-editor-catalog-item {
    grid-template-rows: 90px auto auto;
    padding: 5px;
  }

  .glyph-score-editor-catalog-visual .glyph-cluster-render {
    transform: scale(0.82);
  }

  .glyph-score-editor-catalog-label {
    font-size: 11px;
  }

  .glyph-score-editor-footer {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .glyph-score-editor-footer button {
    min-width: 0;
    padding: 0 6px;
    font-size: 12px;
  }

  body[data-mobile-view="sing"] .quick-pthora-panel {
    position: absolute;
    top: 6px;
    left: calc(var(--ladder-w) + 6px);
    right: 6px;
    z-index: 6;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 6px;
    background: rgba(10, 14, 22, 0.86);
    border: 1px solid rgba(83, 192, 240, 0.32);
    border-radius: 8px;
    pointer-events: auto;
    overflow: hidden;
  }

  .quick-pthora-row {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 6px;
  }

  .quick-pthora-degrees {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 1px;
  }

  .quick-shading-buttons {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 1px;
  }

  .quick-pthora-btn {
    flex: 0 0 52px;
    min-height: 34px;
  }

  .quick-shading-btn {
    flex: 0 0 64px;
    min-height: 34px;
  }

  body[data-mobile-view="scale"] #singscope,
  body[data-mobile-view="scale"] .note-indicator {
    display: none;
  }

  body[data-mobile-view="scale"] #main-content {
    display: flex;
    overflow: hidden;
    overscroll-behavior: contain;
  }

  body[data-mobile-view="scale"] #main-view {
    order: 2;
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
  }

  body[data-mobile-view="scale"] #ladder-container {
    display: block;
    width: 100%;
    height: 100%;
    border-right: 0;
    border-top: 1px solid #333;
  }

  .note-indicator {
    left: 50%;
    bottom: 10px;
    width: min(390px, calc(100vw - 16px));
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 6px 8px;
    min-height: 138px;
    padding: 7px 9px;
  }

  .note-indicator:not(.has-exercise) {
    width: min(300px, calc(100vw - 20px));
    min-height: 68px;
  }

  body[data-mobile-view="sing"] .note-indicator:not(.has-exercise) {
    width: min(260px, calc(100vw - var(--ladder-w) - 14px));
  }

  .note-indicator.has-exercise {
    width: min(390px, calc(100vw - 16px));
    min-height: 138px;
  }

  .note-indicator-martyria {
    width: 52px;
    height: 58px;
  }

  .note-indicator-note-glyph {
    font-size: 32px;
  }

  .note-indicator-below-glyph {
    font-size: 31px;
  }

  .note-indicator-name {
    font-size: 20px;
  }

  .note-indicator-score,
  .note-indicator-offset {
    font-size: 11px;
  }

  #practice-hud-target-label {
    font-size: 15px;
  }

  .practice-hud-footer {
    font-size: 10px;
  }

  .practice-hud-actions {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .practice-hud-actions button {
    min-height: 34px;
    font-size: 12px;
  }

  #palettes {
    order: 1;
    width: 100%;
    max-width: 100vw;
    flex: 0 0 auto;
    max-height: 348px;
    border-right: 0;
    border-bottom: 1px solid #333;
    overflow: hidden;
    padding: 8px;
    gap: 6px;
  }

  #palettes h3 {
    margin-bottom: 2px;
  }

  body[data-mobile-view="scale"] #palettes .palette-section:nth-child(2) {
    display: none;
  }

  .palette-section {
    gap: 2px;
  }

  #pthora-palette {
    max-width: 100%;
    overflow-x: visible;
  }

  .pthora-column-labels {
    display: none;
  }

  .pthora-row {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    width: 100%;
    gap: 3px;
    padding: 3px 0;
  }

  .pthora-phase-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .pthora-column-labels > span,
  .pthora-row-label {
    font-size: 10px;
  }

  .pthora-row-label {
    grid-column: 1 / -1;
    text-align: left;
    padding: 0;
  }

  .pthora-icon,
  .shading-icon {
    min-height: 42px;
    padding: 3px 1px;
  }

  .pthora-icon {
    gap: 3px;
  }

  .palette-degree-label {
    display: block;
  }

  .shading-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    overflow-x: visible;
    padding-bottom: 2px;
  }

  .shading-row .shading-icon {
    min-width: 0;
  }

  .shading-icon .palette-glyph-sbmufl {
    font-size: 25px;
    height: 24px;
  }

  .palette-glyph-sbmufl {
    font-size: 23px;
    width: 26px;
    height: 22px;
  }

  .palette-label {
    font-size: 10px;
  }

  #scale-ladder,
  #singscope {
    touch-action: none;
  }

  @media (orientation: landscape) and (max-height: 520px) {
    #app-header {
      padding: 4px 8px;
    }

    #mobile-tabs {
      grid-template-columns: repeat(4, minmax(0, 1fr));
      padding: 4px 6px;
    }

    .mobile-tab {
      min-height: 30px;
      font-size: 12px;
    }

    body[data-mobile-view="sing"] .quick-pthora-panel {
      top: 6px;
      left: calc(var(--ladder-w) + 6px);
      right: auto;
      width: min(420px, calc(100vw - var(--ladder-w) - 12px));
      padding: 6px;
    }

    .quick-pthora-degrees {
      grid-template-columns: repeat(8, minmax(0, 1fr));
    }

    .quick-shading-buttons {
      grid-template-columns: repeat(7, minmax(0, 1fr));
    }

    .quick-pthora-btn,
    .quick-shading-btn {
      min-height: 32px;
      font-size: 10px;
    }

    .note-indicator {
      bottom: 6px;
    }

    .note-indicator:not(.has-exercise) {
      width: min(300px, calc(100vw - 20px));
    }

    .note-indicator.has-exercise {
      right: 8px;
      left: auto;
      transform: none;
      width: min(390px, calc(100vw - 20px));
      min-height: 126px;
    }

    #controls-panel {
      max-height: 32dvh;
    }

    body[data-mobile-view="scale"] #main-content {
      flex-direction: row;
    }

    body[data-mobile-view="scale"] #palettes {
      width: min(470px, 52vw);
      max-width: 52vw;
      height: 100%;
      max-height: none;
      border-right: 1px solid #333;
      border-bottom: 0;
      overflow: hidden;
    }

    body[data-mobile-view="scale"] #main-view,
    body[data-mobile-view="scale"] #ladder-container {
      min-height: 0;
      height: 100%;
    }
  }
}

/* ── Accidental popup ────────────────────────────────────────── */
#accidental-popup {
  position: fixed;
  display: none;
  background: var(--surface2);
  border: 1px solid var(--accent2);
  border-radius: 6px;
  padding: 8px;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  min-width: 160px;
}
#accidental-popup.visible { display: block; }

.acc-btns { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.acc-btn {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #555;
  border-radius: 3px;
  padding: 3px 6px;
  cursor: pointer;
  font-size: 11px;
}
.acc-btn:hover { border-color: var(--accent2); color: var(--accent2); }

.acc-custom-row { display: flex; gap: 4px; align-items: center; }
.acc-custom-row input {
  width: 56px;
  background: var(--bg);
  border: 1px solid #555;
  border-radius: 3px;
  color: var(--text);
  padding: 2px 4px;
  font-size: 11px;
}
.acc-custom-row button, #acc-clear-btn {
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid #555;
  border-radius: 3px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 11px;
}
.acc-custom-row button:hover { border-color: var(--accent2); color: var(--accent2); }
#acc-clear-btn { margin-top: 4px; width: 100%; color: var(--accent); }
#acc-clear-btn:hover { border-color: var(--accent); }

/* ── Audio status ────────────────────────────────────────── */
.audio-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid currentColor;
  cursor: default;
  letter-spacing: 0.04em;
}
.audio-off  { color: var(--text-dim); border-color: #444; }
.audio-on   { color: #50c878; border-color: #50c878; }

/* ── Ison controls ───────────────────────────────────────── */
.ison-row {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}
.ison-btn {
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid #555;
  border-radius: 4px;
  padding: 3px 8px;
  cursor: pointer;
  font-size: 11px;
  min-width: 36px;
}
.ison-btn.active { color: #50c878; border-color: #50c878; background: #0a2010; }
.ison-btn:hover  { border-color: var(--accent2); }

#ison-octave-select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #444;
  border-radius: 3px;
  padding: 2px 4px;
  font-size: 11px;
  cursor: pointer;
  max-width: 44px;
}

.ison-degree-buttons {
  flex: 1 1 100%;
  order: 1;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 3px;
  min-width: 0;
}
.ison-degree-btn {
  min-width: 0;
  padding: 3px 0;
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
}
.ison-degree-btn:hover { border-color: var(--accent2); }
.ison-degree-btn.active {
  color: #50c878;
  border-color: #50c878;
  background: #0a2010;
}

.voicing-buttons {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}
.voicing-btn {
  min-width: 0;
  padding: 4px 0;
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
}
.voicing-btn:hover { border-color: var(--accent2); }
.voicing-btn.active {
  color: var(--accent2);
  border-color: var(--accent2);
  background: rgba(83, 192, 240, 0.12);
}

.metronome-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.metronome-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.metronome-field input,
.metronome-field select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #444;
  border-radius: 3px;
  padding: 2px 4px;
  font-size: 11px;
  width: 56px;
}
.metronome-pips {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.metronome-pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #2a2a2a;
  border: 1px solid #555;
  transition: background 60ms linear, border-color 60ms linear;
}
.metronome-pip.active {
  background: var(--accent2);
  border-color: var(--accent2);
  box-shadow: 0 0 6px rgba(83, 192, 240, 0.7);
}
.metronome-pip:first-child.active {
  background: #50c878;
  border-color: #50c878;
  box-shadow: 0 0 6px rgba(80, 200, 120, 0.7);
}

/* ── Mic / correction ────────────────────────────────────── */
.mic-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.follow-row {
  margin-top: 8px;
}
.mic-label {
  font-size: 11px;
  color: var(--text-dim);
}
