/* Step Sequencer. Built on Weblab's shared look (../theme.css): transport strip on top, the step grid as the main
   surface, sound and effect controls beside it on wide screens and under it on a phone. Each part has its own colour;
   the section accent is the teal of the bass part. */
:root {
  --accent: #0a8a73;
  --panel: var(--wl-bg); --panel-2: var(--wl-surface); --well: var(--wl-surface-2); --line: var(--wl-edge); --line-2: #cfd4db;
  --ink: var(--wl-ink); --ink-2: var(--wl-ink-2); --ink-3: var(--wl-ink-3);
  --cell-a: #ffffff; --cell-b: #e6e9ee;
  --drum: #c26d00; --bass: #0a8a73; --lead: #cc2a70; --go: var(--accent); --on-ink: var(--wl-on-accent);
  --label: var(--wl-font);
  --mono: var(--wl-mono);
  --on: var(--drum);
  --chip: var(--wl-bg);
}
:root:not([data-theme="light"]) {
  --accent: #2fd6b5; --line-2: #3a3f49; --chip: #33373f;
  --cell-a: #2c2f37; --cell-b: #212429;
  --drum: #ffb02e; --bass: #2fd6b5; --lead: #ff5fa2;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--wl-bg); color: var(--ink); font: 15px/1.5 var(--wl-font); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--wl-focus); outline-offset: 2px; border-radius: 8px; }
h1, h2, p { margin: 0; }

.app { max-width: 1240px; margin: 0 auto; padding-inline: 16px; padding-block: 14px calc(100px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 16px; }

/* ---------- top bar ---------- */
.bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.home { display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--wl-pill); background: var(--wl-surface); color: var(--ink-2); flex: none; transition: background .15s, color .15s; }
.home:hover { background: var(--wl-surface-2); color: var(--ink); }
.home svg { width: 18px; height: 18px; }
h1 { font: 800 24px/1.1 var(--wl-font); letter-spacing: -.035em; margin-right: auto; }
.bar-tools { display: flex; gap: 8px; }

.btn { min-height: 40px; padding: 0 16px; border: 0; border-radius: var(--wl-pill); background: var(--wl-surface-2); font-weight: 600; font-size: 14.5px; white-space: nowrap; transition: background .15s, color .15s; }
.bar-tools .btn, dialog .btn { background: var(--wl-surface); }
.btn:hover { background: color-mix(in srgb, var(--ink) 10%, var(--wl-surface-2)); }
.bar-tools .btn:hover, dialog .btn:hover { background: var(--wl-surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; }
.btn:disabled:hover { background: var(--wl-surface-2); }
.btn.small { min-height: 36px; padding: 0 13px; font-size: 13.5px; }
.btn[aria-pressed="true"], .btn[aria-pressed="true"]:hover { background: var(--accent); color: var(--wl-on-accent); }
dialog #dlg-copy, dialog #dlg-copy:hover { background: var(--accent); color: var(--wl-on-accent); }
.lbl { font: 600 13px/1 var(--wl-font); color: var(--ink-2); }
.readout { font: 700 26px/1 var(--wl-font); letter-spacing: -.03em; font-variant-numeric: tabular-nums; min-width: 3ch; text-align: right; }
.readout.sm { font-size: 19px; min-width: 2ch; }
.hint { font-size: 13.5px; color: var(--ink-3); line-height: 1.5; }

/* ---------- transport ---------- */
.transport { display: grid; grid-template-columns: 1fr; gap: 14px 24px; padding: 16px 18px; background: var(--wl-surface); border-radius: var(--wl-radius); }
.play { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px; padding: 0 28px; border: 0; border-radius: var(--wl-pill); background: var(--go); color: var(--on-ink); font: 700 17px/1 var(--wl-font); letter-spacing: -.01em; box-shadow: var(--wl-shadow); }
.play:hover { filter: brightness(1.06); }
.play svg { width: 20px; height: 20px; fill: currentColor; }
.play .i-stop, .play[aria-pressed="true"] .i-play { display: none; }
.play[aria-pressed="true"] .i-stop { display: inline; }
.tempo, .knob { display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 10px; min-width: 0; }
.knob { grid-template-columns: auto auto 1fr; }
.pats { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; gap: 3px; padding: 3px; background: var(--wl-surface-2); border-radius: var(--wl-pill); }
.seg button { min-width: 42px; min-height: 36px; border: 0; border-radius: var(--wl-pill); background: transparent; color: var(--ink-2); font: 700 15px var(--wl-font); position: relative; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--chip); color: var(--ink); box-shadow: var(--wl-shadow); }
.seg button.has::after { content: ''; position: absolute; left: 50%; bottom: 4px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--accent); }
.seg button.now { box-shadow: inset 0 0 0 2px var(--accent); }

/* On a phone the play button rides at the bottom of the screen, under the thumb. */
@media (max-width: 899px) {
  .play { position: fixed; z-index: 30; left: 16px; right: 16px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); box-shadow: var(--wl-shadow-lift); }
}
@media (min-width: 900px) {
  .app { padding-block: 20px 48px; }
  .transport { grid-template-columns: auto minmax(260px, 1.3fr) minmax(190px, 1fr) auto; align-items: center; }
}

/* ---------- range inputs ---------- */
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; min-width: 0; height: 32px; margin: 0; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--line-2); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line-2); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%; background: var(--accent); border: 3px solid var(--wl-bg); box-shadow: 0 1px 4px rgb(0 0 0 / .25); }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 3px solid var(--wl-bg); box-shadow: 0 1px 4px rgb(0 0 0 / .25); }
select { min-height: 40px; padding: 0 30px 0 12px; border: 0; border-radius: var(--wl-radius-sm); background-color: var(--wl-surface-2); max-width: 100%; font-weight: 500; }
select:hover { background-color: color-mix(in srgb, var(--ink) 8%, var(--wl-surface-2)); }

/* ---------- scope ---------- */
.scope { display: block; width: 100%; height: 56px; border-radius: var(--wl-radius-md); background: var(--wl-surface); }

/* ---------- panels ---------- */
.cols { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
@media (min-width: 1000px) { .cols { grid-template-columns: minmax(0, 1fr) 320px; } }
.side { display: grid; gap: 16px; min-width: 0; }
.panel { min-width: 0; padding: 18px; background: var(--wl-surface); border-radius: var(--wl-radius); display: flex; flex-direction: column; gap: 14px; }
.panel h2 { font: 700 18px/1.2 var(--wl-font); letter-spacing: -.025em; color: var(--ink); }
.pattern-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.tabs { display: inline-flex; gap: 3px; padding: 3px; background: var(--wl-surface-2); border-radius: var(--wl-pill); }
.tab { display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 16px; border: 0; border-radius: var(--wl-pill); background: transparent; color: var(--ink-2); font-weight: 700; font-size: 14.5px; letter-spacing: -.01em; }
.tab::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { background: var(--chip); color: var(--ink); box-shadow: var(--wl-shadow); }
.tab[data-tab="drums"] { --c: var(--drum); } .tab[data-tab="bass"] { --c: var(--bass); } .tab[data-tab="lead"] { --c: var(--lead); }
.tools { display: flex; gap: 6px; flex-wrap: wrap; }

.pager { display: flex; gap: 6px; }
@media (min-width: 700px) { .pager { display: none; } }

/* step lamps: one per step, lit where this part has a note, bright at the playhead */
.leds { display: grid; grid-template-columns: repeat(16, 1fr); gap: 4px; }
.leds[data-tab="bass"] { --on: var(--bass); } .leds[data-tab="lead"] { --on: var(--lead); }
.leds i { height: 6px; border-radius: 3px; background: var(--cell-b); }
.leds i:nth-child(4n+1) { background: var(--line-2); }
.leds i.on { background: color-mix(in srgb, var(--on) 60%, var(--cell-b)); }
.leds i.ph { background: var(--ink); }
.leds i.off-page { opacity: .45; }

/* ---------- the grid ---------- */
.grid { --on: var(--drum); display: grid; gap: 5px; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.grid[data-tab="bass"] { --on: var(--bass); }
.grid[data-tab="lead"] { --on: var(--lead); }
.row { display: grid; grid-template-columns: 54px 28px minmax(0, 1fr); gap: 5px; align-items: stretch; }
.grid:not([data-tab="drums"]) .row { grid-template-columns: 44px minmax(0, 1fr); }
.lab { display: flex; align-items: center; justify-content: flex-start; padding: 0 8px; border: 0; border-radius: 8px; background: var(--wl-surface-2); font: 600 12.5px/1 var(--wl-font); color: var(--ink-2); min-width: 0; overflow: hidden; }
button.lab:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 9%, var(--wl-surface-2)); }
span.lab { justify-content: center; padding: 0; }
span.lab.root { color: var(--on); background: color-mix(in srgb, var(--on) 14%, var(--wl-surface-2)); }
.mute { border: 0; border-radius: 8px; background: var(--wl-surface-2); font: 700 11.5px/1 var(--wl-font); color: var(--ink-3); padding: 0; }
.mute:hover { color: var(--ink); }
.mute[aria-pressed="true"] { background: var(--ink-2); color: var(--wl-bg); }
.row.muted .c { opacity: .38; }
.cells { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 3px; min-width: 0; }
.c { height: 38px; padding: 0; border: 0; border-radius: 7px; background: var(--cell-b); position: relative; }
.grid:not([data-tab="drums"]) .c { height: 30px; }
.c.g1 { background: var(--cell-a); }
.c[data-v="1"] { background: color-mix(in srgb, var(--on) 72%, var(--wl-surface)); }
.c[data-v="2"] { background: var(--on); box-shadow: inset 0 0 0 2px var(--wl-surface), inset 0 0 0 4px var(--on); }
.c.ph::after { content: ''; position: absolute; inset: 0; border-radius: 7px; box-shadow: inset 0 0 0 2px var(--ink); pointer-events: none; }
.grid[data-page="a"] .cells, .grid[data-page="b"] .cells { grid-template-columns: repeat(8, minmax(0, 1fr)); }
.grid[data-page="a"] .c.h2, .grid[data-page="b"] .c.h1 { display: none; }
.cells .c:nth-child(4n+1):not(:first-child) { margin-left: 3px; }
@media (min-width: 700px) { .c { height: 36px; } .row { grid-template-columns: 64px 30px minmax(0, 1fr); } .cells { gap: 4px; } }

/* ---------- instrument and effect controls ---------- */
.inst { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: end; }
.field { display: grid; gap: 6px; min-width: 0; }
.field.grow { flex: 1 1 150px; }
.sliders { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px 16px; }
.xy-wrap { display: grid; gap: 10px; justify-items: start; }
.xy { position: relative; width: 100%; height: 150px; border-radius: var(--wl-radius-md); touch-action: none; cursor: crosshair; overflow: hidden;
  background: radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--accent) 22%, transparent) 0, transparent 70%), var(--wl-surface-2); }
.xy-dot { position: absolute; left: calc(15px + (100% - 30px) * var(--x, 1)); top: calc(15px + (100% - 30px) * var(--y, 1)); width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 50%; background: var(--accent); border: 4px solid var(--wl-bg); box-shadow: 0 2px 8px rgb(0 0 0 / .25); pointer-events: none; }
.xy-x, .xy-y { position: absolute; font: 600 12px/1 var(--wl-font); color: var(--ink-3); pointer-events: none; }
.xy-x { right: 10px; bottom: 9px; }
.xy-y { left: 10px; top: 10px; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; }

.foot { color: var(--ink-3); font-size: 13.5px; max-width: 70ch; }

/* ---------- dialog and toast ---------- */
dialog { width: min(480px, calc(100vw - 32px)); padding: 22px; border: 0; border-radius: var(--wl-radius); background: var(--wl-bg); color: var(--ink); box-shadow: var(--wl-shadow-lift); }
dialog::backdrop { background: rgb(10 12 16 / .45); }
dialog h2 { font: 700 20px/1.2 var(--wl-font); letter-spacing: -.025em; margin-bottom: 8px; }
dialog p { color: var(--ink-2); margin-bottom: 14px; }
dialog input { width: 100%; min-height: 44px; padding: 0 12px; border: 0; border-radius: var(--wl-radius-sm); background: var(--wl-surface-2); font: 13px var(--mono); margin-bottom: 14px; }
.dlg-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.toast { position: fixed; z-index: 40; left: 50%; top: 14px; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: var(--wl-pill); background: var(--ink); color: var(--wl-bg); font-weight: 600; text-align: center; box-shadow: var(--wl-shadow-lift); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
