:root {
  color-scheme: light;
}

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  line-height: 1.4;
  color: #1a1a1a;
  background: #f4f4f6;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: #0b5fff;
}

header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.5rem 1rem;
  background: #1a1a1a;
  color: white;
  flex: none;
}

header h1 {
  font-size: 1.1rem;
  margin: 0;
  flex: 1;
}

#help-button {
  align-self: center;
  min-height: 2rem;
  padding: 0.3rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: white;
  background: #333;
  border: 1px solid #555;
  border-radius: 999px;
  cursor: pointer;
}

#help-button:hover {
  background: #444;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
}

#app {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-areas: "toolbar canvas";
}

#toolbar {
  grid-area: toolbar;
  overflow-y: auto;
  padding: 0.75rem;
  background: #e9e9ee;
  border-right: 1px solid #cfcfd6;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#toolbar fieldset {
  border: 1px solid #cfcfd6;
  border-radius: 6px;
  padding: 0.5rem;
}

#toolbar legend {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #444;
}

#toolbar button,
#toolbar input,
#toolbar select {
  min-height: 2.25rem;
  font-size: 0.95rem;
}

/* :not(.note-swatch) keeps this from outranking the swatch's own pressed
   rule below — without it, this wins on specificity and paints every
   selected note solid blue instead of showing its actual note color. */
#toolbar button[aria-pressed="true"]:not(.note-swatch) {
  background: #0b5fff;
  color: white;
  border-color: #0b5fff;
}

#note-palette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.note-swatch {
  min-height: 2rem !important;
  min-width: 0;
  padding: 0;
  border: 2px solid #cfcfd6;
  border-radius: 4px;
  background: var(--note-color);
  cursor: pointer;
}

.note-swatch[aria-pressed="true"] {
  border-color: #1a1a1a;
  box-shadow: 0 0 0 2px #0b5fff;
}

.octave-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.octave-stepper output {
  font-variant-numeric: tabular-nums;
  min-width: 1.5rem;
  text-align: center;
}

#toolbar button:disabled,
#toolbar input:disabled,
#toolbar select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#toolbar fieldset label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
}

#toolbar fieldset label:last-child {
  margin-bottom: 0;
}

#toolbar select {
  flex: none;
}

#toolbar input[type="range"] {
  flex: 1;
  min-height: auto;
}

#toolbar input[type="text"] {
  flex: 1;
  min-width: 0;
}

.load-row {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}

.load-row select {
  flex: 1;
  min-width: 0;
}

.view-row {
  display: flex;
  gap: 0.4rem;
}

.view-row button {
  flex: 1;
}

.selection-status {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: #444;
}

#canvas-wrap {
  grid-area: canvas;
  position: relative;
  min-width: 0;
  min-height: 0;
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  background: #d8d8de;
}

#start-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: rgba(15, 15, 20, 0.72);
  color: white;
  font-size: 1.5rem;
  font-weight: 600;
  cursor: pointer;
}

#start-overlay[hidden] {
  display: none;
}

#help-dialog {
  position: relative;
  width: min(32rem, 90vw);
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.25rem 1.5rem 1.5rem;
  border: 1px solid #cfcfd6;
  border-radius: 10px;
  background: #fafafa;
  color: #1a1a1a;
}

#help-dialog::backdrop {
  background: rgba(15, 15, 20, 0.6);
}

#help-dialog h2 {
  margin: 0 0 0.75rem;
  font-size: 1.25rem;
}

#help-dialog h3 {
  margin: 1rem 0 0.35rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #444;
}

#help-dialog ul {
  margin: 0;
  padding-left: 1.2rem;
}

#help-dialog li {
  margin-bottom: 0.3rem;
  font-size: 0.9rem;
}

#help-dialog kbd {
  padding: 0.05rem 0.35rem;
  border: 1px solid #cfcfd6;
  border-radius: 4px;
  background: #e9e9ee;
  font-size: 0.85em;
}

#help-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 50%;
  background: #e9e9ee;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

#help-close:hover {
  background: #d8d8de;
}

@media (max-width: 600px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    grid-template-areas:
      "canvas"
      "toolbar";
  }

  #toolbar {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    border-right: none;
    border-top: 1px solid #cfcfd6;
    max-height: 40vh;
  }

  #toolbar fieldset {
    flex: none;
    width: 220px;
  }

  #note-palette {
    grid-template-columns: repeat(4, 1fr);
  }
}
