:root {
  color-scheme: light;
  --page: #d7d6d3;
  --surface: #f7f7f5;
  --surface-soft: #ececea;
  --surface-dark: #151b23;
  --line: #c9c9c6;
  --line-strong: #25282c;
  --text: #1c1d1f;
  --muted: #66686a;
  --faint: #8b8d8f;
  --accent: #0d4f85;
  --accent-strong: #435b6d;
  --accent-soft: #dce6e5;
  --terracotta: #bf0f0f;
  --terracotta-dark: #a30d0d;
  --ochre: #0d852f;
  --ochre-dark: #0a6624;
  --playhead: #999;
  --danger: #8e493b;
  --radius-large: 24px;
  --radius-medium: 18px;
  --radius-small: 10px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--page);
  font-family:
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
.sequencer-scroll:focus-visible {
  outline: 3px solid rgb(67 91 109 / 42%);
  outline-offset: 3px;
}

.app-shell {
  width: min(1600px, calc(100% - 64px));
  margin: 0 auto;
  padding: 36px 0 36px;
}

.app-header {
  margin-bottom: 50px;
}

.brand-block {
  max-width: 840px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 820;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

h1,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(2rem, 5vw, 4.2rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 0.86;
}

.brand-file {
  color: var(--text);
}

.intro {
  margin-bottom: 0;
  color: var(--muted);
  font-size: clamp(1.02rem, 2vw, 1.3rem);
  letter-spacing: -0.025em;
}

.control-surface {
  margin-bottom: 18px;
}

.transport-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-top: 22px;
}

.transport-buttons,
.project-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 48px;
  padding: 10px 19px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--text);
  background: var(--surface);
  font-weight: 780;
  letter-spacing: -0.01em;
  box-shadow: 0 4px 12px rgb(28 29 31 / 8%);
  transition:
    background 130ms ease,
    border-color 130ms ease,
    color 130ms ease,
    transform 130ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:active:not(:disabled) {
  transform: translateY(0);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.button-primary {
  min-width: 112px;
  border-color: var(--accent);
  color: #f8faf9;
  background: var(--accent);
}

.button-primary:hover:not(:disabled) {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.button-secondary {
  border-color: var(--terracotta);
  color: #fff9f6;
  background: var(--terracotta);
}

.button-secondary:hover:not(:disabled) {
  border-color: var(--terracotta-dark);
  background: var(--terracotta-dark);
}

.button-quiet {
  border-color: var(--terracotta);
  color: var(--terracotta-dark);
  background: transparent;
  box-shadow: none;
}

.button-quiet:hover:not(:disabled) {
  color: #fff9f6;
  background: var(--terracotta);
}

.button-export {
  border-color: var(--ochre);
  color: #fefefe;
  background: var(--ochre);
}

.button-export:hover:not(:disabled) {
  border-color: var(--ochre-dark);
  color: #fffaf2;
  background: var(--ochre-dark);
}

.control-layout {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) 190px;
  gap: 28px;
  align-items: stretch;
}

.sequence-controls {
  grid-column: 1;
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  padding: 4px 0;
}

.sequence-control-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.field-group {
  display: grid;
  min-width: 0;
  gap: 5px;
}

.field-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.select-wrap,
.number-control {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface);
}

select {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 0 38px 0 13px;
  border: 0;
  border-radius: inherit;
  color: var(--text);
  background: transparent;
  font-weight: 690;
}

.number-control {
  gap: 5px;
  padding-right: 10px;
}

.number-control input {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 0 2px 0 12px;
  border: 0;
  border-radius: inherit;
  color: var(--text);
  background: transparent;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.number-control span {
  flex: 0 0 auto;
  color: var(--faint);
  font-size: 0.68rem;
  font-weight: 820;
  letter-spacing: 0.06em;
}

.synth-module {
  grid-column: 2;
  justify-self: center;
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: rgb(247 247 245 / 48%);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 50%);
}

.synth-controls {
  display: grid;
  grid-template-columns: 244px 234px;
  gap: 20px;
  align-items: center;
}

.filter-knobs {
  display: grid;
  grid-template-columns: repeat(3, 76px);
  gap: 8px;
  justify-content: start;
}

.knob-control {
  display: grid;
  justify-items: center;
  min-width: 0;
  gap: 6px;
}

.knob-control .field-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.knob {
  --knob-angle: -45deg;
  position: relative;
  display: grid;
  width: 58px;
  height: 58px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: ns-resize;
  touch-action: none;
}

.knob::before {
  position: absolute;
  width: 66px;
  height: 66px;
  border: 1px solid #c8c8c3;
  border-radius: 50%;
  content: "";
}

.knob-face {
  position: relative;
  display: block;
  width: 56px;
  height: 56px;
  border: 1px solid #282b2e;
  border-radius: 50%;
  background:
    radial-gradient(circle at 37% 32%, #4e5255 0 8%, #303336 34%, #202225 72%);
  box-shadow:
    0 5px 9px rgb(27 28 29 / 25%),
    inset 0 1px 1px rgb(255 255 255 / 18%);
}

.knob-indicator {
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  transform: rotate(var(--knob-angle));
}

.knob-indicator::before {
  position: absolute;
  top: 0;
  left: 50%;
  width: 3px;
  height: 14px;
  border-radius: 3px;
  background: var(--ochre);
  content: "";
  transform: translateX(-50%);
}

.knob-resonance .knob-indicator::before {
  background: var(--terracotta);
}

.knob-envelope .knob-indicator::before {
  background: var(--accent);
}

.knob.is-dragging .knob-face {
  box-shadow:
    0 7px 14px rgb(27 28 29 / 30%),
    0 0 0 3px rgb(98 119 137 / 18%),
    inset 0 1px 1px rgb(255 255 255 / 18%);
}

.knob-value {
  color: var(--text);
  font-size: 0.69rem;
  font-weight: 790;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.envelope-panel {
  justify-self: start;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.adsr-controls {
  display: grid;
  grid-template-columns: repeat(4, 54px);
  gap: 6px;
  justify-content: start;
  min-height: 154px;
}

.adsr-slider {
  display: grid;
  grid-template-rows: auto 116px;
  justify-items: center;
  min-width: 0;
  gap: 8px;
}

.adsr-meta {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: flex-start;
  gap: 1px;
  color: var(--muted);
  font-size: 0.66rem;
  font-variant-numeric: tabular-nums;
}

.adsr-meta strong {
  color: var(--text);
  font-size: 0.76rem;
}

.adsr-meta output {
  min-width: 54px;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.adsr-slider input[type="range"] {
  width: 6px;
  height: 116px;
  margin: 0;
  border-radius: 999px;
  appearance: none;
  background: #c9c9c4;
  cursor: ns-resize;
  direction: rtl;
  accent-color: var(--accent);
  writing-mode: vertical-lr;
}

.adsr-slider input[type="range"]::-webkit-slider-thumb {
  width: 17px;
  height: 17px;
  border: 2px solid #f6f5f1;
  border-radius: 50%;
  appearance: none;
  background: var(--accent-strong);
  box-shadow: 0 2px 5px rgb(28 29 31 / 24%);
}

.adsr-slider input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid #f6f5f1;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow: 0 2px 5px rgb(28 29 31 / 24%);
}

.adsr-slider:nth-child(2) input[type="range"]::-webkit-slider-thumb {
  background: var(--ochre);
}

.adsr-slider:nth-child(2) input[type="range"]::-moz-range-thumb {
  background: var(--ochre);
}

.adsr-slider:nth-child(3) input[type="range"]::-webkit-slider-thumb {
  background: var(--terracotta);
}

.adsr-slider:nth-child(3) input[type="range"]::-moz-range-thumb {
  background: var(--terracotta);
}

.adsr-slider:nth-child(4) input[type="range"]::-webkit-slider-thumb {
  background: var(--accent);
}

.adsr-slider:nth-child(4) input[type="range"]::-moz-range-thumb {
  background: var(--accent);
}

.sequencer-panel {
  overflow: hidden;
}

.sequencer-scroll {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-large);
  background: #ffffff;
  scrollbar-color: #909498 #e7e7e4;
  scrollbar-width: thin;
}

.timeline,
.piano-roll {
  display: grid;
  width: 100%;
}

.steps-4 {
  grid-template-columns: 76px repeat(4, minmax(70px, 1fr));
  min-width: 430px;
}

.steps-8 {
  grid-template-columns: 76px repeat(8, minmax(62px, 1fr));
  min-width: 610px;
}

.steps-16 {
  grid-template-columns: 76px repeat(16, minmax(54px, 1fr));
  min-width: 990px;
}

.timeline {
  min-height: 48px;
  border-bottom: 1px solid #3b424b;
  background: var(--surface-dark);
}

.timeline-label,
.step-header {
  display: grid;
  min-width: 0;
  border-right: 1px solid #29313a;
}

.timeline-label {
  background: #121820;
}

.step-header {
  grid-template-rows: 1fr;
  align-items: end;
  padding: 6px 0 8px;
  text-align: left;
}

.step-header.measure-start,
.step-cell.measure-start {
  border-left: 2px solid var(--line-strong);
}

.step-header.is-current {
  background: #29323d;
}

.measure-number {
  align-self: end;
  min-height: 21px;
  padding-left: 9px;
  color: #8194a4;
  font-size: 0.78rem;
  font-weight: 820;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.step-header.is-current .measure-number {
  color: #d7e0e7;
}

.piano-roll {
  grid-auto-rows: 31px;
}

.note-label {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 8px 0 18px;
  border-right: 1px solid var(--line-strong);
  border-bottom: 1px solid #d7d8d7;
  color: #aeb4ba;
  background: #ffffff;
  font-size: 0.72rem;
  font-weight: 780;
  font-variant-numeric: tabular-nums;
}

.note-label.is-accidental {
  color: #e7ebef;
  background: #121416;
}

.note-label.is-c {
  color: var(--accent-strong);
}

.note-label.is-octave-divider {
  border-bottom: 2px solid var(--line-strong);
}

.step-cell {
  display: grid;
  min-width: 0;
  padding: 0;
  place-items: center;
  border: 0;
  border-right: 1px solid #d0d2d3;
  border-bottom: 1px solid #dadbdc;
  border-radius: 0;
  background: #ffffff;
  touch-action: none;
  user-select: none;
  transition: background 80ms ease, box-shadow 80ms ease;
}

.step-cell.is-accidental {
  background: #ededec;
}

.step-cell.is-octave-divider {
  border-bottom: 2px solid var(--line-strong);
}

.step-cell:hover {
  background: #e3e8e9;
}

.step-cell:focus-visible {
  outline: none;
  box-shadow: none;
}

.is-keyboard-navigation .step-cell:focus-visible {
  box-shadow: inset 0 0 0 1px rgb(67 91 109 / 56%);
}

.cell-note {
  display: block;
  width: auto;
  height: 8px;
  margin: 0 6px;
  justify-self: stretch;
  border-radius: 4px;
  background: transparent;
  transition:
    height 100ms ease,
    margin 100ms ease,
    border-radius 100ms ease,
    background 100ms ease;
}

.step-cell.is-active {
  background: var(--accent-soft);
}

.step-cell.is-active .cell-note {
  height: 17px;
  background: var(--accent);
}

.step-cell.is-active.continues-from-previous .cell-note {
  margin-left: -1px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.step-cell.is-active.continues-to-next .cell-note {
  margin-right: -1px;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.step-cell.is-current {
  box-shadow: inset 0 0 0 2px var(--playhead);
  background: #eee;
}

.step-cell.is-active.is-current {
  background: #ddd;
}

.step-cell.is-active.is-current .cell-note {
  background: #999;
}

.help-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 13px 2px 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.help-row p {
  margin-bottom: 0;
}

.keyboard-hint {
  flex: 0 0 auto;
}

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 2px 0;
  color: var(--muted);
  font-size: 0.74rem;
}

.app-footer p {
  margin-bottom: 0;
}

.live-message {
  color: var(--accent-strong);
  text-align: right;
}

noscript {
  display: block;
  padding: 20px;
  color: var(--danger);
  text-align: center;
}

@media (max-width: 1180px) {
  .control-layout {
    grid-template-columns: 190px minmax(0, 1fr) 190px;
    gap: 18px;
  }

  .synth-controls {
    grid-template-columns: 244px 234px;
    gap: 18px;
  }
}

@media (max-width: 1040px) {
  .control-layout {
    grid-template-columns: 1fr;
  }

  .sequence-controls {
    grid-column: auto;
    max-width: 190px;
  }

  .synth-module {
    grid-column: auto;
    justify-self: center;
  }

  .synth-controls {
    grid-template-columns: 244px minmax(0, 1fr);
    gap: 22px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 24px, 1600px);
    padding-top: 34px;
  }

  .app-header {
    margin-bottom: 36px;
  }

  .transport-row,
  .app-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .transport-buttons,
  .project-actions {
    width: 100%;
  }

  .button {
    flex: 1 1 auto;
  }

  .synth-controls {
    grid-template-columns: 1fr;
  }

  .synth-module {
    width: 100%;
  }

  .filter-knobs {
    justify-content: center;
    width: 100%;
  }

  .adsr-controls {
    grid-template-columns: repeat(4, 54px);
    gap: 6px;
    justify-content: center;
  }

  .help-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .live-message {
    text-align: left;
  }
}

@media (max-width: 480px) {
  .app-shell {
    width: min(100% - 18px, 1600px);
  }

  .sequence-control-grid {
    grid-template-columns: 1fr;
  }

  .synth-module {
    padding: 14px;
  }

  .adsr-controls {
    grid-template-columns: repeat(4, 52px);
    gap: 4px;
  }

  .sequencer-scroll {
    border-radius: var(--radius-medium);
  }

  .keyboard-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
