:root {
  --bg: #0f1115;
  --panel: #171a21;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --muted: #a7adbb;
  --accent: #ffb020;
  --accent-text: #1a1200;
  --rec: #ff4d4f;
  --pad: #232835;
  --pad-hit: #ffb020;
  --step-on: #ffb020;
  --step-off: #1d212b;
  --step-play: #3a4152;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, "SF Pro Text", Inter, system-ui, sans-serif; }
body { min-height: 100vh; display: flex; flex-direction: column; padding-bottom: 72px; }
h1 { font-size: 1.05rem; margin: 0 12px 0 0; letter-spacing: 0.02em; }
button, select, input, .button {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; min-height: 44px; padding: 0 14px; cursor: pointer;
}
button:hover, .button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
#record.on { background: var(--rec); border-color: var(--rec); color: #fff; }
input[type="number"], input[type="text"], input:not([type]) { cursor: text; }
.bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 2; }
.field { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.field span { font-size: 0.85rem; }
.field.grow { flex: 1; }
.field.grow input { width: 100%; }
.field input[type="number"] { width: 84px; }
.mode { margin-left: auto; display: inline-flex; border-radius: 8px; overflow: hidden; }
.mode button { border-radius: 0; }
.mode button:first-child { border-radius: 8px 0 0 8px; }
.mode button:last-child { border-radius: 0 8px 8px 0; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); min-height: 44px; }
main { padding: 16px; display: grid; gap: 16px; max-width: 1100px; width: 100%; margin: 0 auto; }
body[data-mode="simple"] .pro { display: none !important; }
body[data-mode="simple"] .pad { aspect-ratio: 2; max-height: 130px; }

.pads { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.pad {
  aspect-ratio: 2.6; min-height: 72px; max-height: 104px; border-radius: 12px; border: 2px solid var(--line); background: var(--pad);
  display: flex; flex-direction: column; justify-content: space-between; padding: 10px 12px; text-align: left; user-select: none;
  transition: transform 60ms, background 120ms, border-color 120ms; position: relative;
  cursor: pointer; color: var(--text); font: inherit;
}
.pad:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pad .name { font-weight: 600; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pad .key { color: var(--muted); font-size: 0.8rem; font-variant: small-caps; }
.pad.empty .name { color: var(--muted); font-weight: 400; }
.pad.selected { border-color: var(--accent); }
.pad.hit { background: var(--pad-hit); color: var(--accent-text); transform: scale(0.97); }
.pad.hit .key { color: var(--accent-text); }
.pad::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; border-radius: 12px 0 0 12px; background: var(--c, transparent); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 12px; }
.panel-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.pad-name { font-weight: 600; width: 200px; }
.key-hint { color: var(--muted); font-size: 0.85rem; }
.knobs { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.knob { display: grid; gap: 4px; }
.knob .label { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.85rem; }
.knob .label b { color: var(--text); font-weight: 500; }
.knob input[type="range"] { width: 100%; min-height: 44px; padding: 0; border: 0; background: transparent; accent-color: var(--accent); }
.knob.toggle { grid-template-columns: auto 1fr; align-items: center; }
.knob.toggle input { width: 22px; height: 22px; min-height: 0; }
.generate { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; border-top: 1px solid var(--line); padding-top: 12px; }
.generate .field { flex-direction: column; align-items: stretch; }
.generate .field span { margin-bottom: 4px; }
.button { display: inline-flex; align-items: center; }

.steps-head { display: flex; justify-content: space-between; align-items: center; color: var(--muted); margin-bottom: 8px; }
.grid { display: grid; grid-template-columns: 110px repeat(16, 1fr); gap: 4px; overflow-x: auto; }
.grid .row-label { font-size: 0.85rem; color: var(--muted); display: flex; align-items: center; padding-right: 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.step { min-height: 36px; border-radius: 6px; background: var(--step-off); border: 1px solid transparent; padding: 0; }
.step:nth-child(16n + 2), .step:nth-child(16n + 6), .step:nth-child(16n + 10), .step:nth-child(16n + 14) { border-color: var(--line); }
.step.on { background: var(--step-on); }
.step.play { box-shadow: inset 0 0 0 2px #fff; }
.grid .col-head { font-size: 0.7rem; color: var(--muted); text-align: center; }

.help { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px; background: #0a0c10; border-top: 1px solid var(--line); color: var(--text); font-size: 0.95rem; min-height: 48px; }
.status { position: fixed; right: 16px; bottom: 60px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: 0.9rem; opacity: 0; transition: opacity 200ms; max-width: 60vw; }
.status.show { opacity: 1; }
.status a { color: var(--accent); }

@media (max-width: 640px) {
  .pads { grid-template-columns: repeat(2, 1fr); }
  /* 4x4 like the hardware, so a column is ~80px: minmax(0,…) stops a long pad name or the
     M/S buttons widening the page past the screen; the buttons drop to the bottom corner,
     beside the key letter, so the name keeps the top line to itself. */
  body[data-mode="pro"] .pads { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  body[data-mode="pro"] .pad { padding: 8px; aspect-ratio: auto; min-height: 76px; } /* 2.6:1 at 72px tall implies 187px wide */
  body[data-mode="pro"] .pad .name { font-size: 0.85rem; }
  body[data-mode="pro"] .pad .tools { top: auto; bottom: 6px; right: 6px; gap: 3px; }
  body[data-mode="pro"] .pad .tools button { min-height: 26px; min-width: 26px; }
  .pad { min-height: 72px; }
  .grid { grid-template-columns: 80px repeat(16, 28px); }
  .mode { margin-left: 0; }
}

/* --- patterns, accents, song, mutes --- */
.steps-head { gap: 10px; flex-wrap: wrap; }
.steps-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.patterns { display: flex; gap: 6px; flex-wrap: wrap; }
.patterns button { min-width: 44px; font-weight: 600; }
.patterns button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.patterns button.playing { box-shadow: 0 0 0 2px #fff inset; }
.legend { color: var(--muted); font-size: 0.8rem; display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.legend .sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; background: var(--step-off); }
.legend .sw.on { background: var(--step-on); }
.legend .sw.accent { background: #fff3c4; }
.step.accent { background: #fff3c4; }
.grid .row-label { gap: 6px; }
.grid .row-label.muted { opacity: 0.35; text-decoration: line-through; }
.pad .tools { position: absolute; right: 8px; top: 8px; display: flex; gap: 4px; }
.pad .tools button { min-height: 28px; min-width: 28px; padding: 0; font-size: 0.75rem; line-height: 1; border-radius: 6px; background: #0f1115; }
.pad .tools button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.pad.muted { opacity: 0.45; }
.pad.muted .tools { opacity: 1; }
.song-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.song-list li { display: grid; grid-template-columns: 32px 1fr auto auto auto auto; gap: 8px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.song-list li.playing { border-color: var(--accent); }
.song-list .idx { color: var(--muted); font-size: 0.85rem; }
.song-list .pname { font-weight: 600; }
.song-list .reps { display: inline-flex; align-items: center; gap: 4px; }
.song-list .reps input { width: 64px; text-align: center; }
.song-list button { min-height: 36px; padding: 0 10px; }
.song-list .bars { color: var(--muted); font-size: 0.85rem; min-width: 70px; text-align: right; }
.muted { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.title { font-weight: 600; color: var(--text); }
#swing { width: 110px; min-height: 44px; accent-color: var(--accent); padding: 0; border: 0; background: transparent; }
button:disabled { opacity: 0.5; cursor: progress; }
.song-list li { grid-template-columns: 32px 56px auto 1fr auto auto auto auto; }
.song-list .arr { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.song-list .dot { min-height: 22px; min-width: 22px; width: 22px; height: 22px; padding: 0; border-radius: 6px; background: var(--c); border: 1px solid transparent; opacity: 1; }
.song-list .dot.off { background: var(--step-off); border-color: var(--line); }
.song-list .dot:hover { border-color: #fff; }
@media (max-width: 760px) { .song-list li { grid-template-columns: 32px 56px auto auto auto auto; } .song-list .arr { grid-column: 1 / -1; } }

/* --- ratchet / chance / note lane --- */
.step.ratchet { background: linear-gradient(90deg, var(--step-on) 0 45%, var(--step-off) 45% 55%, var(--step-on) 55%); }
.step.chance { background: repeating-linear-gradient(135deg, var(--step-on) 0 4px, var(--step-off) 4px 8px); }
.legend .sw.ratchet { background: linear-gradient(90deg, var(--step-on) 0 45%, var(--step-off) 45% 55%, var(--step-on) 55%); }
.legend .sw.chance { background: repeating-linear-gradient(135deg, var(--step-on) 0 3px, var(--step-off) 3px 6px); }
.note-lane { margin-top: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 8px; }
.lane-head { display: flex; justify-content: space-between; align-items: center; }
.lane-cells { display: grid; grid-template-columns: 110px repeat(16, 1fr); gap: 4px; }
.lane-cells .cell { min-height: 36px; border-radius: 6px; padding: 0; font-size: 0.78rem; font-weight: 600; background: var(--step-off); border: 1px solid transparent; }
.lane-cells .cell.has { background: #2b3448; border-color: var(--line); }
.lane-cells .cell.slide::after { content: " ~"; color: var(--accent); }
.lane-cells .cell.sel { border-color: var(--accent); }
.lane-cells .cell:nth-child(16n + 2), .lane-cells .cell:nth-child(16n + 6), .lane-cells .cell:nth-child(16n + 10), .lane-cells .cell:nth-child(16n + 14) { border-left-color: var(--line); }
.note-picker { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.note-picker .key { min-width: 40px; min-height: 40px; padding: 0 6px; font-weight: 600; }
.note-picker .key.black { background: #0b0d12; }
.note-picker .key[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.note-picker .sep { width: 10px; }
.fill-row { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
#fillBtn[aria-pressed="true"], #recArrange.on { background: var(--rec); border-color: var(--rec); color: #fff; }
.song-list .fillflag { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 0.8rem; }
.song-list .fillflag input { width: 18px; height: 18px; min-height: 0; }
.song-list li { grid-template-columns: 32px 56px auto 1fr auto auto auto auto auto; }
.grid[data-steps="32"] .step { min-height: 30px; }
.grid[data-steps="32"] .col-head { font-size: 0.6rem; }
.grid[data-steps="32"] .step:nth-child(33n + 18) { border-left: 2px solid var(--muted); }
.pad.drop { border-color: var(--accent); border-style: dashed; }
.grid .step { touch-action: none; }

/* --- lesson note, mixer, picture, midi --- */
.kit-note { background: #1b2130; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 14px; line-height: 1.45; }
.kit-note p { margin: 0 0 4px; font-weight: 600; }
.kit-note ol { margin: 4px 0 0; padding-left: 20px; color: var(--text); }
.kit-note li { margin: 2px 0; }
.chip { font-size: 0.85rem; color: var(--muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mix-row { display: grid; grid-template-columns: 120px 1fr 170px 44px 44px; gap: 10px; align-items: center; padding: 2px 0; }
.mix-row.muted .mix-name, .mix-row.muted .mix-fader { opacity: 0.4; }
.mix-name { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mix-fader, .mix-pan { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.8rem; }
.mix-fader input, .mix-pan input { flex: 1; min-height: 44px; padding: 0; border: 0; background: transparent; accent-color: var(--accent); }
.mix-fader b { color: var(--text); font-weight: 500; width: 36px; text-align: right; font-variant-numeric: tabular-nums; }
.mix-row button { min-width: 44px; padding: 0; }
.song-list .sweep { min-height: 36px; padding: 0 8px; font-size: 0.85rem; }
.song-list li { grid-template-columns: 32px 56px auto 1fr auto auto auto auto auto auto; }
.picture video { max-height: 340px; max-width: 46%; background: #000; border-radius: 10px; display: block; }
#pictureBody { display: flex; gap: 12px; align-items: flex-start; }
#pictureBody[hidden] { display: none; }
.picture-side { flex: 1; min-width: 0; }
.cue-strip { position: relative; margin: 0 0 8px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; display: grid; gap: 1px; background: var(--line); }
.cue-row { display: grid; grid-template-columns: 104px minmax(0, 1fr); background: var(--panel); }
.cue-row.muted-row { opacity: 0.4; }
.cue-label { font-size: 0.78rem; padding: 0 8px; display: flex; align-items: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border-left: 4px solid var(--c, transparent); color: var(--text); }
.cue-lane { position: relative; height: 26px; background: var(--step-off); cursor: pointer; }
.cue-row.ruler .cue-lane { height: 18px; background: var(--panel); }
.cue-row.ruler .cue-label { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.72rem; }
.cue-row.ruler i { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--line); padding-left: 3px; font-style: normal; font-size: 0.68rem; color: var(--muted); line-height: 18px; }
.cue-lane .cue { position: absolute; top: 3px; bottom: 3px; width: 6px; min-height: 0; padding: 0; border: 0; border-radius: 3px; background: var(--c); transform: translateX(-1px); cursor: grab; touch-action: none; }
.cue-lane .cue.long { opacity: 0.8; transform: none; border-right: 3px solid #fff8; }
.cue-lane .cue:hover { outline: 2px solid #fff; }
.cue-head { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; pointer-events: none; }
#cueArm.on { background: var(--rec); border-color: var(--rec); color: #fff; }
@media (max-width: 760px) { .mix-row { grid-template-columns: 90px 1fr 44px 44px; } .mix-pan { display: none; } .song-list li { grid-template-columns: 32px 56px auto auto auto auto auto; } }

/* --- one page: two columns on a wide window, tighter controls with a mouse, folding sections --- */
main { max-width: 1900px; padding: 10px 14px; gap: 10px; }
.cols { display: grid; gap: 10px; }
.col { display: grid; gap: 10px; align-content: start; min-width: 0; }
.picture, .steps, .song { min-width: 0; }
@media (min-width: 1000px) { .cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); align-items: start; } }
.fold { min-height: 30px; min-width: 30px; padding: 0; margin-right: 4px; }
.folded > :not(.steps-head) { display: none !important; }
.folded .steps-tools, .folded .patterns { display: none; }
.folded .steps-head { margin-bottom: 0; justify-content: flex-start; }
[hidden] { display: none !important; }
.folded .steps-head::after { content: attr(data-name); color: var(--muted); }
@media (pointer: fine) {
  button, select, input, .button, .check { min-height: 32px; padding: 0 10px; }
  .bar { padding: 6px 14px; gap: 6px; }
  .pad, body[data-mode="simple"] .pad { aspect-ratio: auto; height: 54px; min-height: 0; max-height: none; padding: 6px 10px; min-width: 0; }
  body[data-mode="simple"] .pad { height: 72px; }
  .pads { gap: 6px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .pad .tools { right: 5px; top: 5px; gap: 3px; }
  .pad .tools button { min-height: 20px; min-width: 20px; font-size: 0.68rem; padding: 0; }
  .pad .name { padding-right: 46px; font-size: 0.92rem; }
  .panel { padding: 10px; gap: 8px; }
  .knobs { grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 4px 12px; }
  .knob { gap: 0; }
  .knob input[type="range"] { min-height: 22px; }
  .generate { padding-top: 8px; gap: 8px; }
  .step, .lane-cells .cell { min-height: 26px; }
  .mix-fader input, .mix-pan input { min-height: 26px; }
  .help { padding: 6px 14px; min-height: 32px; font-size: 0.88rem; }
  body { padding-bottom: 44px; }
  .status { bottom: 44px; }
  #swing { min-height: 32px; }
}

/* --- typed knob values --- */
.kval-wrap { display: inline-flex; align-items: baseline; gap: 2px; color: var(--muted); }
.kval-wrap i { font-style: normal; font-size: 0.78rem; }
.knob .kval { width: 52px; min-height: 20px; height: 20px; padding: 0 3px; text-align: right; font-size: 0.82rem; color: var(--text); background: transparent; border: 1px solid transparent; border-radius: 4px; cursor: text; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.knob .kval:hover { border-color: var(--line); }
.knob .kval:focus { border-color: var(--accent); background: var(--bg); outline: none; }
.knob .kval::-webkit-inner-spin-button, .knob .kval::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
