:root {
  --bg: #12141a;
  --card: #1c1f28;
  --text: #e8eaf0;
  --muted: #8a90a3;
  --accent: #4f8cff;
  --good: #3ecf8e;
  --ok: #e8c65a;
  --bad: #ef6a6a;
  --key-white: #f2f3f5;
  --key-black: #23262f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 1rem;
}

header {
  width: 100%;
  max-width: 960px;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.8rem;
}
h1 { margin: 0; font-size: 1.25rem; white-space: nowrap; }
.subtitle { margin: 0; color: var(--muted); font-size: 0.85rem; }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; }

.icon-toggle { position: relative; cursor: pointer; user-select: none; }
.icon-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.icon-toggle .icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.35rem;
  border-radius: 8px;
  border: 1px solid #333846;
  background: var(--bg);
}
.icon-toggle input:checked ~ .icon-off { display: none; }
.icon-toggle input:not(:checked) ~ .icon-on { display: none; }
.icon-toggle input:checked ~ .icon-on {
  background: rgba(79, 140, 255, 0.18);
  border-color: var(--accent);
  box-shadow: 0 0 6px rgba(79, 140, 255, 0.45);
}
.icon-toggle input:not(:checked) ~ .icon-off { opacity: 0.5; filter: grayscale(1); }

main { width: 100%; max-width: 960px; display: flex; flex-direction: column; gap: 0.8rem; }

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 1rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem 1.2rem;
  align-items: flex-end;
}

.control { display: flex; flex-direction: column; gap: 0.3rem; }
.control label { font-size: 0.75rem; color: var(--muted); }
.control.checkbox label { font-size: 0.85rem; color: var(--text); display: flex; align-items: center; gap: 0.4rem; }

select, input[type="range"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #333846;
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
}
input[type="range"] { padding: 0; height: 2rem; }

button.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1.4rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
button.primary.running { background: var(--bad); }

.stage { text-align: center; }

.beats { display: flex; justify-content: center; gap: 0.5rem; margin-bottom: 0.5rem; min-height: 14px; }
.beat-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: #333846;
  transition: background 0.05s;
}
.beat-dot.on { background: var(--accent); }
.beat-dot.accent.on { background: var(--good); }

.chord-display .next {
  font-size: 4.5rem;
  font-weight: 700;
  line-height: 1.1;
  min-height: 5rem;
}
.chord-display .current {
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.1;
  min-height: 2.6rem;
  margin-top: 0.2rem;
}
.chord-display .slot-label {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
  vertical-align: middle;
  margin-right: 0.4rem;
}

.feedback {
  min-height: 1.6rem;
  font-size: 1rem;
  font-weight: 600;
  margin: 0.4rem 0;
  transition: opacity 0.3s;
}
.feedback.good { color: var(--good); }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }

.keyboard-wrap { margin-top: 0.5rem; overflow-x: auto; }
#keyboard { width: 100%; min-width: 500px; height: auto; }

#keyboard rect.white { fill: var(--key-white); stroke: #999; stroke-width: 0.5; }
#keyboard rect.black { fill: var(--key-black); stroke: #000; stroke-width: 0.5; }
#keyboard rect.target { fill: var(--accent); }
#keyboard rect.rescue { fill: #35598f; }
#keyboard rect.glow { fill: var(--good); }
#keyboard rect.held-good { fill: var(--good); }
#keyboard rect.held-bad { fill: var(--bad); }
#keyboard rect.held { fill: var(--accent); }

.sound-hint {
  background: rgba(79, 140, 255, 0.15);
  color: var(--accent);
  font-weight: 600;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  margin-bottom: 0.6rem;
  animation: sound-hint-pulse 1.2s ease-in-out infinite;
}
.hidden { display: none; }

@keyframes sound-hint-pulse {
  50% { opacity: 0.55; }
}

.hint-notes { color: var(--muted); font-size: 0.95rem; min-height: 1.3rem; margin-top: 0.3rem; }
.hint-notes b { color: var(--text); }

.stats { display: flex; justify-content: space-around; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 0.15rem; }
.stat-num { font-size: 1.6rem; font-weight: 700; }
.stat-label { font-size: 0.75rem; color: var(--muted); }

footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding-bottom: 1rem; }

@media (max-width: 700px) {
  .subtitle { display: none; }
}

@media (max-width: 600px) {
  .chord-display .next { font-size: 3rem; min-height: 3.4rem; }
  .chord-display .current { font-size: 1.6rem; min-height: 2rem; }
  .controls { gap: 0.6rem; }
}
