:root {
  color-scheme: light dark;
  font-family: system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  max-width: 720px;
  margin: 2rem auto;
  padding: 0 1rem;
  line-height: 1.5;
}

@media (max-width: 480px) {
  body {
    margin: 1rem auto;
  }
}

h1 {
  margin-bottom: 0;
}

.subtitle {
  margin-top: 0.25rem;
  opacity: 0.75;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: end;
  margin: 1.5rem 0;
}

.controls label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  gap: 0.25rem;
}

.controls select,
.controls input {
  font-size: 1rem;
  padding: 0.3rem;
}

.controls button {
  padding: 0.5rem 1.25rem;
  font-size: 1rem;
  cursor: pointer;
}

.beat-row {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.3rem;
  margin: 1.5rem 0;
  max-width: 20rem;
}

.beat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 1.6rem;
  padding: 0 0.2rem;
  border-radius: 5px;
  border: 2px solid #888;
  font-weight: bold;
  font-size: 0.8rem;
}

.beat.current {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3);
}

.beat.pass {
  background: #16a34a;
  border-color: #16a34a;
  color: white;
}

.beat.fail {
  background: #dc2626;
  border-color: #dc2626;
  color: white;
}

.beat.timing {
  background: #ea8c00;
  border-color: #ea8c00;
  color: white;
}

.beat-row.colors-hidden .beat.pass,
.beat-row.colors-hidden .beat.fail,
.beat-row.colors-hidden .beat.timing {
  background: transparent;
  border-color: #888;
  color: inherit;
}

.beat-row.colors-hidden .beat.current {
  border-color: #2563eb;
}

.live-status {
  display: flex;
  gap: 2rem;
  font-size: 1.1rem;
  margin: 1rem 0;
}

.banner {
  padding: 1rem;
  border-radius: 8px;
  margin: 1rem 0;
}

.banner-success {
  background: rgba(22, 163, 74, 0.12);
  border: 1px solid #16a34a;
}

.banner button {
  margin-right: 0.5rem;
  padding: 0.4rem 1rem;
  cursor: pointer;
}

.error {
  color: #dc2626;
  font-weight: bold;
}

.mistakes-section {
  margin: 1.5rem 0;
}

.mistakes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.mistakes-header h2 {
  font-size: 1.1rem;
  margin: 0.5rem 0;
}

.mistakes-header button {
  padding: 0.4rem 1rem;
  cursor: pointer;
}

.mistakes-log {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 16rem;
  overflow-y: auto;
}

.mistake-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  background: rgba(220, 38, 38, 0.1);
  border: 1px solid rgba(220, 38, 38, 0.4);
  font-size: 0.9rem;
}

.mistake-row button {
  flex-shrink: 0;
  padding: 0.2rem 0.6rem;
  cursor: pointer;
}

.mistake-row-timing {
  background: rgba(234, 140, 0, 0.1);
  border-color: rgba(234, 140, 0, 0.4);
}

.count-in {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 6rem;
  font-weight: bold;
  background: rgba(0, 0, 0, 0.55);
  color: white;
  z-index: 10;
}

.count-in[hidden] {
  display: none;
}

.keyboard-section {
  margin: 2rem 0 1rem;
}

.keyboard-section h2 {
  margin-bottom: 0.25rem;
  font-size: 1.1rem;
}

.keyboard-section .hint {
  margin-top: 0;
  font-size: 0.85rem;
  opacity: 0.75;
}

.keyboard {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.key-group {
  display: flex;
  gap: 0.2rem;
  padding: 0.25rem;
  border: 1px dashed #999;
  border-radius: 6px;
  flex-shrink: 0;
}

.key {
  min-width: 1.7rem;
  height: 1.7rem;
  padding: 0 0.15rem;
  border-radius: 5px;
  border: 2px solid #2563eb;
  background: transparent;
  color: inherit;
  font-weight: bold;
  font-size: 0.7rem;
  cursor: pointer;
}

.key:active {
  background: #2563eb;
  color: white;
}

.spectrogram-section {
  margin: 2rem 0;
}

.spectrogram-section h2 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.spectrogram-wrap {
  display: flex;
  gap: 0.4rem;
}

.freq-axis {
  position: relative;
  width: 3rem;
  flex-shrink: 0;
}

.freq-axis span {
  position: absolute;
  right: 0.25rem;
  transform: translateY(-50%);
  font-size: 0.7rem;
  opacity: 0.7;
}

.spectrogram-scroll {
  flex: 1;
  overflow-x: auto;
  border-radius: 6px;
  -webkit-overflow-scrolling: touch;
}

.spectrogram-stack {
  position: relative;
  height: 240px;
  width: max-content;
}

#spectrogram,
#spectrogramGrid {
  display: block;
  height: 240px;
}

.spectrogram-swara-labels {
  position: absolute;
  top: 0;
  left: 0;
  height: 240px;
  pointer-events: none;
  z-index: 2;
}

.spectrogram-swara-labels span {
  position: absolute;
  left: 4px;
  transform: translateY(-50%);
  font-size: 10px;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(0, 0, 0, 0.55);
  padding: 0 3px;
  border-radius: 3px;
  white-space: nowrap;
}

#spectrogram {
  background: #000;
}

#spectrogramGrid {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}
