:root {
  --bg: #0f1115; --panel: #181b22; --panel2: #1f232c; --line: #2b303b; --text: #e7e9ee; --dim: #8a91a0;
  --accent: #f59e0b; --accent-ink: #1a1203; --step: #272c37; --step-beat: #323846; --play: #ffffff55;
  --shadow: 0 1px 0 #0006;
}
:root[data-theme='light'] {
  --bg: #eef0f4; --panel: #ffffff; --panel2: #f4f5f8; --line: #d5d9e2; --text: #181b22; --dim: #646b7a;
  --accent: #d97706; --accent-ink: #ffffff; --step: #e3e6ed; --step-beat: #d2d7e2; --play: #00000033;
  --shadow: 0 1px 0 #0001;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; margin: 0 0 10px; color: var(--dim); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
h2 small { text-transform: none; letter-spacing: 0; font-weight: 400; }
kbd { background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font: 12px ui-monospace, monospace; }

.top { display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: center; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; font-size: 20px; letter-spacing: -.02em; }
.brand span { color: var(--accent); }
.transport, .tools, .pat-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.tools { margin-left: auto; }
.field { display: flex; align-items: center; gap: 6px; color: var(--dim); font-size: 12px; }
.field output { min-width: 40px; color: var(--text); font-variant-numeric: tabular-nums; }
input, select, button { font: inherit; color: var(--text); }
input[type=number], select { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; }
input[type=number] { width: 64px; }
input[type=range] { accent-color: var(--accent); }
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; box-shadow: var(--shadow); }
.btn:hover { border-color: var(--dim); }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; min-width: 72px; }
.btn.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.bar { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; padding: 10px 16px; }
.patterns { display: flex; gap: 4px; flex-wrap: wrap; }
.pat { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; font-weight: 600; position: relative; }
.pat.has::after { content: ''; position: absolute; right: 3px; top: 3px; width: 5px; height: 5px; border-radius: 50%; background: var(--dim); }
.pat.cur { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.pat.live { outline: 2px solid var(--text); outline-offset: 1px; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; padding: 0 16px 24px; align-items: start; }
.left, .right { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; min-width: 0; }

.grid { overflow-x: auto; padding-bottom: 6px; }
.row { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; width: max-content; }
.head { position: sticky; left: 0; z-index: 2; background: var(--panel); display: flex; gap: 4px; align-items: center; padding-right: 6px; width: 272px; }
.name { width: 98px; white-space: nowrap; text-align: left; background: transparent; border: 0; border-left: 4px solid var(--c); padding: 5px 6px; cursor: pointer; border-radius: 4px; font-weight: 600; font-size: 13px; }
.name.sel { background: var(--panel2); }
.ms { width: 24px; height: 24px; padding: 0; font-size: 11px; border-radius: 5px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; }
.ms.on.m { background: #ef4444; border-color: transparent; color: #fff; }
.ms.on.s { background: #22c55e; border-color: transparent; color: #05210f; }
.euc { width: 40px; padding: 2px 4px; font-size: 12px; }
.steps { display: flex; gap: 3px; }
.step { position: relative; width: 28px; height: 32px; border: 0; border-radius: 5px; background: var(--step); cursor: pointer; padding: 0; flex: none; }
.step.beat { background: var(--step-beat); }
.step.gap { margin-left: 8px; }
.step.off { opacity: .25; cursor: default; }
.step.on { background: var(--c); }
.step.on.v1 { opacity: .5; }
.step.on.v2 { opacity: .78; }
.step.on.v3 { opacity: 1; box-shadow: inset 0 0 0 2px #fff6; }
.step.has-p { background-image: repeating-linear-gradient(135deg, #0004 0 3px, transparent 3px 6px); }
.step.has-r::before { content: attr(data-r); position: absolute; left: 3px; top: 1px; font-size: 10px; font-weight: 700; color: #000b; }
.step.has-l::after { content: ''; position: absolute; right: 3px; bottom: 3px; width: 6px; height: 6px; border-radius: 50%; background: #000b; }
.step.sel { outline: 2px solid var(--text); outline-offset: 1px; z-index: 1; }
.step.playing { filter: brightness(1.6); box-shadow: 0 0 0 2px var(--play); }
.step:not(.on).playing { background: var(--play); }

.roll { overflow-x: auto; }
.rrow { display: flex; gap: 3px; margin-bottom: 2px; width: max-content; align-items: center; }
.rlab { position: sticky; left: 0; z-index: 2; width: 275px; text-align: right; padding-right: 10px; line-height: 14px; font-size: 11px; color: var(--dim); background: var(--panel); }
.cell { width: 28px; height: 14px; border: 0; border-radius: 3px; background: var(--step); padding: 0; cursor: pointer; flex: none; }
.cell.beat { background: var(--step-beat); }
.cell.gap { margin-left: 8px; }
.cell.black { filter: brightness(.82); }
.cell.on { background: var(--c); filter: none; }
.cell.on.acc { box-shadow: inset 0 0 0 2px #fffa; }
.cell.on.slide { border-radius: 3px 10px 10px 3px; width: 34px; margin-right: -6px; }
.cell.off { opacity: .25; }
.cell.playing { box-shadow: 0 0 0 2px var(--play); }
.cell.sel { outline: 2px solid var(--text); outline-offset: 1px; }

.song { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.entry { display: flex; gap: 4px; align-items: center; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; }
.entry.live { border-color: var(--accent); }
.entry input { width: 50px; }
.inline { display: inline-flex; gap: 6px; align-items: center; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text); }

.panel-row { display: grid; grid-template-columns: 62px 1fr 44px; gap: 8px; align-items: center; margin-bottom: 6px; font-size: 12px; }
.panel-row label { color: var(--dim); }
.panel-row output { text-align: right; font-variant-numeric: tabular-nums; }
.seg { display: flex; gap: 4px; margin-bottom: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--dim); }
.muted { color: var(--dim); font-size: 12px; }
.help p { margin: 0; color: var(--dim); font-size: 12px; line-height: 1.9; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; opacity: 0; pointer-events: none; transition: .2s; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .tools { margin-left: 0; }
}
@media (max-width: 560px) {
  .step { width: 24px; height: 30px; }
  .cell { width: 24px; }
  .head { width: 232px; }
  .rlab { width: 235px; }
  .name { width: 58px; overflow: hidden; text-overflow: ellipsis; }
}
