:root {
  color-scheme: dark;
  --bg: #090a12;
  --panel: #11131e;
  --panel-2: #181a2a;
  --line: #303449;
  --text: #fff7ea;
  --muted: #b9b0c8;
  --dim: #77738a;
  --hot: #ff9f3f;
  --acid: #ccff4f;
  --cyan: #54dbff;
  --pink: #ff62c7;
  --red: #ff5d5d;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  overscroll-behavior-y: none;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(255, 159, 63, 0.12), transparent 36%),
    radial-gradient(circle at 82% 8%, rgba(84, 219, 255, 0.18), transparent 24%),
    radial-gradient(circle at 12% 24%, rgba(255, 98, 199, 0.12), transparent 22%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
}

button, input, select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  min-height: 40px;
  border-radius: 7px;
  padding: 0 14px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, background 0.12s, box-shadow 0.12s;
}

button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:hover { border-color: color-mix(in srgb, var(--cyan), white 12%); }

.app-shell {
  position: relative;
  width: min(1180px, 100vw);
  margin: 0 auto;
  padding: 18px;
  overflow-x: hidden;
}

.kit-flash {
  pointer-events: none;
  position: fixed;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%) scale(0.86) rotate(-3deg);
  z-index: 100;
  opacity: 0;
  min-width: min(520px, 82vw);
  padding: 26px 32px;
  border: 5px solid #090a12;
  border-radius: 18px;
  background: var(--acid);
  color: #090a12;
  box-shadow: 12px 12px 0 rgba(0,0,0,0.42);
  font-family: var(--sans);
  font-size: clamp(42px, 14vw, 112px);
  font-weight: 950;
  line-height: 0.9;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0;
}

.kit-flash.show {
  animation: kit-pop 0.9s cubic-bezier(.18,.9,.24,1) both;
}

@keyframes kit-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.64) rotate(-8deg); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.05) rotate(2deg); }
  72% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-2deg); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.08) rotate(3deg); }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}

.eyebrow, .section-label {
  margin: 0 0 4px;
  color: var(--hot);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 5vw, 42px);
  line-height: 1;
  letter-spacing: 0;
}

.icon-button {
  width: 44px;
  min-width: 44px;
  padding: 0;
  color: var(--red);
}

.transport {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.primary-button {
  background: linear-gradient(135deg, var(--hot), #ffd166);
  color: #15100b;
  border-color: var(--hot);
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(255, 159, 63, 0.16);
}

.primary-button.recording {
  background: var(--red);
  border-color: var(--red);
  color: white;
}

.start-here {
  background: var(--acid);
  border-color: var(--acid);
  color: #090a12;
  font-weight: 900;
  box-shadow: 0 0 0 0 rgba(204, 255, 79, 0.42);
  animation: start-pulse 1.6s ease-in-out infinite;
}

@keyframes start-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(204, 255, 79, 0.38); }
  50% { box-shadow: 0 0 0 6px rgba(204, 255, 79, 0); }
}

.recording-export {
  background: var(--red);
  border-color: var(--red);
  color: white;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.mic-recording {
  background: var(--red);
  border-color: var(--red);
  color: white;
  font-weight: 800;
}

.meter {
  grid-column: 1 / -1;
  height: 8px;
  border-radius: 999px;
  background: #070808;
  overflow: hidden;
  border: 1px solid var(--line);
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--hot), var(--acid));
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 8px 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(13, 15, 24, 0.78);
  padding: 6px;
}

.tab {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tab.active {
  color: #0b0c0d;
  background: linear-gradient(135deg, var(--acid), var(--cyan));
  border-color: var(--acid);
  font-weight: 800;
}

.panel {
  display: none;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(24, 26, 42, 0.92), rgba(13, 15, 24, 0.92));
  border-radius: 8px;
  padding: 10px;
}

.panel.active { display: block; }

.pad-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  touch-action: pan-y;
}

.pad {
  min-height: 118px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px;
  text-align: left;
  position: relative;
  overflow: hidden;
  background: var(--pad-color);
  color: var(--pad-text);
  border: 3px solid var(--pad-text);
  touch-action: pan-y;
  user-select: none;
  box-shadow: 6px 6px 0 rgba(0,0,0,0.32);
}

.pad.active {
  transform: translate(-2px, -2px) scale(1.015);
  box-shadow:
    10px 10px 0 rgba(0,0,0,0.36),
    0 0 0 3px #fff;
}

.pad strong {
  position: relative;
  font-size: 19px;
  letter-spacing: 0;
  text-shadow: none;
}

.pad span {
  position: relative;
  color: color-mix(in srgb, var(--pad-text), transparent 18%);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.quick-controls, .input-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, auto)) minmax(220px, 1fr);
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.input-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.quick-controls label {
  min-width: 220px;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--hot);
}

select {
  min-height: 38px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 0 10px;
}

.compact-select {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.sequence-head, .noise-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.sequence-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.muted {
  color: var(--muted);
  margin: 0;
}

.sequencer-wrap {
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-color: var(--hot) #090b12;
}

.bar-ruler {
  display: grid;
  gap: 5px;
  align-items: center;
  min-width: max-content;
  margin-bottom: 6px;
}

.ruler-spacer {
  position: sticky;
  left: 0;
  z-index: 3;
  height: 20px;
  background: #0d0f18;
}

.bar-marker {
  height: 20px;
  border-left: 3px solid var(--cyan);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding-left: 8px;
}

.sequencer {
  min-width: max-content;
}

.seq-row {
  display: grid;
  grid-template-columns: 92px repeat(16, 34px);
  gap: 5px;
  align-items: center;
  margin-bottom: 6px;
}

.seq-name {
  position: sticky;
  left: 0;
  z-index: 2;
  min-height: 34px;
  display: flex;
  align-items: center;
  background: #0d0f18;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.cell {
  width: 34px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #090b12;
}

.cell.bar-start {
  border-left-width: 3px;
  border-left-color: var(--cyan);
}

.cell.on {
  background: var(--voice-color, var(--hot));
  border-color: var(--voice-color, var(--hot));
  box-shadow: 0 0 14px color-mix(in srgb, var(--voice-color, var(--hot)), transparent 62%);
}
.cell.playhead {
  border-color: var(--acid);
  box-shadow: inset 0 0 0 2px var(--acid), 0 0 14px rgba(204, 255, 79, 0.28);
}

.cell.on.playhead {
  box-shadow: inset 0 0 0 2px #090a12, 0 0 0 3px var(--acid), 0 0 14px rgba(204, 255, 79, 0.34);
}

.capture-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #0d0f18;
}

.capture-status span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--panel-2);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.capture-status.capturing span {
  background: var(--red);
  color: white;
}

.capture-status strong {
  color: var(--text);
  font-size: 13px;
  text-align: right;
}

.saved-loops {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.saved-loop-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.saved-loop {
  display: grid;
  grid-template-columns: 1fr 30px;
  gap: 6px;
}

.saved-loop button:first-child {
  min-height: 76px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  border-left: 4px solid var(--hot);
  background:
    linear-gradient(90deg, rgba(255, 159, 63, 0.12), transparent 58%),
    var(--panel-2);
}

.saved-badges {
  display: flex;
  gap: 6px;
  margin-bottom: 7px;
  color: inherit;
}

.saved-loop em {
  color: var(--hot);
  font-family: var(--mono);
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 2px 6px;
}

.saved-song button:first-child {
  border-color: color-mix(in srgb, var(--cyan), var(--line) 45%);
  border-left-color: var(--cyan);
  background:
    linear-gradient(90deg, rgba(84, 219, 255, 0.12), transparent 58%),
    var(--panel-2);
}

.saved-song em {
  color: var(--cyan);
}

.saved-loop .mic-badge {
  color: var(--pink);
}

.saved-loop strong {
  font-size: 14px;
  line-height: 1.15;
}

.saved-loop span {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.delete-loop {
  padding: 0;
  color: var(--red);
  font-size: 15px;
  opacity: 0.62;
  min-height: 30px;
  align-self: start;
}

.delete-loop:hover {
  opacity: 1;
}

.empty-saved {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.arrange-actions {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.song-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.song-section {
  min-height: 92px;
  border: 1px solid var(--section-color, var(--line));
  border-radius: 8px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--section-color, var(--panel-2)) 20%, transparent), transparent 70%),
    var(--panel-2);
  color: var(--text);
  padding: 10px;
  text-align: left;
}

.song-section.kind-current { --section-color: var(--hot); }
.song-section.kind-mutate { --section-color: var(--cyan); }
.song-section.kind-quiet { --section-color: #9bffea; }
.song-section.kind-chaos { --section-color: var(--pink); }

.song-section.playing {
  background: var(--acid);
  border-color: var(--acid);
  color: #090a12;
  box-shadow: 0 0 0 3px rgba(204, 255, 79, 0.18);
}

.song-main {
  width: 100%;
  min-height: 66px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
  box-shadow: none;
}

.song-main:hover {
  border-color: transparent;
}

.song-section small {
  display: block;
  margin-bottom: 8px;
  color: var(--section-color, var(--muted));
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.song-section.playing small {
  color: #090a12;
}

.song-section strong {
  display: block;
  font-size: 22px;
  line-height: 1;
}

.song-section span {
  display: block;
  margin-top: 8px;
  color: currentColor;
  opacity: 0.72;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.song-tools {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 10px;
}

.song-tools button {
  min-height: 32px;
  padding: 0;
  color: inherit;
  font-size: 16px;
}

.empty-song {
  grid-column: 1 / -1;
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

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

.input-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d0f18;
  padding: 12px;
}

.input-head {
  margin-bottom: 10px;
}

.dropzone {
  min-height: 170px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(84, 219, 255, 0.08), rgba(255, 98, 199, 0.07)),
    #0d0f18;
  display: grid;
  place-items: center;
  text-align: center;
  cursor: pointer;
  color: var(--text);
}

.dropzone input { display: none; }
.dropzone small { display: block; margin-top: 8px; color: var(--muted); }
.dropzone.over { border-color: var(--acid); }

.mic-pad {
  min-height: 170px;
  border: 3px solid #ff6b6b;
  border-radius: 8px;
  background: #ff6b6b;
  color: #1c0505;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px;
  box-shadow: 6px 6px 0 rgba(0,0,0,0.26);
}

.mic-pad strong {
  font-size: 24px;
  line-height: 1;
}

.mic-pad span {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#imageCanvas, #scopeCanvas {
  width: 100%;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #070913;
}

#imageCanvas { min-height: 210px; }

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

.voice-card {
  background: linear-gradient(180deg, rgba(22, 24, 38, 0.98), rgba(11, 13, 21, 0.98));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  border-top: 4px solid var(--hot);
}

.voice-card h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.voice-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.voice-card-head h3 {
  margin: 0;
}

.voice-card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.voice-card-actions button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.voice-card-actions button.on {
  background: var(--acid);
  border-color: var(--acid);
  color: #090a12;
  font-weight: 800;
}

.voice-card label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

.noise-image {
  margin-top: 12px;
  border: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(255, 159, 63, 0.1), rgba(84, 219, 255, 0.1)),
    rgba(17, 19, 30, 0.82);
  border-radius: 8px;
  padding: 10px;
}

.noise-head {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#scopeCanvas {
  height: 74px;
}

@media (max-width: 760px) {
  .app-shell {
    padding: max(12px, env(safe-area-inset-top)) 12px calc(184px + env(safe-area-inset-bottom));
  }
  .topbar {
    margin-bottom: 10px;
  }
  .transport {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 30;
    grid-template-columns: 1fr 1fr;
    padding: 8px;
    border: 1px solid color-mix(in srgb, var(--line), white 8%);
    border-radius: 10px;
    background: rgba(13, 15, 24, 0.92);
    box-shadow: 0 12px 34px rgba(0,0,0,0.36);
    backdrop-filter: blur(16px);
  }
  .transport button { min-height: 46px; }
  #exportBtn { grid-column: 1 / -1; }
  button { min-width: 0; padding-inline: 10px; }
  .panel { padding: 10px; }
  .quick-controls, .input-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #replayMicBtn { grid-column: 1 / -1; }
  .quick-controls label { min-width: 0; }
  .quick-controls > label:last-child { grid-column: 1 / -1; }
  .capture-status { align-items: flex-start; flex-direction: column; }
  .capture-status strong { text-align: left; }
  .saved-loop-list { grid-template-columns: 1fr; }
  .sequence-head { align-items: flex-start; flex-direction: column; }
  .sequence-actions { width: 100%; justify-content: stretch; }
  .sequence-actions > * { flex: 1; }
  .pad-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .pad { min-height: 102px; padding: 10px; }
  .pad strong { font-size: 15px; }
  .tabs { grid-template-columns: repeat(3, 1fr); }
  .arrange-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .song-strip { grid-template-columns: 1fr 1fr; }
  .input-grid { grid-template-columns: 1fr; }
  .orchestra-list { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .app-shell { padding-inline: 10px; }
  .pad-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pad { min-height: 108px; }
  .quick-controls { gap: 7px; }
  .quick-controls button { min-height: 44px; font-size: 15px; }
  .compact-select { min-width: 0; }
  .compact-select select { min-width: 0; width: 100%; }
  .song-strip { grid-template-columns: 1fr; }
  .arrange-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
