:root {
  --bg: #0a0e1a;
  --bg-2: #111727;
  --panel: #131a2b;
  --panel-2: #182037;
  --line: #243049;
  --text: #e6ecf5;
  --muted: #8a96b3;
  --accent: #5cf2c0;
  --accent-2: #7aa2ff;
  --hot: #ff5d8f;
  --warn: #ffb454;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: radial-gradient(1200px 600px at 20% -10%, #1a2340 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

#error {
  display: none;
  background: var(--hot); color: #1a0010;
  padding: 10px 16px; font-weight: 600;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent);
  position: sticky; top: 0; z-index: 5;
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo {
  font-size: 28px; color: var(--accent);
  text-shadow: 0 0 12px rgba(92,242,192,0.55);
}
.brand h1 {
  margin: 0; font-size: 18px; letter-spacing: 0.18em;
  font-weight: 700;
}

.transport {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}

.btn {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s, border-color 0.15s;
}
.btn:hover { background: var(--panel-2); border-color: #324468; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(180deg, #1f3a55, #16273b);
  border-color: #2c4d72;
  color: var(--accent);
}
.btn.primary.active {
  box-shadow: 0 0 0 1px var(--accent), 0 0 18px rgba(92,242,192,0.35);
  color: #00120c;
  background: var(--accent);
  border-color: var(--accent);
}

.ctrl {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; color: var(--muted); min-width: 110px;
}
.ctrl span { display: flex; justify-content: space-between; }
.ctrl em { color: var(--text); font-style: normal; font-weight: 600; }
.ctrl input[type=range], .ctrl select {
  width: 100%;
}
select {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  padding: 6px 8px; border-radius: 6px;
}

#scope {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #060912;
  display: block;
}

main {
  padding: 18px 22px 36px;
  display: flex; flex-direction: column; gap: 18px;
  max-width: 1400px; margin: 0 auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 2px 0 rgba(0,0,0,0.25), 0 12px 32px rgba(0,0,0,0.25);
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.hint {
  margin: 10px 2px 0;
  font-size: 11px;
  color: var(--muted);
}
kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--text);
  font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 10px;
}

/* ---- Step grid ---- */
.grid {
  display: flex; flex-direction: column; gap: 6px;
}
.row {
  display: flex; align-items: center; gap: 10px;
}
.row-label {
  width: 88px; flex: 0 0 88px;
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
  display: flex; align-items: center; justify-content: space-between;
  gap: 6px;
}
.audition {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 4px; cursor: pointer;
  width: 22px; height: 22px; line-height: 1;
  font-size: 10px; padding: 0;
}
.audition:hover { border-color: var(--accent); color: var(--accent); }

.cells {
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  gap: 4px;
  flex: 1;
}
.cell {
  height: 36px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  font-size: 9px;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  user-select: none;
  transition: background 0.08s, border-color 0.08s, transform 0.05s;
}
.cell.beat { background: #1b243c; }
.cell:hover { border-color: #3b517a; }
.cell.on {
  background: linear-gradient(180deg, #2bd9a4, #1aa07a);
  border-color: #5cf2c0;
  color: #00170e;
  font-weight: 700;
  box-shadow: 0 0 12px rgba(92,242,192,0.35);
}
.row[data-track="synth"] .cell.on {
  background: linear-gradient(180deg, #7aa2ff, #4a73d6);
  border-color: #a5c0ff;
  color: #04102b;
  box-shadow: 0 0 12px rgba(122,162,255,0.4);
}
.cell.playing {
  outline: 2px solid var(--warn);
  outline-offset: -2px;
}

/* ---- Knob/control panels ---- */
.panels {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 18px;
}
@media (max-width: 980px) {
  .panels { grid-template-columns: 1fr; }
}

/* ---- Mobile (tablet) ---- */
@media (max-width: 768px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
    gap: 12px;
  }
  .brand { justify-content: center; }
  .brand h1 { font-size: 14px; }
  .transport {
    justify-content: center;
    gap: 8px;
  }
  .btn {
    min-height: 44px;
    padding: 8px 12px;
    font-size: 13px;
  }
  .ctrl { min-width: 100px; font-size: 11px; }
  #scope { width: 100%; max-width: 240px; }

  main { padding: 12px; gap: 12px; }
  .panel { padding: 12px; }

  /* Sequencer scrolls horizontally so 16 cells stay usable */
  .grid { gap: 8px; }
  .row { gap: 8px; }
  .row-label { width: 70px; flex: 0 0 70px; font-size: 10px; }
  .audition { min-width: 28px; min-height: 28px; }
  .cells {
    overflow-x: auto;
    grid-template-columns: repeat(16, 32px);
    -webkit-overflow-scrolling: touch;
  }
  .cell { height: 44px; min-width: 32px; font-size: 10px; }

  .knobs { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .knob { font-size: 10px; }

  .keyboard { height: 110px; }

  select, input[type=range] { min-height: 36px; }
}

/* ---- Mobile (phone) ---- */
@media (max-width: 480px) {
  .topbar { padding: 8px 10px; gap: 8px; }
  .brand h1 { font-size: 12px; letter-spacing: 0.12em; }
  .transport { gap: 6px; }
  .btn { padding: 8px 10px; font-size: 12px; min-height: 44px; }
  .ctrl { min-width: 88px; font-size: 10px; }
  #scope { display: none; }

  main { padding: 10px; gap: 10px; }
  .panel { padding: 10px; border-radius: 10px; }
  .panel h2 { font-size: 10px; margin-bottom: 8px; }

  .row-label { width: 56px; flex: 0 0 56px; font-size: 9px; letter-spacing: 0.04em; }
  .audition { min-width: 24px; min-height: 24px; font-size: 9px; }
  .cells { grid-template-columns: repeat(16, 28px); gap: 3px; }
  .cell { height: 44px; min-width: 28px; font-size: 9px; }

  .knobs { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .knob { font-size: 10px; }
  .knob span { font-size: 10px; }

  .keyboard { height: 90px; }
  .hint { font-size: 10px; }
  kbd { font-size: 9px; padding: 1px 4px; }
}
.knobs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px 14px;
}
.knob {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 10px; color: var(--muted);
}
.knob span { display: flex; justify-content: space-between; }
.knob em {
  color: var(--accent); font-style: normal; font-weight: 700;
  font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
}

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px;
  background: var(--line); border-radius: 3px;
  outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid #082018;
  box-shadow: 0 0 8px rgba(92,242,192,0.45);
  cursor: pointer;
}
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid #082018;
  box-shadow: 0 0 8px rgba(92,242,192,0.45);
  cursor: pointer; border-style: solid;
}

/* ---- On-screen keyboard ---- */
.keyboard-panel { padding-bottom: 22px; }
.keyboard {
  position: relative;
  display: flex;
  height: 140px;
  background: #060912;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
}
.key {
  flex: 1;
  background: linear-gradient(180deg, #f1f4fb, #c7cfe0);
  border: 1px solid #2a2f44;
  border-radius: 0 0 4px 4px;
  margin-right: 2px;
  cursor: pointer;
  transition: background 0.08s;
  position: relative;
}
.key:hover { background: linear-gradient(180deg, #fff, #d6dded); }
.key.pressed { background: linear-gradient(180deg, #5cf2c0, #2bd9a4); }
.key.black {
  position: absolute;
  top: 0;
  height: 62%;
  background: linear-gradient(180deg, #1a1f33, #0a0d18);
  border: 1px solid #000;
  border-radius: 0 0 4px 4px;
  z-index: 2;
  margin: 0;
  flex: none;
  box-shadow: 0 4px 8px rgba(0,0,0,0.5);
}
.key.black:hover { background: linear-gradient(180deg, #28304a, #131826); }
.key.black.pressed { background: linear-gradient(180deg, #2bd9a4, #1aa07a); }
