:root {
  --bg: #f7f7f8;
  --fg: #1a1a1a;
  --muted: #666;
  --accent: #2563eb;
  --ok: #16a34a;
  --err: #dc2626;
  --surface: #ffffff;
  --border: #e5e7eb;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --fg: #f1f5f9;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --ok: #4ade80;
  --err: #f87171;
  --surface: #1e293b;
  --border: #334155;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.back-link {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 1.1rem;
  text-decoration: none;
}
.back-link:hover {
  background: var(--bg);
}

.topbar-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.midi-picker {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.5rem 0.25rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.midi-picker .midi-icon {
  font-size: 1rem;
  opacity: 0.8;
}

.midi-picker select {
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 0.9rem;
  padding: 0.2rem 0.2rem;
  cursor: pointer;
  max-width: 220px;
}

.midi-picker select:focus {
  outline: none;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--fg);
}

.icon-btn:hover {
  background: var(--bg);
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

#status-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

#timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--muted);
}

#round-info {
  text-align: right;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

.progress {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--fg);
}

#highscore-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.55rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.92rem;
}

.hs-label {
  color: var(--muted);
  flex: 1;
}
.hs-value {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.hs-value.highlight {
  color: var(--ok);
  font-weight: 700;
}
.hs-value.dim {
  color: var(--muted);
}

.primary-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn:hover {
  filter: brightness(1.05);
}

.primary-btn.stop {
  background: var(--err);
}

.note-feedback {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  min-height: 2.4rem;
  letter-spacing: 0.02em;
}

.note-feedback.ok {
  color: var(--ok);
}

.note-feedback.err {
  color: var(--err);
}

#staff-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  justify-content: center;
}

#staff-container {
  width: 100%;
  max-width: 700px;
  /* In Dark-Mode invertieren wir das von VexFlow gerenderte SVG, damit Linien hell sind */
}

[data-theme="dark"] #staff-container svg {
  filter: invert(0.92) hue-rotate(180deg);
}

#piano-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  min-height: 180px;
  overflow-x: auto;
  /* Eigener, größerer Container außerhalb der 960px-Begrenzung von <main>.
     max-width legt fest, wie groß die Klaviatur maximal werden darf;
     Wert = 2× natürliche SVG-Breite (28 weiße Tasten × 36px = 1008px → ~2000px). */
  max-width: 2032px;
  margin: 0 auto 1.5rem;
}

#piano-container {
  width: 100%;
  display: flex;
  justify-content: center;
}

#piano-container svg {
  display: block;
  height: auto;
  width: 100%;
}

.placeholder {
  color: var(--muted);
  font-style: italic;
}

/* ===== Settings Modal ===== */

.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: none;
  z-index: 100;
}
.settings-backdrop.open {
  display: block;
}

.settings-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(640px, 92vw);
  max-height: 88vh;
  display: none;
  flex-direction: column;
  z-index: 101;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.settings-modal.open {
  display: flex;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.settings-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.settings-body {
  padding: 1rem 1.25rem 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.settings-section {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem 1rem;
  margin: 0;
}
.settings-section legend {
  padding: 0 0.4rem;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--muted);
}
.settings-section label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
  cursor: pointer;
  font-size: 0.95rem;
}
.settings-section hr {
  border: none;
  border-top: 1px dashed var(--border);
  margin: 0.6rem 0;
}

.toggle-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

/* Range slider */
.range-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}
.range-label {
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.range-divider {
  color: var(--muted);
  font-size: 0.9rem;
}

.dual-slider {
  position: relative;
  height: 32px;
  margin: 0 0.5rem;
}
.dual-track {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  transform: translateY(-50%);
}
.dual-fill {
  position: absolute;
  top: 50%;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  transform: translateY(-50%);
}
.dual-slider input[type="range"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 32px;
  margin: 0;
  background: none;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}
.dual-slider input[type="range"]::-webkit-slider-thumb {
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}
.dual-slider input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  cursor: pointer;
}
.dual-slider input[type="range"]::-webkit-slider-runnable-track {
  background: transparent;
  height: 4px;
}

.range-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}

/* Pill-Group für 1/2/3/4 */
.pill-group {
  display: flex;
  gap: 0.4rem;
}
.pill-group button {
  flex: 1;
  padding: 0.5rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}
.pill-group button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.settings-footer {
  display: flex;
  justify-content: flex-end;
}
.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
}
.ghost-btn:hover {
  color: var(--fg);
}

.hint {
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
}
