:root {
  --bg: #14161b;
  --panel: #1d2027;
  --border: #2d313b;
  --text: #e8e9ec;
  --muted: #8b909c;
  --accent: #6aa8ff;
  --good: #3ccf7a;
  --bad: #ff5d5d;
  --hint: #f5c451;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, "Segoe UI", sans-serif;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}
header h1 { margin: 0; font-size: 20px; font-weight: 600; }

.midi { display: flex; align-items: center; gap: 10px; }
.status { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--panel); }
.status.on { color: var(--good); }
.status.off { color: var(--bad); }

select, button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font: inherit;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }

.prompt { text-align: center; padding: 8px 0 8px; }
.session-bar { display: flex; justify-content: flex-end; align-items: center; gap: 8px; min-height: 34px; }
.session-timer { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; min-width: 80px; text-align: left; }
#btn-session.active { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button:disabled:hover { border-color: var(--border); }
select:disabled { opacity: .6; }
.chord-name {
  font-size: 96px;
  font-weight: 700;
  line-height: 1;
  transition: color .15s;
}
.chord-name.good { color: var(--good); }

/* "Correct!" pops up over the chord name until the next chord comes. */
.name-wrap { position: relative; }
.correct-pop {
  position: absolute; left: 50%; top: 100%; z-index: 2;
  transform: translate(-50%, -35%) scale(.6); opacity: 0; pointer-events: none;
  padding: 14px 28px; border-radius: 16px; white-space: nowrap;
  background: var(--good); color: #0c1a11; box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
  transition: opacity .2s, transform .2s;
}
.correct-pop.show { opacity: 1; transform: translate(-50%, -35%) scale(1); animation: correct-pop .35s ease-out; }
@keyframes correct-pop {
  0% { transform: translate(-50%, -35%) scale(.6); opacity: 0; }
  60% { transform: translate(-50%, -35%) scale(1.08); opacity: 1; }
  100% { transform: translate(-50%, -35%) scale(1); }
}
.correct-title { font-size: 34px; font-weight: 800; }
.correct-detail { font-size: 15px; font-weight: 600; opacity: .8; margin-top: 2px; }
.correct-letgo { font-size: 13px; font-weight: 600; margin-top: 6px; }
@media (prefers-reduced-motion: reduce) {
  .correct-pop, .correct-pop.show { animation: none; transition: opacity .2s; transform: translate(-50%, -35%); }
}
.chord-name.words { font-size: 64px; }
.prompt-row { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.chord-inv { color: var(--accent); font-size: 20px; font-weight: 600; min-height: 1.4em; margin-top: 6px; }
.staff {
  background: #f7f5ef;
  border-radius: 10px;
  padding: 4px 8px;
  line-height: 0;
}
.staff[hidden] { display: none; }
.staff .err { color: #333; font-size: 13px; line-height: 1.4; padding: 20px; display: block; }
button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.chord-sub { color: var(--muted); margin-top: 8px; min-height: 1.4em; font-size: 18px; }
.chord-sub .notes { color: var(--hint); font-weight: 600; letter-spacing: 1px; }
/* A right-hand finger number after a note name. */
.finger {
  display: inline-block; min-width: 1.25em; margin-left: 3px; padding: 0 3px; border-radius: 4px;
  font-size: .72em; line-height: 1.35; text-align: center; letter-spacing: 0; vertical-align: 2px;
  color: var(--muted); border: 1px solid currentColor;
}
.feedback { min-height: 1.6em; margin-top: 8px; font-size: 18px; font-weight: 600; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 12px; }

.piano-wrap { margin: 16px 0; }
.piano {
  position: relative;
  height: 160px;
  user-select: none;
  overflow-x: auto;
}
.key {
  position: absolute;
  top: 0;
  border: 1px solid #222;
  border-radius: 0 0 5px 5px;
  cursor: pointer;
}
.key.white { background: #f4f4f4; height: 160px; z-index: 1; }
.key.black { background: #1a1a1a; height: 100px; z-index: 2; }
.key.hint.white { background: #fbe3a0; }
.key.hint.black { background: #b08a2a; }
.key.down.white { background: var(--accent); }
.key.down.black { background: #3d78cc; }
.key.down.good { background: var(--good); }
.key.down.bad { background: var(--bad); }
.key .label {
  position: absolute;
  bottom: 6px;
  width: 100%;
  text-align: center;
  font-size: 10px;
  color: #888;
}
.held { color: var(--muted); margin-top: 8px; font-size: 14px; }

.mic-panel {
  margin-top: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}
.mic-panel[hidden], #mic-canvas[hidden] { display: none; }
.mic-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px 28px; font-size: 14px; }
.mic-control { display: flex; flex-direction: column; gap: 4px; flex: 1 1 220px; max-width: 300px; }
.mic-control small { color: var(--muted); font-size: 12px; line-height: 1.35; }
.mic-control input[type=range] { width: 150px; vertical-align: middle; }
.mic-control span[id$="-val"] { color: var(--muted); font-size: 12px; }
.mic-show { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; align-self: center; }
.meter-label { color: var(--muted); }
.meter { width: 150px; height: 8px; background: #101216; border-radius: 4px; overflow: hidden; margin: 6px 0 2px; }
#mic-level { height: 100%; width: 0; background: var(--good); transition: width .05s; }
#mic-canvas { display: block; width: 100%; height: 170px; margin-top: 10px; border-radius: 6px; }

.settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 24px;
}
fieldset {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px 14px;
}
legend { color: var(--muted); padding: 0 6px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
fieldset label { display: block; margin: 4px 0; cursor: pointer; }
.checks label { display: inline-flex; gap: 4px; margin: 0; }
.indent { margin: 4px 0 0 24px; }
.mini { margin-top: 10px; display: flex; gap: 6px; }
.mini button { padding: 3px 10px; font-size: 13px; }

.note { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
fieldset select, fieldset input[type=number] { margin-left: 6px; }
fieldset input[type=number] { width: 64px; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; font: inherit; }

.badge {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--hint);
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
}
.badge[hidden] { display: none; }

/* Progress: mastery is ordinal, one blue hue, darker = less practiced, lighter = mastered. */
:root {
  --lvl-1: #184f95;
  --lvl-2: #256abf;
  --lvl-3: #3987e5;
  --lvl-4: #86b6ef;
}
.progress {
  margin-top: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.progress-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.progress-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.progress-summary { color: var(--muted); font-size: 14px; margin: 6px 0 12px; }
.progress-grid { display: grid; gap: 2px; overflow-x: auto; font-size: 12px; }
.col-head { text-align: center; color: var(--muted); padding-bottom: 2px; }
.row-head { color: var(--muted); padding-right: 10px; white-space: nowrap; align-self: center; }
.cell {
  height: 26px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  cursor: default;
}
.cell.lvl-0, .swatch.lvl-0 { border: 1px dashed var(--border); }
.lvl-1 { background: var(--lvl-1); color: #f0efec; }
.lvl-2 { background: var(--lvl-2); color: #f0efec; }
.lvl-3 { background: var(--lvl-3); color: #0b0b0b; }
.lvl-4 { background: var(--lvl-4); color: #0b0b0b; }
.cell.off { opacity: .35; }
.cell:hover, .cell:focus { outline: 2px solid var(--text); outline-offset: 1px; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin-top: 12px; font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; }
.legend-note { color: var(--muted); flex-basis: 100%; display: block !important; }
.progress-tip {
  position: fixed;
  z-index: 10;
  max-width: 300px;
  background: #0d0e11;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  white-space: pre-line;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}
.progress-tip[hidden] { display: none; }
.progress-details { margin-top: 12px; font-size: 14px; }
.progress-details summary { cursor: pointer; color: var(--muted); }
#progress-table { border-collapse: collapse; margin-top: 8px; width: 100%; }
#progress-table th, #progress-table td { text-align: left; padding: 4px 10px 4px 0; border-bottom: 1px solid var(--border); }
#progress-table th { color: var(--muted); font-weight: 500; }
#progress-table tr.off { opacity: .5; }

.tip { color: var(--muted); font-size: 13px; margin-top: 24px; }

/* ---- Tabs and play along ---- */
[hidden] { display: none !important; }
.tabs { display: flex; gap: 4px; padding: 10px 24px 0; border-bottom: 1px solid var(--border); }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 16px; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
code { background: var(--bg); padding: 0 4px; border-radius: 4px; }
button.primary { background: var(--accent); color: #0b0b0b; border-color: var(--accent); font-weight: 600; min-width: 90px; }
button.mini { padding: 3px 10px; font-size: 13px; }
button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
#mode-play { padding-top: 16px; }
.play-top { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
.play-setup label, .play-options label { display: block; margin: 4px 0 8px; }
.play-setup select { max-width: 100%; margin-left: 6px; }
.play-setup textarea {
  display: block; width: 100%; margin-top: 4px; font-family: ui-monospace, Consolas, monospace; resize: vertical;
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; font-size: 15px;
}
.transpose button { padding: 2px 10px; margin: 0 4px; }
.song-link { display: inline-block; font-size: 14px; color: var(--accent); margin: 0 0 6px; text-decoration: none; }
.song-link:hover { text-decoration: underline; }
.errors { color: var(--hint); font-size: 13px; min-height: 1.2em; margin: 4px 0; }
.play-options select { display: block; margin-top: 4px; max-width: 100%; }
.play-options input[type=range] { width: 150px; vertical-align: middle; }
.bars { display: flex; flex-wrap: wrap; gap: 4px; margin: 16px 0 8px; }
.bar {
  flex: 0 0 calc(25% - 3px); display: flex; gap: 10px; justify-content: space-around;
  border: 1px solid var(--border); border-radius: 6px; padding: 8px; font-size: 18px; font-weight: 600;
}
.bar.current { border-color: var(--accent); background: rgba(106, 168, 255, .1); }
.bar-chord.hit { color: var(--good); }
.bar-chord.late { color: var(--hint); }
.bar-chord.missed { color: var(--bad); text-decoration: line-through; }
.play-stage { display: flex; justify-content: center; align-items: flex-end; gap: 48px; margin-top: 12px; }
.play-stage .label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .5px; text-align: center; }
.play-stage .now, .play-stage .next { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.play-stage .chord-name { font-size: 72px; }
.now-notes { color: var(--hint); font-weight: 600; letter-spacing: 1px; min-height: 1.4em; }
.next-name { font-size: 36px; font-weight: 700; color: var(--muted); }
.beat-dots { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 14px; min-height: 18px; }
.beat-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--border); }
.beat-dot.one { outline: 1px solid var(--muted); }
.beat-dot.on { background: var(--accent); }
.count-in { color: var(--hint); font-weight: 600; margin-left: 8px; }
#play-feedback { text-align: center; }
.feedback.big { font-size: 26px; color: var(--accent); }
.summary { margin-top: 12px; }
.summary h3, .changes h3 { margin: 0 0 6px; font-size: 15px; }
.summary-list { margin: 4px 0 0; padding-left: 18px; }
.changes { margin-top: 16px; }
.chord-input { width: 80px; text-align: center; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px; font: inherit; }
.change-row { display: flex; align-items: center; gap: 14px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.change-name { font-weight: 600; min-width: 110px; }
.change-time { font-variant-numeric: tabular-nums; min-width: 50px; }
@media (max-width: 800px) {
  .play-top { grid-template-columns: 1fr; }
  .bar { flex-basis: calc(50% - 2px); }
}
.storage-note { color: var(--muted); font-size: 12px; margin: 6px 0 0; opacity: .8; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  width: min(520px, 100%);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-box h2 { margin: 0 0 14px; font-size: 20px; }
.modal-box h3 { margin: 16px 0 6px; font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.report-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.report-tile { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; text-align: center; }
.report-value { display: block; font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.report-label { font-size: 12px; color: var(--muted); }
.report-compare { color: var(--muted); font-size: 14px; margin: 12px 0 0; }
.report-list { margin: 0; padding-left: 18px; font-size: 15px; line-height: 1.6; }
.modal-actions { margin-top: 18px; text-align: right; }
kbd {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  margin: 0 1px;
  font-size: 12px;
}

@media (max-width: 800px) {
  .settings { grid-template-columns: 1fr; }
  .chord-name { font-size: 64px; }
}

/* Phones: shorter keys to go with the narrower keyboard range. */
@media (max-width: 600px) {
  .play-stage { flex-wrap: wrap; gap: 16px 24px; } /* "Next" goes under "Now" */
  .piano, .key.white { height: 120px; }
  .key.black { height: 75px; }
}

.calib-status { color: var(--hint) !important; }
.calib-status:empty { display: none; }
#mic-calibrate { align-self: flex-start; margin-top: 2px; }

/* Let the play-along panels shrink to a phone's width (grid items otherwise keep their widest
   content's width, such as a long option in the mode menu). */
.play-top > * { min-width: 0; }
.play-setup select, .play-options select { width: 100%; max-width: 100%; margin-left: 0; }
.play-setup textarea { max-width: 100%; }
