:root {
  --bg: #0f1216;
  --card: #191f26;
  --card-2: #212a33;
  --text: #e8edf2;
  --muted: #9aa7b4;
  --accent: #4cc2ff;
  --good: #37d67a;
  --warn: #f6c343;
  --bad: #ff5f6d;
  --line: #2b353f;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* hidden-Attribut erzwingen – sonst überschreibt `label { display: flex }`
   das display:none des Browsers, und ausgeblendete Felder bleiben sichtbar. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

/* Zweispaltiges Layout: Übung (Schritt 2) links, restliche Schritte rechts */
.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.sidebar {
  grid-column: 1;
  grid-row: 1;
  position: sticky;
  top: 20px;
}

.main-col {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar,
  .main-col {
    grid-column: 1;
    grid-row: auto;
  }
  .sidebar {
    position: static;
  }
}

header {
  text-align: center;
  margin-bottom: 24px;
}

h1 {
  margin: 0;
  font-size: 2.2rem;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 {
  margin: 0 0 16px;
  font-size: 1.05rem;
  color: var(--muted);
  font-weight: 600;
}

/* Übungs-Typ (Segment-Art) deutlich vom Rest abgesetzt */
.mode-row {
  display: flex;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.mode-field {
  flex: 0 1 260px;
}

.mode-field select {
  font-weight: 600;
}

.controls {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  flex: 1;
  min-width: 140px;
}

select {
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1rem;
}

.staff-wrap {
  margin: 18px 0;
  display: flex;
  justify-content: center;
  background: #f4f1ea;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

#staff {
  width: 100%;
  max-width: 320px;
  height: auto;
}

#staff .staff-line,
#staff .ledger {
  stroke: #2b2b2b;
  stroke-width: 1.2;
}

.staff-wrap.editable #staff {
  cursor: pointer;
}

/* Vorschau-Note unterm Cursor (Klick würde sie hinzufügen) */
#staff .note.ghost,
#staff .ledger.ghost {
  opacity: 0.35;
  pointer-events: none;
}

#staff .ghost-label {
  fill: #55606b;
  font: 11px system-ui, sans-serif;
  opacity: 0.7;
  pointer-events: none;
}

/* Hover über vorhandener Note: Klick würde sie entfernen */
#staff .note.delete-hover {
  fill: #c43b47;
  stroke: #ff5f6d;
  stroke-width: 1.5;
}

.staff-wrap.editable {
  border-color: var(--accent);
}

#staff .note {
  fill: #14181d;
}

#staff .note.active {
  fill: #1fa35c;
  stroke: #37d67a;
  stroke-width: 2;
}

#staff .note-name.active {
  fill: #1fa35c;
  font-weight: 700;
}

#staff .clef circle,
#staff .clef path {
  fill: #14181d;
}

#staff .clef path {
  stroke: #14181d;
  stroke-width: 1;
  stroke-linejoin: round;
}

/* Vorzeichen (als Pfade gezeichnet, siehe accidentalSVG) */
#staff .acc line {
  stroke: #14181d;
  stroke-width: 1.3;
}

#staff .acc line.bar {
  stroke-width: 2.4;
}

#staff .acc path {
  fill: #14181d;
  stroke: #14181d;
  stroke-width: 0.8;
}

#staff .note-name {
  fill: #55606b;
  font: 12px system-ui, sans-serif;
  text-anchor: middle;
}

.inline-tempo {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 0 1 auto;
  color: var(--muted);
  font-size: 0.85rem;
}

.inline-tempo input[type="range"] {
  width: 120px;
  accent-color: var(--accent);
}

.inline-tempo input[type="number"] {
  width: 70px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.95rem;
  text-align: center;
}

/* Zahlen-Stepper (hoch/runter) auf dunklem Grund sichtbar machen */
.inline-tempo input[type="number"]::-webkit-inner-spin-button,
.inline-tempo input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: inner-spin-button;
  opacity: 1;
  height: 26px;
  filter: invert(1) brightness(1.6);
}

.button-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease;
}

.btn:hover { background: #2a343e; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  color: #062330;
  border-color: transparent;
  font-weight: 600;
}
.btn.primary:hover { background: #6fd0ff; }

/* „Abspielen": sekundär/umrandet – testet nur die gezeigten Töne, ist
   bewusst zurückhaltender als der Haupt-Button „Übung starten". */
.btn.ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
.btn.ghost:hover { background: rgba(76, 194, 255, 0.12); }

.btn.recording {
  background: var(--bad);
  color: #350309;
  border-color: transparent;
  font-weight: 600;
}

/* Pause-Knopf: gelb; im pausierten Zustand („Fortsetzen") grün */
.btn.pause {
  background: var(--warn);
  color: #3a2c05;
  border-color: transparent;
  font-weight: 600;
}
.btn.pause:hover { background: #f8d060; }

.btn.pause.resume {
  background: var(--good);
  color: #06331a;
}
.btn.pause.resume:hover { background: #5be294; }

.readout {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin: 8px 0 14px;
}

.readout-note {
  font-size: 2.4rem;
  font-weight: 700;
  min-width: 2.5em;
}

.readout-cents {
  font-size: 1.1rem;
  color: var(--muted);
}

canvas {
  width: 100%;
  height: auto;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: block;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 12px 0 0;
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

/* Mikrofon-Auswahl fest oben rechts im Fenster */
.mic-topbar {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 20;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.mic-topbar label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
}

.mic-topbar select {
  padding: 6px 8px;
  font-size: 0.9rem;
  max-width: 220px;
}

/* --- Übung (Lehrmodus) --- */

.seg-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.seg-empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 10px 12px;
  background: var(--card-2);
  border: 1px dashed var(--line);
  border-radius: 10px;
}

.seg-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
}

.seg-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
  padding: 4px 2px;
  user-select: none;
  -webkit-user-select: none;
}

.seg-handle:active { cursor: grabbing; }

.seg-item.dragging {
  opacity: 0.55;
  border-color: var(--accent);
}

.seg-label {
  flex: 1;
  font-size: 0.95rem;
}

.seg-reps {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.seg-reps input {
  width: 60px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.95rem;
  text-align: center;
}

/* Zahlen-Stepper (hoch/runter) auf dunklem Grund deutlich sichtbar machen */
.seg-reps input::-webkit-inner-spin-button,
.seg-reps input::-webkit-outer-spin-button {
  -webkit-appearance: inner-spin-button;
  opacity: 1;
  height: 26px;
  filter: invert(1) brightness(1.6);
}

.seg-del {
  padding: 6px 10px;
  font-size: 0.9rem;
  color: var(--bad);
}

.exercise-progress {
  margin: 14px 0 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent);
}

/* --- Übungsmodus ---------------------------------------------------- */
/* Während die Übung läuft (body.exercise-running): rechts nur noch
   Notensystem + Pitch-Kurve, links bleibt die Segment-Karte sichtbar
   (der Start-Knopf zeigt dann „⏹ Übung abbrechen"). */

body.exercise-running header,
body.exercise-running footer,
body.exercise-running #setup .controls,
body.exercise-running #setup .button-row,
body.exercise-running #setup .hint,
body.exercise-running #exercise > .hint,
body.exercise-running #practice .button-row,
body.exercise-running #practice .readout,
body.exercise-running #practice .hint {
  display: none !important;
}

body.exercise-running #staff {
  max-width: 420px;
}

/* Phasen-Anzeige: 👂 Zuhören / 🎻 Spielen */
.phase-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px 24px;
}

.phase-icon {
  font-size: 4rem;
  line-height: 1;
}

.phase-text {
  font-size: 2.6rem;
  font-weight: 700;
}

.phase-card.listen .phase-text { color: var(--accent); }
.phase-card.play .phase-text { color: var(--good); }

/* --- Auswertung --- */

.review-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.review-pos {
  color: var(--muted);
  font-size: 0.9rem;
  min-width: 140px;
  text-align: center;
}

.review-label {
  margin: 0 0 12px;
  font-weight: 600;
}

.review-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0 10px;
  font-size: 0.92rem;
}

.review-table th,
.review-table td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
}

.review-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.review-table td.ok { color: var(--good); font-weight: 700; }
.review-table td.miss { color: var(--bad); font-weight: 700; }

.review-summary {
  color: var(--muted);
  font-size: 0.92rem;
}

.review-summary b {
  color: var(--text);
}
