:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #667085;
  --line: #d7dde7;
  --surface: #f8fafc;
  --panel: #ffffff;
  --blue: #246bfe;
  --green: #138a55;
  --amber: #b46100;
  --red: #c0362c;
  --shadow: 0 18px 60px rgba(21, 32, 43, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--surface);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.transport {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary {
  min-width: 140px;
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

.secondary {
  padding-inline: 14px;
  font-weight: 700;
}

.toggle-button {
  min-width: 132px;
  padding-inline: 14px;
  font-weight: 800;
}

.toggle-button.activate {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.toggle-button.deactivate {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

.bpm-presets {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: -4px 0 12px;
}

.bpmPreset {
  min-height: 34px;
  padding: 0;
  font-size: 0.84rem;
  font-weight: 800;
}

.bpmPreset.active {
  border-color: var(--blue);
  background: #e8f0ff;
  color: var(--blue);
}

.icon-button {
  width: 42px;
  padding: 0;
}

.workbench {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
}

.panel,
.stage {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.controls {
  padding: 18px;
}

.panel-section {
  padding: 0 0 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: 0;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: #2b3645;
  font-size: 0.9rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--blue);
}

.inline-value,
.small-text {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.strong-value {
  color: var(--ink);
  font-size: 1.25rem;
  font-weight: 900;
}

.check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.check-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  margin: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  font-size: 0.84rem;
}

.loop-controls {
  display: grid;
  gap: 8px;
  margin: 2px 0 14px;
}

.loop-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.loop-range label {
  margin-bottom: 0;
}

.input-source-panel {
  display: grid;
  gap: 12px;
}

.source-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.source-tab {
  min-width: 0;
  min-height: 54px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  font-size: 0.95rem;
  font-weight: 900;
}

.source-tab:last-child {
  border-right: 0;
}

.source-tab.active {
  background: #e8f0ff;
  color: var(--blue);
}

.configure-source {
  width: 100%;
}

.check-grid input {
  width: 16px;
  min-height: 16px;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}

.inline-check input {
  width: 16px;
  min-height: 16px;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.import-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.import-row .small-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#midiRefreshBtn,
#learnBtn {
  width: 100%;
  margin-bottom: 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #edf2f7;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.status-pill.live {
  background: #e6f6ee;
  color: var(--green);
}

.status-pill.warn {
  background: #fff4e0;
  color: var(--amber);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.32);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: min(520px, 100%);
  max-height: min(720px, calc(100vh - 40px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 18px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.modal-head h2 {
  margin-bottom: 0;
  font-size: 1.2rem;
}

.input-settings-pane[hidden] {
  display: none;
}

.stage {
  display: grid;
  grid-template-rows: auto auto auto auto;
  align-content: start;
  min-height: calc(100vh - 118px);
  overflow: visible;
}

.phase-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  max-height: 92px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  font-weight: 900;
}

.stage[data-phase="demo"] .phase-strip {
  background: #eef5ff;
  border-bottom-color: #b8ccff;
}

.stage[data-phase="count-response"] .phase-strip {
  background: #fff8eb;
  border-bottom-color: #ffd89b;
}

.stage[data-phase="response"] .phase-strip {
  background: #e8f8ef;
  border-bottom-color: #9bd8b8;
}

.stage[data-phase="done"] .phase-strip {
  background: #f1f5f9;
}

#phaseLabel {
  display: block;
  margin-bottom: 4px;
  font-size: 1.1rem;
}

#phaseHint {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.stage[data-phase="response"] #phaseLabel {
  color: var(--green);
  font-size: 1.45rem;
  text-transform: uppercase;
}

.stage[data-phase="response"] #phaseHint {
  color: #0f6d43;
}

#countLabel {
  min-width: 64px;
  text-align: right;
  color: var(--blue);
  font-size: 2rem;
  line-height: 1;
}

.score-wrap {
  display: flex;
  flex-direction: column;
  padding: 16px 18px 42px;
  gap: 12px;
  overflow: visible;
  background:
    linear-gradient(#eef3fa 1px, transparent 1px),
    linear-gradient(90deg, #eef3fa 1px, transparent 1px);
  background-size: 48px 48px;
}

#abcContainer {
  width: 100%;
  min-height: 130px;
  overflow: visible;
  padding-bottom: 22px;
}

#abcContainer svg {
  width: 100% !important;
  height: auto !important;
  overflow: visible;
  margin-bottom: 18px;
}

#abcContainer .abcjs-note,
#abcContainer .abcjs-rest,
#abcContainer .abcjs-bar {
  pointer-events: none;
}

.abc-cursor {
  fill: #00ff00 !important;
  opacity: 1;
}

.abc-cursor-response {
  fill: #00ff00 !important;
  opacity: 1;
}

.feedback-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.feedback-grid > div {
  min-height: 78px;
  padding: 14px 18px;
  border-right: 1px solid var(--line);
}

.feedback-grid > div:last-child {
  border-right: 0;
}

.metric-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.feedback-grid strong {
  font-size: 1.55rem;
}

.event-log {
  max-height: 210px;
  overflow: auto;
  padding: 16px 18px 18px;
}

.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.log-head h2 {
  margin: 0;
}

#eventList {
  display: grid;
  gap: 8px;
  padding-left: 24px;
  margin: 0;
}

#eventList li {
  color: var(--muted);
  font-size: 0.9rem;
}

.event-detail {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.hit {
  color: var(--green);
}

.early {
  color: var(--red);
}

.late,
.extra,
.miss {
  color: var(--red);
}

@media (max-width: 980px) {
  .app-shell {
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workbench {
    grid-template-columns: 1fr;
  }

  .stage {
    min-height: auto;
    grid-template-rows: auto auto auto auto;
  }
}

@media (max-width: 640px) {
  .feedback-grid {
    grid-template-columns: 1fr 1fr;
  }

  .feedback-grid > div:nth-child(2n) {
    border-right: 0;
  }

  .check-grid {
    grid-template-columns: 1fr;
  }

  .transport {
    width: 100%;
  }

  .primary {
    flex: 1;
  }
}
