/* =============================================================================
   Lofi Studio Pro — app.css
   A control surface, not a website: fixed app shell, hardware-style panels,
   physical knobs and faders, touch-first sizing.

   Layout
     < 720px   one column, bottom tab bar, transport above it
     >= 720px  left icon rail, wider stage, transport full width
     >= 1080px two-column mixer, wider sequencer
   ========================================================================== */

/* ------------------------------------------------------------------ tokens */
:root {
  --bg: #12101a;
  --panel: #1a1727;
  --panel-2: #221e33;
  --line: #2e2942;
  --text: #f2f0f7;
  --dim: #9a94ad;
  --acc: #e94560;
  --acc2: #533483;
  --pad-off: #241f38;
  --pad-off-2: #1d1930;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;

  --tap: 44px;                 /* minimum comfortable touch target */
  --head: 92px;                /* sequencer row-header width */
  --pad: 44px;                 /* step pad size */
  --topbar: 54px;
  --transport: 74px;
  --tabbar: 58px;

  --shadow-panel: 0 1px 0 rgba(255,255,255,.04) inset, 0 10px 30px rgba(0,0,0,.35);
  --ease: cubic-bezier(.2,.8,.2,1);
}

[data-theme="purple"]    { --bg:#12101a; --panel:#1a1727; --panel-2:#221e33; --line:#2e2942; --acc:#e94560; --acc2:#533483; --pad-off:#241f38; --pad-off-2:#1d1930; }
[data-theme="pink"]      { --bg:#180d14; --panel:#22131d; --panel-2:#2c1a26; --line:#3d2333; --acc:#ff6b9d; --acc2:#c73e6c; --pad-off:#2a1822; --pad-off-2:#22131b; }
[data-theme="black"]     { --bg:#08080a; --panel:#111113; --panel-2:#17171a; --line:#26262b; --acc:#e94560; --acc2:#7a1f30; --pad-off:#17171a; --pad-off-2:#121214; }
[data-theme="ocean"]     { --bg:#04121b; --panel:#081d29; --panel-2:#0c2735; --line:#123444; --acc:#00d68f; --acc2:#1e8fa6; --pad-off:#0b2430; --pad-off-2:#081d27; }
[data-theme="forest"]    { --bg:#081209; --panel:#0e1f13; --panel-2:#13291a; --line:#1c3a24; --acc:#4ade80; --acc2:#2f7a4a; --pad-off:#112518; --pad-off-2:#0e1f14; }
[data-theme="sunset"]    { --bg:#1a0e1c; --panel:#26152a; --panel-2:#321c37; --line:#432547; --acc:#ffaa00; --acc2:#e94560; --pad-off:#2b1830; --pad-off-2:#24142a; }
[data-theme="midnight"]  { --bg:#040a18; --panel:#0a1224; --panel-2:#0e1930; --line:#152344; --acc:#4361ee; --acc2:#3a0ca3; --pad-off:#0d1730; --pad-off-2:#0a1226; }
[data-theme="cyberpunk"] { --bg:#0a0113; --panel:#150523; --panel-2:#1d0830; --line:#2f0d4a; --acc:#ff2079; --acc2:#00f0ff; --pad-off:#1a0728; --pad-off-2:#140520; }

/* Two themes are light; everything else assumes a dark surface. */
[data-theme="bright"] {
  --bg:#ece9f4; --panel:#f8f6fc; --panel-2:#ffffff; --line:#d8d3e6;
  --text:#1b1630; --dim:#5f5878; --acc:#6d4fc4; --acc2:#e94560;
  --pad-off:#e4e0ef; --pad-off-2:#dcd7ea;
  --shadow-panel: 0 1px 0 rgba(255,255,255,.9) inset, 0 8px 24px rgba(40,30,70,.10);
}
[data-theme="lavender"] {
  --bg:#e9e3f7; --panel:#f7f3ff; --panel-2:#ffffff; --line:#d6cbee;
  --text:#241a3d; --dim:#5c527a; --acc:#7c4dff; --acc2:#c68fff;
  --pad-off:#e2daf4; --pad-off-2:#d8cdee;
  --shadow-panel: 0 1px 0 rgba(255,255,255,.9) inset, 0 8px 24px rgba(50,30,90,.10);
}

/* ------------------------------------------------------------------- reset */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }

/* ------------------------------------------------------------------- shell */
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: var(--topbar) minmax(0, 1fr) var(--transport) var(--tabbar);
  grid-template-areas:
    "top"
    "stage"
    "transport"
    "tabs";
  overflow: hidden;
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px;
  padding-top: env(safe-area-inset-top);
  height: calc(var(--topbar) + env(safe-area-inset-top));
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--acc), var(--acc2));
  display: grid; place-items: center;
  box-shadow: 0 0 14px -2px var(--acc);
}
.brand-mark::before {
  content: ""; width: 11px; height: 11px; border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.95);
}
.brand-mark::after {
  content: ""; position: absolute; width: 3px; height: 3px; border-radius: 50%;
  background: #fff;
}
.brand-mark { position: relative; }
.brand-name {
  font-size: 14px; font-weight: 650; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-name b { color: var(--acc); font-weight: 650; }
.top-tools { display: flex; align-items: center; gap: 6px; flex: none; }
.vol-ico { display: flex; align-items: center; color: var(--dim); }
.top-tools .tp-group { flex-direction: row; gap: 4px; }
.vol-ico svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* -------------------------------------------------------------------- rail */
.rail { display: none; grid-area: rail; }

/* --------------------------------------------------------------- stage/views */
.stage {
  grid-area: stage;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  padding-bottom: 20px;
}
.view { display: flex; flex-direction: column; gap: 12px; max-width: 1180px; margin: 0 auto; min-height: 100%; }
#view-mix, #view-amb, #view-themes { justify-content: center; }

.block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 12px;
  box-shadow: var(--shadow-panel);
}
.block-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 10px;
}
.block-title {
  font-size: 10.5px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--dim);
}
.block + .block { margin-top: 0; }
#view-studio .block:last-child { padding-bottom: 14px; }

/* --------------------------------------------------------------- pills/chips */
.pill-row, .chip-row {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
}
.pill-row::-webkit-scrollbar, .chip-row::-webkit-scrollbar { display: none; }

.pill, .chip {
  flex: none;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--dim);
  font-size: 12.5px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform .12s var(--ease), background .16s, color .16s, border-color .16s;
}
.pill:active, .chip:active { transform: scale(.96); }
.pill.active, .chip.active {
  background: linear-gradient(135deg, var(--acc), var(--acc2));
  border-color: transparent; color: #fff;
  box-shadow: 0 4px 14px -6px var(--acc);
}
.chip { min-height: 32px; font-size: 12px; padding: 0 10px; }

/* -------------------------------------------------------------- visualiser */
.viz-wrap {
  height: 46px; border-radius: var(--r-md);
  background: var(--panel); border: 1px solid var(--line);
  overflow: hidden; position: relative;
}
#viz { display: block; width: 100%; height: 100%; }

/* --------------------------------------------------------------- sequencer */
.seq-scroll {
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none;
  margin: 0 -12px; padding: 0 12px;
  -webkit-overflow-scrolling: touch;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent);
}
.seq-scroll::-webkit-scrollbar { display: none; }

.seq { display: flex; flex-direction: column; gap: 6px; width: max-content; min-width: 100%; }

.seq-row.hit .seq-name { color: var(--acc); }
.seq-row.hit .seq-dot { transform: scale(1.6); }
.seq-dot { transition: transform .12s; }
.seq-row {
  display: grid;
  grid-template-columns: var(--head) repeat(16, var(--pad));
  gap: 5px;
  align-items: center;
}
.seq-head {
  position: sticky; left: 0; z-index: 3;
  display: grid;
  grid-template-columns: 8px 1fr;
  align-items: center; gap: 7px;
  height: var(--pad);
  padding: 0 6px 0 0;
  margin: 0;
  border: 0; background: none; color: inherit;
  text-align: left; cursor: pointer;
  background: linear-gradient(90deg, var(--panel) 84%, transparent);
  -webkit-tap-highlight-color: transparent;
}
.seq-head.on .seq-name { color: var(--dim); text-decoration: line-through; }
.seq-head.on .seq-dot { background: transparent; box-shadow: none; border: 1px solid var(--dim); }
.seq-head:active .seq-name { opacity: .6; }
.seq-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--c); box-shadow: 0 0 8px var(--c);
}
.seq-name {
  font-size: 12px; font-weight: 650; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.pad {
  width: var(--pad); height: var(--pad);
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--pad-off);
  box-shadow: 0 1px 0 rgba(255,255,255,.03) inset;
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform .08s var(--ease), background .12s, box-shadow .12s;
  position: relative;
}
.pad.bar { background: var(--pad-off-2); }
.pad::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: var(--c); opacity: 0; transition: opacity .12s;
}
.pad.on { border-color: transparent; }
.pad.on::after { opacity: .86; box-shadow: 0 0 10px -4px var(--c), 0 0 0 1px rgba(255,255,255,.14) inset; }
.pad[data-vel="2"]::after { opacity: 1; box-shadow: 0 0 18px -1px var(--c), 0 0 0 1px rgba(255,255,255,.3) inset; }
.pad[data-vel="3"]::after { opacity: .34; box-shadow: none; }

/* chance mode: the pad shows how often it fires */
.seq.chance-mode .pad { font-size: 9px; font-weight: 800; color: rgba(255,255,255,.9); }
.seq.chance-mode .pad.on::after { opacity: .5; }
.seq.chance-mode .pad[data-chance="25"]::after { opacity: .22; }
.seq.chance-mode .pad[data-chance="50"]::after { opacity: .32; }
.seq.chance-mode .pad[data-chance="75"]::after { opacity: .42; }
.pad:active { transform: scale(.92); }
.pad.is-playing { outline: 2px solid var(--text); outline-offset: -3px; }
.pad.is-playing.on { filter: brightness(1.25); }

/* ------------------------------------------------------------------ knobs */
.knob {
  position: relative;
  width: 56px; height: 56px;
  border-radius: 50%;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.knob.knob-sm { width: 40px; height: 40px; }
.knob.is-dragging { cursor: grabbing; }
.knob svg { width: 100%; height: 100%; display: block; transform: rotate(0deg); }
.knob-track {
  fill: none; stroke: var(--line); stroke-width: 4; stroke-linecap: round;
  transform: rotate(135deg); transform-origin: 24px 24px;
  stroke-dasharray: 89.5 119.4;
}
.knob-fill {
  fill: none; stroke: var(--acc); stroke-width: 4; stroke-linecap: round;
  transform: rotate(135deg); transform-origin: 24px 24px;
  transition: stroke-dasharray .06s linear;
}
.knob-hub { fill: var(--panel-2); stroke: var(--line); stroke-width: 1; }
.knob-tick { stroke: var(--text); stroke-width: 2.4; stroke-linecap: round; }
.knob-val {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 10px; font-weight: 700; color: var(--text);
  pointer-events: none; padding-top: 6px;
}
.knob-sm .knob-val { font-size: 9px; padding-top: 4px; }

/* ------------------------------------------------------------------ faders */
.faders {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px 6px;
  justify-items: center;
}
.strip {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  width: 100%;
}
.strip-label {
  font-size: 9.5px; font-weight: 800; letter-spacing: .06em;
  color: var(--c);
}
.strip-tools { display: flex; gap: 3px; }
.strip-fx { display: flex; align-items: center; gap: 4px; width: 100%; }
.strip-fx > span {
  font-size: 7.5px; font-weight: 800; letter-spacing: .06em;
  color: var(--dim); width: 22px; flex: none; text-align: right;
}
.strip-fx input { flex: 1; min-width: 0; height: 16px; }
.strip .pan, .strip .send {
  width: 100%; max-width: 74px; height: 18px;
  margin: 0;
}
.strip-fx input::-webkit-slider-runnable-track { height: 4px; }
.strip-fx input::-webkit-slider-thumb { width: 11px; height: 11px; margin-top: -4px; }
.strip .pan::-webkit-slider-runnable-track { height: 4px; }
.strip .pan::-webkit-slider-thumb { width: 12px; height: 12px; margin-top: -4.5px; }

.fader {
  width: 34px; height: 116px;
  display: flex; align-items: center; justify-content: center;
  cursor: grab; touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.fader-rail {
  position: relative;
  width: 8px; height: 100%;
  border-radius: 999px;
  background: var(--pad-off);
  border: 1px solid var(--line);
}
.fader-fill {
  position: absolute; left: 0; right: 0; bottom: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--acc), var(--acc2));
  opacity: .85;
}
.fader-cap {
  position: absolute; left: 50%; width: 26px; height: 18px;
  transform: translateX(-50%);
  border-radius: 5px;
  background: linear-gradient(180deg, var(--panel-2), var(--pad-off));
  border: 1px solid var(--line);
  box-shadow: 0 2px 6px rgba(0,0,0,.4), 0 1px 0 rgba(255,255,255,.08) inset;
}
.fader.is-dragging .fader-cap { border-color: var(--acc); }

/* --------------------------------------------------------------------- fx */
.fx-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px 8px;
  justify-items: center;
}
.fx-cell { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.fx-label {
  font-size: 9.5px; color: var(--dim); font-weight: 600;
  text-align: center; line-height: 1.2;
}

/* ---------------------------------------------------------------- ambience */
.amb-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.amb-tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 96px;
  transition: border-color .16s, background .16s;
}
.amb-tile.on { border-color: var(--acc); background: color-mix(in srgb, var(--acc) 10%, var(--panel)); }
.amb-head {
  display: flex; align-items: center; gap: 8px;
  background: none; border: 0; padding: 0; cursor: pointer;
  min-height: 34px; text-align: left;
}
.amb-icon {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: var(--dim); stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
  transition: stroke .16s;
}
.amb-tile.on .amb-icon { stroke: var(--acc); }
.amb-led {
  width: 7px; height: 7px; border-radius: 50%; margin-left: auto;
  background: var(--pad-off); border: 1px solid var(--line);
  transition: background .16s, box-shadow .16s;
}
.amb-tile.on .amb-led { background: var(--acc); border-color: transparent; box-shadow: 0 0 8px var(--acc); }
.amb-name { font-size: 12.5px; font-weight: 650; }
.amb-tile.on .amb-name { color: var(--acc); }

/* ------------------------------------------------------------- range input */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 20px; background: transparent; cursor: pointer;
  touch-action: manipulation;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px;
  background: linear-gradient(90deg, var(--acc) var(--fill, 50%), var(--pad-off) var(--fill, 50%));
  border: 1px solid var(--line);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 15px; height: 15px; margin-top: -5.5px;
  border-radius: 50%; border: 0;
  background: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,.45);
}
input[type="range"]::-moz-range-track {
  height: 6px; border-radius: 999px;
  background: var(--pad-off); border: 1px solid var(--line);
}
input[type="range"]::-moz-range-progress {
  height: 6px; border-radius: 999px; background: var(--acc);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; border: 0;
  background: var(--text);
}

/* ---------------------------------------------------------------- switches */
.mini {
  width: 30px; height: 26px; border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2); color: var(--dim);
  font-size: 9px; font-weight: 800; line-height: 1;
  display: grid; place-items: center;
  cursor: pointer; padding: 0;
  touch-action: manipulation;
}
.mini.on { background: var(--acc); border-color: transparent; color: #fff; }
.mini[data-solo].on { background: #ffaa00; color: #201500; }

.toggle-chip {
  min-height: 32px; padding: 0 11px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--dim);
  font-size: 11.5px; font-weight: 650; cursor: pointer;
  touch-action: manipulation;
}
.toggle-chip.on { background: var(--acc); border-color: transparent; color: #fff; }

/* ------------------------------------------------------------------ themes */
.themes-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.swatch {
  display: flex; align-items: center; gap: 10px;
  min-height: 52px; padding: 10px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--sw-bg);
  color: #fff; cursor: pointer; text-align: left;
  touch-action: manipulation;
  transition: transform .12s var(--ease), border-color .16s;
}
.swatch:active { transform: scale(.98); }
.swatch.active { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc), 0 6px 18px -8px var(--acc); }
.sw-dot {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--sw-a), var(--sw-b));
}
.sw-name { font-size: 12.5px; font-weight: 650; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.5); }

/* ---------------------------------------------------------------- settings */
.rows { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 52px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}
.row:last-child { border-bottom: 0; }
.row-text { display: flex; flex-direction: column; gap: 2px; }
.row-text strong { font-size: 13px; font-weight: 650; }
.row-text span { font-size: 11.5px; color: var(--dim); line-height: 1.35; }

.switch {
  width: 46px; height: 27px; border-radius: 999px; flex: none;
  border: 1px solid var(--line);
  background: var(--pad-off); position: relative; cursor: pointer; padding: 0;
  touch-action: manipulation;
  transition: background .18s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 21px; height: 21px; border-radius: 50%;
  background: var(--dim);
  transition: transform .18s var(--ease), background .18s;
}
.switch.on { background: var(--acc); border-color: transparent; }
.switch.on::after { transform: translateX(19px); background: #fff; }

.btn {
  min-height: var(--tap); padding: 0 16px;
  border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text);
  font-size: 13px; font-weight: 650; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  touch-action: manipulation;
  transition: transform .1s var(--ease), filter .16s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(135deg, var(--acc), var(--acc2)); border-color: transparent; color: #fff; }
.btn-danger { color: #ff6b81; border-color: color-mix(in srgb, #ff3d71 40%, var(--line)); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 12px; }

.about { font-size: 11.5px; color: var(--dim); line-height: 1.6; }
.about a { color: var(--acc); }

/* --------------------------------------------------------------- transport */
.transport {
  grid-area: transport;
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border-top: 1px solid var(--line);
  z-index: 15;
}
.play {
  width: 50px; height: 50px; border-radius: 50%; flex: none;
  border: 0; cursor: pointer;
  background: linear-gradient(135deg, var(--acc), var(--acc2));
  color: #fff; display: grid; place-items: center;
  box-shadow: 0 6px 20px -8px var(--acc), 0 1px 0 rgba(255,255,255,.25) inset;
  transition: transform .1s var(--ease);
  touch-action: manipulation;
}
.play svg { width: 24px; height: 24px; fill: currentColor; }
.play:active { transform: scale(.94); }
.play.playing { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse {
  0%,100% { box-shadow: 0 6px 20px -8px var(--acc); }
  50% { box-shadow: 0 6px 28px -2px var(--acc); }
}

.bpm {
  display: flex; align-items: center; gap: 2px;
  background: var(--pad-off); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 2px;
}
.bpm button {
  width: 30px; height: 34px; border: 0; border-radius: 7px;
  background: transparent; color: var(--dim);
  font-size: 17px; font-weight: 600; cursor: pointer; line-height: 1;
  touch-action: manipulation;
}
.bpm button:active { background: var(--panel-2); color: var(--text); }
.bpm-num {
  min-width: 34px; text-align: center;
  font-size: 16px; font-weight: 750; letter-spacing: -.02em;
}
.tp-label {
  font-size: 8.5px; font-weight: 700; letter-spacing: .1em;
  color: var(--dim); text-transform: uppercase;
}
.tp-group { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.tp-swing { display: flex; }
.tp-info { display: none; }
.readout {
  font-size: 11.5px; font-weight: 700; color: var(--dim);
  padding: 3px 8px; border-radius: 6px; background: var(--pad-off);
  border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.head-right { display: flex; align-items: center; gap: 8px; }
.tap {
  height: 38px; min-width: 46px; padding: 0 10px;
  border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--panel-2); color: var(--dim);
  font-size: 11px; font-weight: 800; letter-spacing: .08em;
  cursor: pointer; touch-action: manipulation;
}
.tap:active { background: var(--acc); color: #fff; border-color: transparent; }
.tp-spacer { flex: 1; }

/* ------------------------------------------------------------------- icons */
.icon {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--panel-2); color: var(--dim);
  cursor: pointer; flex: none; padding: 0;
  touch-action: manipulation;
  transition: transform .1s var(--ease), background .16s, color .16s;
}
.icon:active { transform: scale(.94); }
.icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon.danger { color: #ff5a72; }
.icon-sm { width: 34px; height: 34px; }
.icon-sm svg { width: 16px; height: 16px; }

#btn-record { position: relative; }
#btn-record .rec-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: #ff3d71; transition: transform .2s;
}
#btn-record.recording { border-color: #ff3d71; background: color-mix(in srgb, #ff3d71 18%, var(--panel-2)); }
#btn-record.recording .rec-dot { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .25; } }
.rec-time {
  position: absolute; bottom: -2px; right: -2px;
  font-size: 8px; font-weight: 700; color: #ff5a72;
  background: var(--panel); padding: 0 2px; border-radius: 3px;
}

/* ------------------------------------------------------------------ tabbar */
.tabbar {
  grid-area: tabs;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
.tabbar .navbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-height: var(--tabbar);
  background: none; border: 0; cursor: pointer; padding: 0;
  color: var(--dim); font-size: 9.5px; font-weight: 650; letter-spacing: .02em;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color .16s;
}
.tabbar .navbtn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabbar .navbtn.active { color: var(--acc); }
.tabbar .navbtn.active svg { stroke-width: 2.1; }

/* ------------------------------------------------------------------ toasts */
#toasts {
  position: fixed; left: 50%; bottom: calc(var(--transport) + var(--tabbar) + 12px);
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  z-index: 60; pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  pointer-events: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--acc);
  color: var(--text);
  font-size: 12.5px; font-weight: 600;
  padding: 9px 14px; border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0,0,0,.45);
  animation: toastIn .18s var(--ease);
}
.toast { display: flex; align-items: center; gap: 10px; }
.toast-msg { flex: 1; }
.toast-act {
  flex: none; min-height: 28px; padding: 0 10px;
  border-radius: 7px; border: 1px solid var(--acc);
  background: transparent; color: var(--acc);
  font-size: 11.5px; font-weight: 700; cursor: pointer;
}
.toast-success { border-left-color: #00d68f; }
.toast-warn { border-left-color: #ffaa00; }
.toast-error { border-left-color: #ff3d71; }
.toast.out { opacity: 0; transform: translateY(4px); transition: all .2s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

.keys {
  display: grid; grid-template-columns: 1fr auto;
  gap: 8px 14px; align-items: center;
  font-size: 12.5px; color: var(--text);
}
.keys kbd {
  justify-self: end;
  font: inherit; font-size: 11px; font-weight: 650;
  color: var(--dim);
  background: var(--pad-off);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 8px;
  white-space: nowrap;
}
#btn-undo[disabled] { opacity: .35; cursor: default; }

.song-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.slot {
  min-height: 54px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--panel-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  cursor: pointer; color: var(--dim); padding: 6px 4px;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: border-color .16s, background .16s, color .16s;
}
.slot .slot-id { font-size: 13px; font-weight: 750; letter-spacing: .04em; }
.slot .slot-name { font-size: 9.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.slot.filled { color: var(--text); border-color: color-mix(in srgb, var(--acc) 40%, var(--line)); }
.slot.playing { border-color: var(--acc); background: color-mix(in srgb, var(--acc) 16%, var(--panel-2)); color: var(--text); box-shadow: 0 0 0 1px var(--acc) inset; }
.song-hint { font-size: 10.5px; color: var(--dim); margin-top: 10px; line-height: 1.45; }

.row-menu {
  position: fixed; z-index: 70;
  display: flex; flex-direction: column; min-width: 132px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 16px 40px rgba(0,0,0,.5);
}
.row-menu button {
  text-align: left; padding: 10px 14px; min-height: 40px;
  background: none; border: 0; color: var(--text);
  font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.row-menu button:hover { background: var(--pad-off); }
.row-menu button[disabled] { opacity: .35; cursor: default; }

/* ----------------------------------------------------------------- presets */
.preset-save { display: flex; gap: 8px; margin-bottom: 10px; }
.text-input {
  flex: 1; min-width: 0; min-height: 38px;
  padding: 0 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--pad-off);
  color: var(--text);
  font-size: 13px;
}
.text-input::placeholder { color: var(--dim); }
.text-input:focus { outline: 2px solid var(--acc); outline-offset: 1px; border-color: transparent; }

.preset-list { display: flex; flex-direction: column; }
.preset-row {
  display: flex; align-items: center; gap: 10px;
  min-height: 46px; padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.preset-row:last-child { border-bottom: 0; }
.preset-row .p-name {
  flex: 1; min-width: 0; font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.preset-row .p-meta { font-size: 10.5px; color: var(--dim); font-weight: 500; }
.preset-row button { flex: none; }
.p-empty { font-size: 12px; color: var(--dim); padding: 6px 0; }

/* ------------------------------------------------------------------ sheet */
.sheet {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px;
  animation: fadeIn .2s ease;
}
.sheet-card {
  width: 100%; max-width: 420px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 -10px 40px rgba(0,0,0,.5);
}
.sheet-card h3 { margin: 0 0 8px; font-size: 15px; font-weight: 700; }
.sheet-card p { margin: 0 0 18px; font-size: 13px; color: var(--dim); line-height: 1.55; }
.sheet-card b { color: var(--text); }
@keyframes fadeIn { from { opacity: 0; } }

/* ------------------------------------------------------------------ loader */
#loader {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center;
  background: var(--bg);
  transition: opacity .3s;
}
#loader.gone { opacity: 0; pointer-events: none; }
.loader-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--acc), var(--acc2));
  animation: bob 1.1s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-6px) scale(.96); } }

/* ============================================================== responsive */
@media (min-width: 560px) {
  .faders { grid-template-columns: repeat(6, 1fr); }
  .amb-grid { grid-template-columns: repeat(3, 1fr); }
  .themes-grid { grid-template-columns: repeat(3, 1fr); }
  .fx-grid { grid-template-columns: repeat(6, 1fr); }
}

@media (min-width: 720px) {
  .app {
    grid-template-columns: 72px minmax(0, 1fr);
    grid-template-rows: var(--topbar) minmax(0, 1fr) 80px;
    grid-template-areas:
      "top   top"
      "rail  stage"
      "rail  transport";
  }
  .tabbar { display: none; }
  :root { --topbar: 58px; --transport: 80px; --head: 108px; --pad: 46px; }

  .rail {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 10px 0;
    background: linear-gradient(180deg, var(--panel), var(--panel-2));
    border-right: 1px solid var(--line);
  }
  .rail .navbtn {
    width: 52px; height: 50px; border-radius: 12px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    background: none; border: 0; color: var(--dim); cursor: pointer; padding: 0;
    font-size: 8.5px; font-weight: 650;
    transition: background .16s, color .16s;
  }
  .rail .navbtn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  .rail .navbtn:hover { background: var(--panel-2); color: var(--text); }
  .rail .navbtn.active { color: var(--acc); background: color-mix(in srgb, var(--acc) 12%, transparent); }

  .stage { padding: 16px 20px 24px; }
  .transport { padding: 0 20px; gap: 16px; }
  .tp-info { display: flex; flex-direction: column; gap: 2px; min-width: 90px; }
  .tp-info strong { font-size: 12.5px; font-weight: 650; }
  .tp-info span { font-size: 10.5px; color: var(--dim); }
  #toasts { bottom: calc(var(--transport) + 16px); }
  .seq-scroll { margin: 0; padding: 0; }
  .seq { width: 100%; max-width: 1010px; margin: 0 auto; }
  .seq-row.hit .seq-name { color: var(--acc); }
.seq-row.hit .seq-dot { transform: scale(1.6); }
.seq-dot { transition: transform .12s; }
.seq-row { grid-template-columns: var(--head) repeat(16, minmax(24px, 1fr)); }
  .pad { width: 100%; height: auto; aspect-ratio: 1.3; }
  .play { width: 54px; height: 54px; }
}

@media (min-width: 1024px) {
  #view-mix { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; align-content: center; }
  .amb-grid { grid-template-columns: repeat(5, 1fr); }
  .themes-grid { grid-template-columns: repeat(5, 1fr); }
  .fader { height: 140px; }
  :root { --pad: 48px; }
}

@media (max-width: 400px) {
  :root { --head: 78px; --pad: 40px; }
  .brand-name { font-size: 13px; }
}

@media (max-height: 700px) {
  .viz-wrap { display: none; }
  .fader { height: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
