:root {
  color-scheme: dark;
  --bg: #101214;
  --panel: #171b1f;
  --panel-2: #20262b;
  --line: #323b43;
  --text: #edf2f4;
  --muted: #a7b2ba;
  --cyan: #36d6d6;
  --coral: #ff6b5f;
  --gold: #ffd166;
  --mint: #6ee7a6;
  --ink: #07090b;
  --danger: #f05d72;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: minmax(292px, 336px) minmax(0, 1fr);
  height: 100vh;
  min-height: 640px;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #12161a;
  overflow-y: auto;
  padding: 18px;
}

.brand {
  padding: 4px 2px 16px;
}

.brand h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.05;
  letter-spacing: 0;
}

.brand p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
}

.panel h2 {
  margin: 0 0 12px;
  color: #d9e1e5;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid #3a454e;
  border-radius: 6px;
  background: #0f1316;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus,
button:focus-visible,
canvas:focus-visible {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(54, 214, 214, 0.18);
}

input[type="range"] {
  min-height: 24px;
  padding: 0;
  accent-color: var(--cyan);
}

.file-drop {
  align-items: center;
  justify-items: center;
  min-height: 82px;
  border: 1px dashed #52606b;
  border-radius: 8px;
  background: #0d1114;
  color: var(--text);
  cursor: pointer;
}

.small-drop {
  min-height: 48px;
}

.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.audio-name {
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.segment,
button {
  min-height: 38px;
  border: 1px solid #3a454e;
  border-radius: 6px;
  background: #11171b;
  color: var(--text);
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

button:hover {
  border-color: #60707b;
  background: #182026;
}

button:active {
  transform: translateY(1px);
}

.segment.active {
  border-color: var(--cyan);
  background: rgba(54, 214, 214, 0.15);
  color: #edffff;
}

.compact-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.compact-grid h2 {
  grid-column: 1 / -1;
  margin-bottom: 0;
}

.slider-label {
  grid-template-columns: 74px 1fr 46px;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
}

.slider-label span {
  color: #dbe5e9;
  text-align: right;
  font-size: 12px;
}

.check-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 9px;
  min-height: 28px;
  margin-bottom: 8px;
  color: #dce5e9;
}

.check-row input {
  width: 16px;
  min-height: 16px;
  padding: 0;
  accent-color: var(--cyan);
}

.mini-note {
  margin: -2px 0 4px 27px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.actions {
  display: grid;
  gap: 8px;
}

.actions h2 {
  margin-bottom: 2px;
}

.primary {
  border-color: transparent;
  background: var(--cyan);
  color: var(--ink);
  font-weight: 800;
}

.primary:hover {
  border-color: transparent;
  background: #65eeee;
}

.secondary {
  background: var(--panel-2);
}

.danger {
  border-color: rgba(240, 93, 114, 0.45);
  color: #ffd3da;
}

.edit-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.edit-grid h2,
.edit-grid .check-row,
.edit-grid label {
  grid-column: 1 / -1;
}

.edit-grid button {
  min-width: 0;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  background:
    linear-gradient(90deg, rgba(255, 209, 102, 0.05), transparent 32%),
    linear-gradient(180deg, #101417, #0c0f12);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 74px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

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

.status-text {
  margin-top: 4px;
  color: #f5fafc;
  font-size: 16px;
  overflow-wrap: anywhere;
}

.meters {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: 8px;
  min-width: 260px;
}

.meters div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(15, 19, 22, 0.74);
  text-align: right;
}

.meters span {
  display: block;
  color: #ffffff;
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

.meters small {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.stage-shell {
  position: relative;
  min-height: 0;
  padding: 18px;
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 420px;
  border: 1px solid #2c363d;
  border-radius: 8px;
  background: #07090b;
  touch-action: none;
}

.stage-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(520px, calc(100% - 64px));
  transform: translate(-50%, -50%);
  color: rgba(237, 242, 244, 0.82);
  text-align: center;
  font-size: 16px;
  line-height: 1.45;
  pointer-events: none;
}

.stage-hint.hidden {
  display: none;
}

.transport {
  display: grid;
  gap: 10px;
  padding: 0 20px calc(18px + env(safe-area-inset-bottom));
}

.touch-dock {
  display: none;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.touch-dock button,
.touch-dock select,
.touch-load {
  min-height: 46px;
}

.touch-load {
  display: grid;
  align-items: center;
  justify-items: center;
  border: 1px solid #3a454e;
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

.touch-load input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.timeline {
  position: relative;
  height: 12px;
  overflow: hidden;
  border: 1px solid #2d363d;
  border-radius: 8px;
  background: #12171b;
}

#timelineProgress {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--gold));
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 50%;
  vertical-align: -1px;
}

.swatch.raw {
  background: var(--coral);
}

.swatch.quantized {
  background: var(--cyan);
}

.swatch.assist {
  background: var(--gold);
}

.swatch.flow {
  background: var(--mint);
}

@media (max-width: 1180px) {
  body {
    overflow: auto;
  }

  .app {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  .workspace {
    order: 1;
    min-height: 0;
    height: 100dvh;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .sidebar {
    order: 2;
    border-right: 0;
    border-top: 1px solid var(--line);
    max-height: 42dvh;
    padding: 12px;
  }

  .topbar {
    min-height: 0;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    gap: 10px;
  }

  .meters {
    min-width: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .meters div {
    padding: 7px 8px;
  }

  .status-text {
    font-size: 14px;
  }

  .stage-shell {
    padding: 10px 10px 8px;
  }

  #stage {
    min-height: 0;
    height: 100%;
    border-radius: 6px;
  }

  .stage-hint {
    width: min(440px, calc(100% - 36px));
    font-size: 14px;
  }

  .transport {
    padding: 0 10px calc(10px + env(safe-area-inset-bottom));
  }

  .touch-dock {
    display: grid;
  }

  button,
  input,
  select,
  .file-drop {
    min-height: 44px;
  }
}

@media (max-width: 560px) {
  .topbar {
    padding-top: calc(8px + env(safe-area-inset-top));
  }

  .meters span {
    font-size: 15px;
  }

  .meters small {
    font-size: 10px;
  }

  .touch-dock {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .legend {
    gap: 8px;
    font-size: 11px;
  }

  .sidebar {
    max-height: 48dvh;
  }

  .brand h1 {
    font-size: 22px;
  }
}
