:root {
  --bg: #f4f5f1;
  --surface: #ffffff;
  --ink: #17202a;
  --muted: #66717d;
  --line: rgba(23, 32, 42, 0.14);
  --accent: #f06f4f;
  --mint: #60d8c2;
  --amber: #f2c14e;
  --violet: #7c6cf2;
  --radius: 8px;
  --shadow: 0 18px 48px rgba(23, 32, 42, 0.12);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-width: 320px; min-height: 100%; margin: 0;
  background:
    linear-gradient(rgba(23, 32, 42, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 32, 42, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
  color: var(--ink);
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.58; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; min-height: 64px; padding: 12px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line); background: rgba(244, 245, 241, 0.88); backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: baseline; gap: 10px; color: inherit; text-decoration: none; }
.brand strong { font-size: 20px; font-weight: 900; letter-spacing: 0; }
.brand span { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }

.transport { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.icon-button, .secondary-action, .track-button {
  min-height: 38px; padding: 0 13px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); font-size: 13px; font-weight: 850;
  box-shadow: 0 8px 18px rgba(23, 32, 42, 0.08);
}
.primary-action {
  border-color: transparent; background: var(--ink); color: #fff;
}
.icon-button:hover, .secondary-action:hover, .track-button:hover {
  border-color: var(--accent); color: var(--accent);
}
.primary-action:hover { background: var(--accent); color: #fff; }
.download-link[hidden] { display: none; }
.download-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

.app-shell {
  display: grid; gap: 12px; width: min(100%, 1280px); margin: 0 auto; padding: clamp(10px, 2vw, 18px);
}

.monitor-panel, .panel {
  border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.monitor-panel {
  display: grid; grid-template-columns: minmax(220px, 0.34fr) minmax(0, 1fr) minmax(220px, 0.26fr);
  gap: 12px; align-items: center; padding: 14px;
}

.monitor-copy { display: grid; gap: 6px; }
.kicker {
  margin: 0; color: var(--accent); font-size: 12px; font-weight: 900; letter-spacing: 0.08em;
  line-height: 1; text-transform: uppercase;
}
h1, h2 { margin: 0; color: var(--ink); letter-spacing: 0; }
h1 { font-size: clamp(28px, 3.2vw, 42px); line-height: 0.98; }
h2 { font-size: 20px; line-height: 1.08; }

.meter-row { display: grid; grid-template-columns: 1fr 110px; gap: 10px; align-items: stretch; }
.meter {
  display: grid; gap: 6px; align-content: center; min-height: 68px; padding: 9px;
  border: 1px solid var(--line); border-radius: var(--radius); background: #fbfcf8;
}
.meter span { color: var(--muted); font-size: 12px; font-weight: 850; text-transform: uppercase; }
.meter strong { font-size: 26px; line-height: 1; }
.score-track { overflow: hidden; height: 8px; border-radius: 999px; background: rgba(23, 32, 42, 0.1); }
.score-track span {
  display: block; width: 0; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, var(--mint), var(--amber), var(--accent));
}

.waveform {
  display: block; width: 100%; height: 92px; border-radius: var(--radius);
  background: #101820;
}
.status-line {
  grid-column: 1 / -1; min-height: 20px; margin: 0; color: var(--muted); font-size: 13px; font-weight: 750;
}

.synth-form {
  display: grid; gap: 12px;
}
.panel { min-width: 0; padding: 16px; }
.controls-panel { display: grid; gap: 0; align-content: start; padding: 0; overflow: hidden; }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.panel-heading > div { display: grid; gap: 5px; }
summary.panel-heading {
  min-height: 58px; padding: 12px 14px; align-items: center; cursor: pointer; list-style: none;
}
summary.panel-heading::-webkit-details-marker { display: none; }
summary.panel-heading::after {
  content: "+"; display: grid; place-items: center; width: 28px; height: 28px; border: 1px solid var(--line);
  border-radius: 50%; color: var(--muted); font-size: 18px; font-weight: 850;
}
details[open] > summary.panel-heading {
  border-bottom: 1px solid var(--line); background: #fbfcf8;
}
details[open] > summary.panel-heading::after { content: "-"; color: var(--accent); }
.settings-dock {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px;
}
.settings-body {
  display: grid; gap: 14px; max-height: min(42vh, 430px); padding: 14px;
  overflow-y: auto; overscroll-behavior: contain;
}

label { display: grid; gap: 7px; min-width: 0; }
label > span {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  color: #34414e; font-size: 12px; font-weight: 850;
}
output { color: var(--accent); font-weight: 900; }
input, select {
  width: 100%; min-height: 40px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); outline: none;
}
input[type="text"], input[type="number"], select { padding: 0 10px; }
input[type="range"] { min-height: 30px; accent-color: var(--accent); }
input:focus, select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.field-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.control-pair { display: grid; grid-template-columns: minmax(0, 1fr) 76px; gap: 8px; align-items: center; }
.control-pair input[type="number"] { min-height: 34px; padding-inline: 8px; text-align: right; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.toggle-row {
  grid-template-columns: auto minmax(0, 1fr); align-items: center; justify-content: start;
  min-height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fbfcf8;
}
.toggle-row input { width: 18px; min-height: auto; height: 18px; accent-color: var(--accent); }
.toggle-row span { display: block; color: var(--ink); font-size: 13px; text-transform: none; }

.sequencer-panel { display: grid; gap: 12px; padding: 14px; }
.sequencer-heading { align-items: center; }
.chord-strip {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: min(680px, 100%);
  margin: 0; padding: 0; list-style: none;
}
.chord-strip li {
  display: flex; align-items: center; gap: 7px; padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fbfcf8; color: #34414e; font-size: 12px; font-weight: 800; white-space: nowrap;
}
.chord-strip select {
  width: 72px; min-height: 32px; padding-inline: 8px; font-size: 12px; font-weight: 850;
}
.track-toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.track-button {
  min-width: 92px; box-shadow: none;
}
.track-button.is-active {
  border-color: transparent; background: var(--ink); color: #fff;
}
.grid-scroll {
  overflow: auto; max-height: min(52vh, 470px); border: 1px solid var(--line); border-radius: var(--radius);
  background: #f9faf5; overscroll-behavior: contain;
}
.sequencer-grid {
  --steps: 64;
  display: grid; grid-template-columns: 72px repeat(var(--steps), 34px); gap: 1px;
  min-width: max-content; padding: 8px; background: rgba(23, 32, 42, 0.08);
}
.grid-corner, .step-marker, .note-label, .step-cell {
  display: grid; place-items: center; min-width: 0; border: 0; border-radius: 4px;
}
.grid-corner, .step-marker, .note-label {
  min-height: 28px; background: #ffffff; color: var(--muted); font-size: 11px; font-weight: 850;
}
.step-marker-bar { color: var(--accent); }
.note-label {
  position: sticky; left: 8px; z-index: 2; justify-content: end; padding-right: 9px; color: #34414e;
  box-shadow: none;
}
button.note-label { cursor: pointer; }
button.note-label:hover { color: var(--accent); }
.step-cell {
  width: 34px; height: 28px; background: #ffffff; color: transparent; font-size: 0;
}
.step-cell:hover { background: color-mix(in srgb, var(--accent) 14%, #ffffff); }
.step-cell.is-active {
  background: var(--accent); color: transparent; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.54);
}
.step-cell.is-anchor { background: var(--violet); }
.step-cell.is-kick { background: #101820; }
.step-cell.is-snare { background: var(--accent); }
.step-cell.is-hat { background: var(--mint); }
.step-cell[data-playhead="true"] {
  outline: 2px solid var(--amber); outline-offset: -2px;
}

@media (max-width: 980px) {
  .settings-dock { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .app-shell { padding: 10px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .brand { align-items: start; flex-direction: column; gap: 2px; }
  .transport { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .icon-button { padding-inline: 8px; }
  .monitor-panel { grid-template-columns: 1fr; }
  .monitor-panel, .panel { padding: 12px; }
  .controls-panel { padding: 0; }
  .meter-row { grid-template-columns: 1fr 96px; }
  .settings-dock { grid-template-columns: 1fr; }
  .settings-body { max-height: 320px; }
  .field-pair { grid-template-columns: 1fr; }
  .sequencer-heading { align-items: stretch; flex-direction: column; }
  .chord-strip { justify-content: flex-start; }
  .track-toolbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .track-button { min-width: 0; }
  .grid-scroll { max-height: 48vh; }
  .waveform { height: 76px; }
}

@media (max-width: 460px) {
  .meter-row { grid-template-columns: 1fr; }
}
