:root {
  --bg: #1c1c1c; --panel: #262626; --panel2: #303030; --text: #efe8d8; --dim: #9a958c;
  --red: #e2412e; --orange: #f28c28; --yellow: #f2d43a; --cream: #efe8d8; --led: #ff3b2a;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column; background: var(--bg); color: var(--text); overscroll-behavior: none;
  font: 12px/1.25 "Helvetica Neue", Arial, sans-serif; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) 0 env(safe-area-inset-left, 0);
}
button { font: inherit; color: inherit; border: 0; }
[hidden] { display: none !important; }

/* header */
.top { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px 6px;
  background: linear-gradient(#2c2c2c, var(--bg)); border-bottom: 2px solid #000; }
.rc { font: italic 600 11px/1 "Helvetica Neue", Arial, sans-serif; color: var(--orange); letter-spacing: .5px; }
.model { font-weight: 800; font-size: 24px; letter-spacing: 1px; line-height: 1.05; }
.model small { font-size: 10px; font-weight: 600; color: var(--dim); margin-left: 4px; letter-spacing: 2px; }
.tempo { display: flex; align-items: center; gap: 4px; }
.led { min-width: 74px; padding: 3px 8px; background: #120606; border: 2px solid #000; border-radius: 3px; text-align: right; touch-action: none; cursor: ns-resize; }
.led span { font: 700 24px/1 ui-monospace, Menlo, monospace; color: var(--led); text-shadow: 0 0 6px rgba(255,59,42,.7); }
.led small { display: block; font-size: 7px; color: #8a3a32; letter-spacing: 1px; }
.tbtn { width: 34px; height: 34px; border-radius: 4px; background: var(--panel2); font-size: 18px; box-shadow: 0 2px 0 #000; }
.tbtn.tap { width: auto; padding: 0 8px; font-size: 11px; font-weight: 700; letter-spacing: 1px; }
.tbtn:active { transform: translateY(2px); box-shadow: none; }

/* transport */
.transport { flex: 0 0 auto; display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--panel); }
.play { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 4px; background: var(--cream); color: #111;
  font-weight: 800; letter-spacing: 1px; box-shadow: 0 3px 0 #8f887a; }
.play i { width: 9px; height: 9px; border-radius: 50%; background: #5a1a14; }
.play[aria-pressed="true"] i { background: var(--led); box-shadow: 0 0 8px var(--led); }
.play:active { transform: translateY(3px); box-shadow: none; }
.mini { flex: 1; font-size: 9px; letter-spacing: 1px; color: var(--dim); }
.mini output, .knob output { float: right; color: var(--orange); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 26px; margin: 0; background: transparent; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: #474747; }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: #474747; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -8px; border-radius: 50%; background: var(--cream); border: 3px solid #555; }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--cream); border: 3px solid #555; }

/* patterns */
.patterns { flex: 0 0 auto; display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; padding: 6px 12px; background: var(--panel); }
.pat { position: relative; padding: 5px 2px 4px; border-radius: 3px; background: var(--panel2); text-align: center; box-shadow: 0 2px 0 #000; }
.pat b { display: block; font-size: 13px; } .pat span { display: block; font-size: 7px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pat[aria-pressed="true"] { background: var(--cream); color: #111; } .pat[aria-pressed="true"] span { color: #555; }
.pat.queued { outline: 2px dashed var(--orange); outline-offset: -2px; }

.modes { flex: 0 0 auto; display: flex; gap: 4px; padding: 6px 12px; background: var(--panel); border-bottom: 2px solid #000; }
.mode { flex: 1; padding: 7px 0; border-radius: 3px; background: var(--panel2); font-weight: 700; font-size: 11px; letter-spacing: 1px; }
.mode[aria-selected="true"] { background: var(--orange); color: #111; }
.mode.act { flex: .8; color: var(--dim); }
.mode:active { background: var(--cream); color: #111; }

main { flex: 1; overflow-y: auto; padding: 8px 12px calc(12px + var(--safe-b)); -webkit-overflow-scrolling: touch; }

/* instrument chips */
.insts { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.insts::-webkit-scrollbar { display: none; }
.inst { flex: 0 0 auto; min-width: 48px; padding: 5px 6px 4px; border-radius: 3px; background: var(--panel2); text-align: center; position: relative; }
.inst b { display: block; font-size: 13px; } .inst span { display: block; font-size: 7px; color: var(--dim); white-space: nowrap; }
.inst[aria-pressed="true"] { background: var(--cream); color: #111; } .inst[aria-pressed="true"] span { color: #555; }
.inst i, .pad i { position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: #4a1a15; }
.flash i { background: var(--led) !important; box-shadow: 0 0 6px var(--led); }

/* knobs */
.knobs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 2px 0 8px; min-height: 40px; }
.knob { font-size: 9px; letter-spacing: 1px; color: var(--dim); }
.knobs .note { grid-column: 1 / -1; color: var(--dim); font-size: 11px; padding-top: 8px; }

/* the 16 step keys */
.steps { touch-action: pan-y; display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px 5px; margin-bottom: 12px; }
.step { position: relative; height: 54px; border-radius: 4px; box-shadow: 0 3px 0 rgba(0,0,0,.6), inset 0 -6px 0 rgba(0,0,0,.12); }
.step:nth-child(-n+4) { background: var(--red); } .step:nth-child(n+5):nth-child(-n+8) { background: var(--orange); }
.step:nth-child(n+9):nth-child(-n+12) { background: var(--yellow); } .step:nth-child(n+13) { background: var(--cream); }
.step i { position: absolute; top: 6px; left: 50%; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: #4a1a15; border: 1px solid rgba(0,0,0,.4); }
.step.on i { background: var(--led); box-shadow: 0 0 8px var(--led), 0 0 2px #fff inset; }
.step span { position: absolute; bottom: 5px; left: 0; right: 0; text-align: center; font-size: 10px; font-weight: 700; color: rgba(0,0,0,.55); }
.step.now { filter: brightness(1.35); transform: translateY(1px); }
.step:active { transform: translateY(3px); box-shadow: none; }

/* overview of every track */
.grid { display: grid; grid-template-columns: 30px repeat(16, 1fr); gap: 2px; touch-action: pan-y; }
.grid .lab { font-size: 9px; font-weight: 700; color: var(--dim); align-self: center; padding: 3px 0; }
.grid .lab.sel { color: var(--orange); }
.cell { height: 20px; border-radius: 2px; background: #333; cursor: crosshair; }
.step { cursor: crosshair; }
.cell:nth-child(17n+6), .cell:nth-child(17n+10), .cell:nth-child(17n+14) { margin-left: 2px; }
.cell.on { background: var(--cream); }
.cell.on.ac { background: var(--red); }
.cell.now { box-shadow: inset 0 0 0 2px var(--orange); }
.row-sel { background: #3d3a35; } .row-sel.on { background: var(--orange); }

/* hint under the grid: mouse wording on computers, touch wording on phones */
.paint-hint { margin: 8px 0 0; font-size: 10px; color: var(--dim); text-align: center; }
.paint-hint .mouse { display: none; }
@media (hover: hover) and (pointer: fine) { .paint-hint .mouse { display: inline; } .paint-hint .touch { display: none; } }

/* pads */
.pads { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; touch-action: none; }
.pad { position: relative; aspect-ratio: 1; border-radius: 6px; background: #3a3a3a; box-shadow: 0 3px 0 #000; display: flex; flex-direction: column;
  align-items: center; justify-content: center; }
.pad b { font-size: 18px; } .pad span { font-size: 8px; color: var(--dim); margin-top: 2px; }
.pad.hit { background: var(--cream); color: #111; transform: translateY(3px); box-shadow: none; }
.pad.toggle[aria-pressed="true"] { background: var(--red); color: #fff; } .pad.toggle[aria-pressed="true"] span { color: #fdd; }
.pads .hint { grid-column: 1 / -1; color: var(--dim); font-size: 11px; text-align: center; }

@media (orientation: landscape) and (max-height: 520px) {
  .top { padding: 4px 12px; } .transport, .patterns, .modes { padding-top: 4px; padding-bottom: 4px; }
  .steps { grid-template-columns: repeat(16, 1fr); } .step { height: 46px; }
  .pads { grid-template-columns: repeat(8, 1fr); }
}
@media (min-width: 700px) and (orientation: portrait) { .steps { grid-template-columns: repeat(16, 1fr); } }
