:root {
  --paper: #fbfaf6;
  --ink: #171717;
  --muted: #68665f;
  --line: #d8d3c8;
  --line-strong: #999487;
  --surface: #fffefb;
  --accent: #0b6f92;
  --active: #dceff5;
  --good: #27734d;
  --bad: #a8463d;
  --key-white: #fffdf8;
  --key-black: #171717;
  --lab-width: 1248px;
}

* { box-sizing: border-box; }

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

.app-shell {
  max-width: 1340px;
  margin: 0 auto;
  padding: 22px 28px 34px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) auto;
  gap: 20px;
  align-items: start;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--ink);
}

h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 650;
  letter-spacing: 0;
}

.description {
  min-height: 20px;
  max-width: 760px;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.42;
}

.toolbar {
  display: flex;
  max-width: 900px;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
}

label,
.status {
  color: var(--muted);
  font-size: 12px;
}

.status {
  min-width: 54px;
  white-space: nowrap;
}

button,
select {
  min-height: 30px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

button {
  padding: 5px 10px;
  cursor: pointer;
}

button.secondary {
  border-color: var(--line-strong);
  color: var(--muted);
}

button:hover,
select:hover {
  border-color: var(--accent);
  color: var(--accent);
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

select {
  max-width: 240px;
  padding: 4px 28px 4px 8px;
}

input[type="range"] {
  width: 96px;
  accent-color: var(--accent);
}

.select-fallback {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.instrument-palette {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 8px 10px;
  align-items: center;
  padding: 14px 0 12px;
  border-bottom: 1px solid var(--line);
}

.instrument-group-label {
  color: var(--muted);
  font-size: 12px;
}

.instrument-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.instrument-group button {
  min-height: 28px;
  padding: 4px 9px;
  border-color: var(--line-strong);
  background: transparent;
  color: var(--ink);
}

.instrument-group button[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.demo-strip {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  padding: 12px 0 16px;
  border-bottom: 1px solid var(--line);
}

.demo-strip button {
  min-height: 28px;
  padding: 4px 9px;
  border-color: var(--line-strong);
  color: var(--ink);
  background: transparent;
}

.demo-strip button:active {
  background: var(--active);
}

.lab-scroll {
  overflow-x: auto;
  padding: 18px 0 10px;
}

.pitch-lab {
  width: var(--lab-width);
}

.keyboard-frame {
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--line-strong);
  background: var(--surface);
}

.piano {
  position: relative;
  width: var(--lab-width);
  height: 118px;
  user-select: none;
  overflow: hidden;
  background: var(--surface);
}

.key {
  position: absolute;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  border: 1px solid var(--ink);
  border-top: 0;
  font-size: 10px;
  line-height: 1;
  padding-bottom: 5px;
  cursor: pointer;
  touch-action: none;
}

.key.white {
  width: 24px;
  height: 118px;
  background: var(--key-white);
  color: var(--muted);
  z-index: 1;
}

.key.black {
  width: 15px;
  height: 72px;
  top: 0;
  bottom: auto;
  background: var(--key-black);
  color: transparent;
  z-index: 2;
  border-top: 1px solid var(--ink);
}

.key.active.white {
  background: var(--active);
  color: var(--ink);
}

.key.active.black {
  background: var(--accent);
}

.chart-block {
  margin-top: 16px;
}

.chart-heading {
  display: flex;
  align-items: baseline;
  min-height: 20px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
}

.chart-frame {
  position: relative;
  width: var(--lab-width);
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--line-strong);
  background: var(--surface);
}

canvas {
  display: block;
  width: var(--lab-width);
  max-width: none;
  background: var(--surface);
}

.pitch-grid {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.grid-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
}

.grid-line::before,
.grid-line::after {
  content: "";
  position: absolute;
  left: 0;
  width: 1px;
  height: 7px;
  background: rgba(23, 23, 23, 0.16);
}

.grid-line::before {
  top: 0;
}

.grid-line::after {
  bottom: 0;
}

.grid-line.octave::before,
.grid-line.octave::after {
  height: 13px;
  background: rgba(23, 23, 23, 0.36);
}

.partials-shell {
  margin-top: 16px;
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line);
}

.partials-shell summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
}

.partials {
  padding: 0 0 12px;
}

.partial-row {
  display: grid;
  grid-template-columns: 54px 92px 84px 72px minmax(140px, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 28px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.partial-row strong {
  color: var(--ink);
  font-weight: 600;
}

.partial-bar {
  height: 4px;
  background: #ebe7dc;
}

.partial-bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
}

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

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

  .toolbar {
    justify-content: flex-start;
  }

  .instrument-palette {
    grid-template-columns: 1fr;
  }

  .status {
    min-width: 0;
  }
}
