:root {
  --bg: #1e1e24;
  --panel: #2a2a33;
  --text: #e8e8ec;
  --muted: #9a9aa5;
  --accent: #6c8cff;
  --correct: #35c46a;
  --incorrect: #e05353;
  --border: #3a3a45;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* The piano breaks out of main's max-width to use the full viewport
     width (see .piano-wrap) — 100vw can be wider than the visible area
     when a vertical scrollbar is present, which would otherwise add an
     unwanted horizontal scrollbar to the whole page. */
  overflow-x: hidden;
}

header {
  padding: 1.5rem 1rem 0.5rem;
  text-align: center;
}

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

.tagline {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.app-footer {
  width: 100%;
  max-width: 640px;
  padding: 0 1rem 1.5rem;
  text-align: center;
}

.app-footer p {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.app-footer a {
  color: var(--muted);
}

main {
  width: 100%;
  max-width: 640px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.midi-panel {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
}

.midi-panel label {
  color: var(--muted);
}

#midi-device {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
}

.status {
  color: var(--muted);
  margin-left: auto;
}

.status.ok {
  color: var(--correct);
}

.status.error {
  color: var(--incorrect);
}

.practice-options {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
}

#start-session-btn {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

#start-session-btn:hover {
  opacity: 0.9;
}

.practice-options label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  cursor: pointer;
}

.practice-options label:has(input:disabled) {
  cursor: default;
  opacity: 0.6;
}

.staff-panel {
  position: relative;
  background: #fdfdf8;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  justify-content: center;
  overflow-x: auto;
}

#staff svg {
  max-width: 100%;
}

.flash-overlay {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease-out;
}

.flash-overlay.correct {
  background: var(--correct);
  opacity: 0.35;
}

.flash-overlay.incorrect {
  background: var(--incorrect);
  opacity: 0.35;
}

.hidden {
  display: none !important;
}

.corrective-feedback {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--incorrect);
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  pointer-events: none;
  z-index: 1;
}

.piano-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 0.75rem;
  overflow-x: auto;
  box-sizing: border-box;
  /* Break out of main's max-width so the piano can use the full viewport
     width on desktop (key widths are computed in JS to fill it exactly,
     avoiding scroll). On narrow/mobile viewports the computed key width
     hits its floor and this scrolls horizontally, which is expected. */
  width: 100vw;
  margin-left: calc(50% - 50vw);
}

#piano {
  position: relative;
}

.piano-key {
  position: absolute;
  top: 0;
  box-sizing: border-box;
  border: 1px solid #000;
  border-radius: 0 0 4px 4px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.piano-key.white {
  background: #fdfdf8;
  z-index: 1;
}

.piano-key.white.active {
  background: var(--accent);
}

.piano-key.black {
  background: #1a1a1a;
  z-index: 2;
}

.piano-key.black.active {
  background: var(--accent);
}

.idle-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--muted);
}

.summary-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem 1rem;
  text-align: center;
}

.summary-panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1.2rem;
}

.summary-score {
  font-size: 1.6rem;
  font-weight: 600;
  margin: 0.25rem 0;
}

.summary-avg {
  color: var(--muted);
  margin: 0 0 1rem;
}

#play-again-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

#play-again-btn:hover {
  opacity: 0.9;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.5rem;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.4rem;
  font-weight: 600;
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

@media (max-width: 480px) {
  .stats-panel {
    grid-template-columns: repeat(2, 1fr);
  }
}
