:root {
  --bg: #101418;
  --panel-bg: #181f26;
  --border: #2a333c;
  --text: #eef2f5;
  --text-dim: #8b98a5;
  --accent: #ffb300;
  --hh-color: #4fc3f7;
  --sd-color: #ff8a65;
  --bd-color: #ef5350;
  --cell-empty: #232c34;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: 10px;
  gap: 10px;
}

.app-header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 4px 10px;
}

.app-header h1 {
  font-size: 1.1rem;
  margin: 0;
  color: var(--text-dim);
  font-weight: 600;
}

.exercise-title {
  font-size: 1.4rem;
  font-weight: 700;
}

.app-body {
  flex: 1;
  display: flex;
  gap: 10px;
  min-height: 0;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.main-panel {
  flex: 1;
  display: flex;
  min-width: 0;
}

.step-grid-panel {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 16px;
  overflow: auto;
}

/* Exercise switcher */

#exercise-switcher {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  overflow-y: auto;
  width: 92px;
}

.exercise-btn {
  flex: none;
  height: 64px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--cell-empty);
  color: var(--text);
  font-size: 1.4rem;
  font-weight: 700;
}

.exercise-btn.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 22%, var(--cell-empty));
  color: var(--accent);
}

/* Step grid */

.step-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}

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

.grid-label {
  width: 68px;
  flex: none;
  font-size: 0.95rem;
  color: var(--text-dim);
  text-align: right;
}

.grid-cells {
  flex: 1;
  display: flex;
  gap: 6px;
}

.grid-cell {
  flex: 1 1 0;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: var(--cell-empty);
  border: 2px solid var(--border);
}

.grid-cell.bar-start {
  margin-left: 10px;
}

.grid-row:nth-child(1) .grid-cell.hit {
  background: var(--hh-color);
  border-color: var(--hh-color);
}

.grid-row:nth-child(2) .grid-cell.hit {
  background: var(--sd-color);
  border-color: var(--sd-color);
}

.grid-row:nth-child(3) .grid-cell.hit {
  background: var(--bd-color);
  border-color: var(--bd-color);
}

.grid-cell.active {
  outline: 4px solid var(--accent);
  outline-offset: 2px;
}

/* Footer controls */

.app-footer {
  display: flex;
  gap: 10px;
  height: 110px;
}

.tempo-control {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 12px 20px;
}

.tempo-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.tempo-readout {
  font-size: 1.4rem;
  font-weight: 700;
  min-width: 110px;
  text-align: center;
}

.tempo-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--cell-empty);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
}

.tempo-slider {
  width: 100%;
  height: 36px;
}

.transport-control {
  width: 350px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px;
}

.play-btn {
  height: 76px;
  flex: 1;
  border-radius: 14px;
  border: none;
  background: #2e7d32;
  color: white;
  font-size: 1.3rem;
  font-weight: 700;
}

.play-btn.playing {
  background: #c62828;
}

.metronome-btn {
  height: 76px;
  width: 96px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--cell-empty);
  color: var(--text-dim);
  font-size: 0.95rem;
  font-weight: 700;
}

.metronome-btn.selected {
  border-color: var(--accent);
  color: var(--accent);
}

@media (max-width: 700px) {
  .app-body {
    flex-direction: column;
  }
  #exercise-switcher {
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .exercise-btn {
    flex: 1 0 56px;
  }
  .app-footer {
    flex-direction: column;
    height: auto;
  }
  .transport-control {
    width: auto;
  }
}
