:root {
  color-scheme: dark;
  --bg: #101312;
  --surface: #18201f;
  --surface-strong: #202927;
  --surface-soft: #131918;
  --line: rgba(160, 186, 178, 0.28);
  --ink: #f5f1e7;
  --muted: #b7c0bb;
  --cyan: #7bd8c8;
  --gold: #e8c35e;
  --rose: #ef8b7b;
  --green: #95d379;
  --blue: #91baf2;
  --keyboard-height: 380px;
  --white-key-height: 364px;
  --black-key-height: 182px;
  --key-button-size: 23px;
  --key-label-height: 20px;
  --key-control-gap: 2px;
  --white-control-black-key-clearance: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="text"] {
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

button {
  min-height: 42px;
  padding: 8px 12px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: rgba(123, 216, 200, 0.62);
}

button:disabled {
  cursor: default;
  opacity: 0.48;
}

button[aria-pressed="true"],
button.primary-on {
  color: #101312;
  background: var(--cyan);
  border-color: rgba(123, 216, 200, 0.95);
}

.secondary-button {
  background: rgba(246, 241, 231, 0.04);
}

.secondary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid rgba(246, 241, 231, 0.18);
  border-radius: 6px;
  background: rgba(246, 241, 231, 0.04);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 700;
  padding: 10px 12px;
  text-align: center;
  text-decoration: none;
}

.secondary-link:hover {
  border-color: rgba(123, 216, 200, 0.62);
}

.hidden-ui {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 304px;
  gap: 10px;
  width: calc(100% - 12px);
  height: calc(100vh - 12px);
  margin: 6px auto;
  align-items: stretch;
  overflow: hidden;
}

.workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.keyboard-panel,
.edit-card,
.score-panel,
.panel,
.status {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.keyboard-panel {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.keyboard-range-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 12px;
  align-items: center;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 720;
}

.keyboard-range-row output {
  color: var(--text);
}

.keyboard-slider-shell {
  position: relative;
  grid-column: 1 / -1;
  height: 22px;
}

.keyboard-viewport-track,
#keyboardRangeControl {
  position: absolute;
  inset: 0;
}

.keyboard-viewport-track {
  top: 7px;
  height: 8px;
  border: 1px solid rgba(123, 216, 200, 0.28);
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(246, 241, 231, 0.16), rgba(246, 241, 231, 0.07));
  overflow: hidden;
}

.keyboard-viewport-thumb {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 20%;
  border-radius: 999px;
  background: linear-gradient(90deg, #7bd8c8, #95d379);
  box-shadow: 0 0 0 1px rgba(13, 17, 17, 0.45) inset;
}

#keyboardRangeControl {
  z-index: 2;
  width: 100%;
  opacity: 0;
  cursor: pointer;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--cyan);
}

.keyboard {
  position: relative;
  height: var(--keyboard-height);
  overflow: hidden;
  border: 1px solid rgba(123, 216, 200, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(123, 216, 200, 0.06), transparent 42%),
    linear-gradient(180deg, #111918, #0c100f);
}

.key {
  position: absolute;
  display: block;
  --key-accent: var(--cyan);
  user-select: none;
}

.white-key {
  z-index: 1;
  height: var(--white-key-height);
  color: #111312;
  background: linear-gradient(180deg, #fffaf0 0%, #efe8dc 100%);
  border: 1px solid #77817d;
  border-radius: 0 0 8px 8px;
}

.black-key {
  z-index: 3;
  height: var(--black-key-height);
  color: #f7f1e6;
  background: linear-gradient(180deg, #171d1c 0%, #090c0c 100%);
  border: 1px solid #46524f;
  border-radius: 0 0 6px 6px;
}

.key:hover,
.key:focus-visible {
  border-color: color-mix(in srgb, var(--key-accent) 72%, white);
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--key-accent) 62%, transparent) inset,
    0 0 14px color-mix(in srgb, var(--key-accent) 30%, transparent);
}

.key.latched {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--key-accent) 82%, white), var(--key-accent));
  color: #0d1111;
  border-color: color-mix(in srgb, var(--key-accent) 80%, white);
}

.key.sounding {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--key-accent) 76%, white) inset;
}

.key.latched.sounding {
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--key-accent) 80%, white) inset,
    0 0 18px color-mix(in srgb, var(--key-accent) 42%, transparent);
}

.key-label {
  display: grid;
  flex: 0 0 var(--key-label-height);
  place-items: center;
  width: var(--key-button-size);
  height: var(--key-label-height);
  margin: 0 auto;
  min-height: 0;
  padding: 0;
  font-weight: 820;
  font-size: 0.9rem;
  line-height: 1;
}

.black-key .key-label {
  color: #f7f1e6;
  font-size: 0.82rem;
}

.white-key .key-label {
  padding-bottom: 0;
}

.key-controls {
  position: absolute;
  right: 0;
  bottom: 6px;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--key-control-gap);
  padding: 0;
}

.white-key .key-controls {
  top: calc(var(--black-key-height) + var(--white-control-black-key-clearance));
  bottom: 12px;
  gap: var(--key-control-gap);
}

.black-key .key-controls {
  right: 0;
  bottom: 12px;
  left: 0;
  gap: var(--key-control-gap);
}

.key-control,
.key-duration,
.key-count {
  display: grid;
  flex: 0 0 var(--key-button-size);
  place-items: center;
  width: var(--key-button-size);
  height: var(--key-button-size);
  min-height: 0;
  padding: 0;
  border-radius: 9px;
  border: 1px solid rgba(17, 19, 18, 0.28);
  font-size: 1rem;
  font-weight: 880;
  line-height: 0.92;
}

.key-control {
  color: inherit;
  background: rgba(17, 19, 18, 0.16);
}

.black-key .key-control {
  border-color: rgba(246, 241, 231, 0.24);
  background: rgba(246, 241, 231, 0.24);
}

.black-key .key-control {
  min-height: 0;
  font-size: 0.96rem;
}

.black-key .key-duration {
  min-height: 0;
}

.white-key .key-control {
  font-size: 1rem;
}

.key-duration,
.key-count {
  background: rgba(232, 195, 94, 0.28);
  border-color: rgba(17, 19, 18, 0.34);
}

.key-duration {
  font-family: "Noto Music", "Bravura", "Segoe UI Symbol", serif;
  font-size: 1.62rem;
  font-weight: 900;
  line-height: 0.86;
}

.black-key .key-duration,
.black-key .key-count {
  border-color: rgba(232, 195, 94, 0.5);
  background: rgba(232, 195, 94, 0.34);
}

.black-key .key-duration {
  font-size: 1.46rem;
}

.white-key .key-duration {
  font-size: 1.62rem;
}

.key-count {
  font-size: 0.92rem;
  font-weight: 860;
}

.key:not(.has-count) .key-count {
  opacity: 0.58;
}

.key:hover .key-label,
.key:focus-visible .key-label,
.key:hover .key-duration,
.key:focus-visible .key-duration,
.key:hover .key-count,
.key:focus-visible .key-count,
.key.latched .key-label,
.key.latched .key-duration,
.key.latched .key-count,
.key.sounding .key-label,
.key.sounding .key-duration,
.key.sounding .key-count {
  color: color-mix(in srgb, var(--key-accent) 84%, white);
  border-color: color-mix(in srgb, var(--key-accent) 54%, white);
}

.white-key:hover .key-label,
.white-key:focus-visible .key-label,
.white-key.latched .key-label,
.white-key.sounding .key-label {
  color: color-mix(in srgb, var(--key-accent) 76%, #111312);
}

.key:hover .key-duration,
.key:focus-visible .key-duration,
.key:hover .key-count,
.key:focus-visible .key-count,
.key.latched .key-duration,
.key.latched .key-count,
.key.sounding .key-duration,
.key.sounding .key-count {
  background: color-mix(in srgb, var(--key-accent) 28%, rgba(232, 195, 94, 0.12));
}

.key.latched .key-duration,
.key.latched .key-count {
  color: #0d1111;
  background: color-mix(in srgb, var(--key-accent) 18%, #f8f0d9);
  border-color: color-mix(in srgb, var(--key-accent) 68%, #f8f0d9);
}

.slice-play-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.slice-play-row button {
  min-width: 160px;
}

.slice-text {
  min-height: 20px;
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 0.86rem;
}

.edit-strip {
  display: grid;
  grid-template-columns: minmax(360px, 560px) minmax(160px, 220px);
  gap: 10px;
  justify-content: center;
  justify-items: center;
  min-width: 0;
}

.duration-card {
  width: 100%;
}

.slice-action-card {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.slice-action-card button {
  flex: 1;
  min-height: 42px;
}

.edit-card,
.panel,
.status {
  padding: 12px 14px;
}

.panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.label,
.eyebrow {
  margin: 0;
  color: var(--cyan);
  font-size: 0.74rem;
  font-weight: 780;
  text-transform: uppercase;
}

.summary,
.status {
  color: var(--muted);
  font-size: 0.84rem;
}

.summary,
.status,
.brand h1,
.brand p,
.slice-text {
  margin: 0;
}

.notation-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(38px, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.notation-grid button {
  min-height: 42px;
  padding: 3px 6px;
}

.notation-glyph {
  font-family: "Noto Music", "Bravura", "Segoe UI Symbol", serif;
  font-size: 1.45rem;
  line-height: 1;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.button-row.two-up {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.score-panel {
  min-height: 0;
  overflow: auto;
}

#scoreCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.controls {
  position: sticky;
  top: 6px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 12px);
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 6px 0;
}

.brand-mark {
  width: 44px;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, #101312 0 8px, transparent 9px),
    conic-gradient(from 20deg, var(--cyan), var(--blue), var(--gold), var(--rose), var(--green), var(--cyan));
}

.brand h1 {
  font-size: 1.38rem;
  line-height: 1.05;
}

.panel {
  display: grid;
  gap: 10px;
}

.field-label,
.slider-row {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.84rem;
}

.field-label input,
.field-label select,
.panel select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
}

.line-grid,
.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.line-grid {
  grid-template-columns: 1fr;
}

.drum-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.drum-grid button:nth-child(5) {
  grid-column: 1 / -1;
}

.audio-tools-panel {
  margin-top: auto;
}

.mix-controls {
  display: grid;
  gap: 10px;
}

.mix-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.84rem;
}

.mix-row input {
  grid-column: 1 / -1;
}

.copyright-notice {
  margin: 0 2px 8px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - 12px);
    overflow: visible;
  }

  body {
    overflow: auto;
  }

  .edit-strip {
    grid-template-columns: 1fr;
  }

  .controls {
    position: static;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: none;
    overflow: visible;
  }

  .brand,
  .status {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .keyboard-range-row,
  .slice-play-row,
  .edit-strip,
  .controls {
    grid-template-columns: 1fr;
  }

  .notation-grid {
    grid-template-columns: repeat(5, minmax(42px, 1fr));
  }
}
