:root {
  --bg: #0c0d11;
  --surface: #15171d;
  --surface-2: #1c1f27;
  --surface-3: #252934;
  --line: #262a34;
  --text: #eceef3;
  --muted: #8b91a1;
  --faint: #7c8395;
  --accent: #8f7dff;
  --accent-soft: rgba(143, 125, 255, 0.16);
  --play: #3fd99a;
  --play-soft: rgba(63, 217, 154, 0.15);
  --queued: #ffb547;
  --queued-soft: rgba(255, 181, 71, 0.16);
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.15);
  --danger-glow: rgba(255, 107, 107, 0.5);
  --danger-ink: #1a0505;
  --danger-text: var(--danger);
  --queued-text: var(--queued);
  --play-text: var(--play);
  --on-accent: #0c0d11;
  --radius: 18px;
  --radius-sm: 10px;
  --topbar-bg: rgba(12, 13, 17, 0.85);
  --dial-hi: #1f2230;
  --arc-accent: #343948;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f2f3f7;
  --surface: #ffffff;
  --surface-2: #eceef3;
  --surface-3: #dfe2ea;
  --line: #dde0e7;
  --text: #15171d;
  --muted: #5b6273;
  --faint: #6c7282;
  --accent: #6b59f0;
  --accent-soft: rgba(107, 89, 240, 0.12);
  --play: #13a86c;
  --play-soft: rgba(19, 168, 108, 0.12);
  --queued: #d98500;
  --queued-soft: rgba(217, 133, 0, 0.12);
  --danger: #e04848;
  --danger-soft: rgba(224, 72, 72, 0.12);
  --danger-glow: rgba(224, 72, 72, 0.45);
  --danger-ink: #fff;
  --danger-text: #c22f2f;
  --queued-text: #9a5c00;
  --play-text: #0b7a4d;
  --on-accent: #fff;
  --topbar-bg: rgba(255, 255, 255, 0.88);
  --dial-hi: #ffffff;
  --arc-accent: #b9bdca;
  --shadow: 0 10px 40px rgba(20, 24, 40, 0.18);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 12px max(20px, env(safe-area-inset-left));
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.01em; font-size: 17px; }
.transport { display: flex; align-items: center; gap: 18px; margin: 0 auto; }
.transport .field { flex-direction: row; align-items: center; gap: 10px; }
.transport .field label { margin: 0; }
.play {
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  box-shadow: 0 6px 24px rgba(143, 125, 255, 0.35);
  transition: transform .12s, background .2s;
}
.play:active { transform: scale(.94); }
.play svg { width: 24px; height: 24px; fill: currentColor; }
.play .i-stop, .running .play .i-play { display: none; }
.running .play .i-stop { display: block; }
.running .play { background: var(--danger); color: var(--danger-ink); box-shadow: 0 0 0 4px var(--danger-soft), 0 0 20px var(--danger-glow); }
.bar-count { display: flex; flex-direction: column; align-items: center; min-width: 36px; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 18px; line-height: 1.1; }
.bar-count small { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-weight: 500; }
.master { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.master svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
.master input { width: 110px; }

/* ---------- Layout ---------- */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 16px;
  padding: 16px max(20px, env(safe-area-inset-left)) 8px;
  max-width: 1280px; margin: 0 auto;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  display: flex; flex-direction: column; gap: 18px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.head-tools { display: flex; align-items: center; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; display: flex; gap: 8px; align-items: baseline; }
.field label small { color: var(--faint); font-weight: 400; }
.field output { margin-left: auto; color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Controls ---------- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.seg button { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-size: 13px; font-weight: 500; min-width: 44px; min-height: 44px; transition: background .15s, color .15s; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25), inset 0 0 0 1.5px var(--accent); }

select {
  background: var(--surface-2); border: 0; border-radius: 8px; padding: 6px 28px 6px 10px; font-size: 13px;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238b91a1' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}

input[type=range] {
  margin: 0;
  -webkit-appearance: none; appearance: none; background: transparent; height: 44px; width: 100%; cursor: pointer;
  --pct: 50%;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 6px;
  background: linear-gradient(to right, var(--accent) var(--pct), var(--surface-3) var(--pct));
}
input[type=range]::-moz-range-track { height: 6px; border-radius: 6px; background: var(--surface-3); }
input[type=range]::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 24px; height: 24px; border-radius: 50%; background: #fff; margin-top: -9px;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
input[type=range]::-moz-range-thumb { width: 24px; height: 24px; border: 0; border-radius: 50%; background: #fff; }
input.mini { width: 96px; flex: 0 1 auto; min-width: 0; }

.btn, .ghost {
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
  padding: 7px 12px; border-radius: 9px; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.ghost { color: var(--muted); }

.round {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  background: var(--surface-2); font-size: 20px; line-height: 1;
}
.round:active, .tap:active { transform: scale(.94); }

/* ---------- Metronome ---------- */
.dial-wrap { position: relative; width: min(100%, 300px); aspect-ratio: 1; margin: 0 auto; }
.dial { width: 100%; height: 100%; display: block; }
.dial .seg-arc { fill: none; stroke: var(--surface-3); stroke-linecap: round; transition: stroke .25s ease-out; }
.dial .seg-arc.accent { stroke: var(--arc-accent); }
.dial .seg-arc.mute { stroke: var(--surface-2); stroke-dasharray: 2 6; }
.dial .seg-arc.hit { stroke: var(--accent); transition: none; }
.dial .seg-arc.hit.accent { stroke: var(--text); }
.dial-center {
  position: absolute; inset: 22%; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 35%, var(--dial-hi), var(--surface-2));
  cursor: ns-resize; user-select: none; touch-action: none;
  transition: transform .08s;
}
.dial-center.pulse { transform: scale(1.035); }
.dial-center:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 50%; }
.bpm { font-size: clamp(48px, 9vw, 68px); font-weight: 700; letter-spacing: -0.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.bpm-label { margin-top: 6px; font-size: 12px; color: var(--muted); letter-spacing: .04em; }

.tempo-row { display: flex; align-items: center; gap: 12px; }
.tap {
  height: 44px; padding: 0 18px; border-radius: 22px; flex: none;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}
.tap.flash { background: var(--accent); color: var(--on-accent); }

.metro-opts { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; }
.stepper { display: inline-flex; align-items: center; background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; }
.stepper button { width: 44px; height: 44px; min-height: 44px; border-radius: 8px; font-size: 18px; }
.stepper span { min-width: 44px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

.accents { display: flex; gap: 6px; height: 58px; }
.accents button {
  flex: 1; min-width: 0; border-radius: 8px; background: var(--surface-2);
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center; padding: 6px 0 5px; gap: 4px;
  position: relative;
}
.accents button i { display: block; width: 60%; max-width: 26px; border-radius: 3px; background: var(--faint); height: 40%; transition: background .2s; }
.accents button[data-a="2"] i { height: 72%; background: var(--text); }
.accents button[data-a="0"] i { height: 3px; background: var(--surface-3); }
.accents button span { font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.accents button.hit i { background: var(--accent); transition: none; }

/* ---------- Pads ---------- */
.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.key {
  position: relative; aspect-ratio: 1.45; border-radius: 14px;
  background: var(--surface-2); border: 1px solid transparent;
  font-size: clamp(24px, 3.4vw, 38px); font-weight: 700; letter-spacing: -0.02em;
  display: grid; place-items: center; user-select: none; touch-action: none;
  transition: background .25s, border-color .25s, transform .08s;
}
.key:active { transform: scale(.97); }
.key.on {
  background: var(--accent); color: #fff;
  border-color: transparent;
  box-shadow: 0 0 0 3px var(--accent-soft), 0 0 40px var(--accent);
}
.key.on small { color: rgba(255,255,255,.8); }
.key.on::after {
  content: ""; position: absolute; right: 10px; top: 10px; width: 8px; height: 8px; border-radius: 50%;
  background: #fff; animation: breathe 2.4s ease-in-out infinite;
}
.key.queued {
  border-color: var(--queued); background: var(--queued-soft);
  box-shadow: inset 0 0 0 3px var(--queued); animation: qpulse 1s ease-in-out infinite;
}
/* On and queued to stop: amber ring over a dimmed glow. */
.key.on.queued {
  background: var(--accent);
  box-shadow: inset 0 0 0 3px var(--queued), 0 0 0 3px var(--accent-soft), 0 0 16px var(--accent-soft);
  animation-name: qpulse-on;
}
.pad-opts { grid-auto-flow: row dense; }
.pad-opts .wide { grid-column: 1 / -1; }
.pad-opts .wide .seg { display: flex; }
.pad-opts .wide .seg button { flex: 1; }
.loading { margin-left: 8px; font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--queued-text); }
.loading[hidden] { display: none; }
/* Samples failed: a tappable retry pill (JS sets class, role and text). */
.loading.error {
  display: inline-flex; align-items: center; min-height: 44px; padding: 6px 12px; vertical-align: middle;
  color: var(--danger-text); background: var(--danger-soft); border: 1px solid var(--danger); border-radius: 999px;
  cursor: pointer;
}
.loading.error[hidden] { display: none; }
.credit { margin: 0; font-size: 10.5px; color: var(--faint); }
.credit a { color: inherit; }
.pad-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px 20px; }

/* ---------- Clips ---------- */
.clip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.clip-grid:empty { display: none; }
.clip {
  position: relative; overflow: hidden; border-radius: 14px; min-height: 92px;
  background: var(--surface-2); border: 1px solid transparent; text-align: left;
  padding: 12px 12px 10px; display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
  user-select: none;
}
.clip .name { font-weight: 600; font-size: 14px; line-height: 1.25; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clip .meta { display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.clip .tools { display: flex; gap: 2px; }
.clip .tools span { padding: 3px 6px; border-radius: 6px; color: var(--faint); font-size: 12px; }
.clip .tools .loop.on { color: var(--play-text); }
.clip .prog { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--play); width: 0; }
.clip.playing { background: var(--play-soft); border-color: rgba(63,217,154,.5); }
.clip.queued { background: var(--queued-soft); border-color: var(--queued); box-shadow: inset 0 0 0 3px var(--queued); animation: qpulse 1s ease-in-out infinite; }
.clips.drag { border-color: var(--accent); background: var(--accent-soft); }
.empty { margin: 0; color: var(--faint); font-size: 13px; text-align: center; padding: 18px 12px; border: 1px dashed var(--line); border-radius: 14px; }

/* ---------- Setlist ---------- */
.song-form { display: flex; gap: 8px; }
.song-form[hidden] { display: none; }
.song-form input { flex: 1; min-width: 0; background: var(--surface-2); border: 1px solid var(--faint); border-radius: 9px; padding: 7px 10px; }
.songs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; counter-reset: song; }
.songs:empty { display: none; }
.song {
  display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 14px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid transparent; cursor: pointer; counter-increment: song;
}
.song::before { content: counter(song); color: var(--faint); font-size: 12px; width: 14px; font-variant-numeric: tabular-nums; }
.song .title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song .info { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.song .del { color: var(--faint); padding: 2px 8px; border-radius: 6px; }
.song.current { border-color: rgba(143,125,255,.5); background: var(--accent-soft); }
.song.queued {
  border-color: var(--queued); background: var(--queued-soft);
  box-shadow: inset 0 0 0 3px var(--queued); animation: qpulse 1s ease-in-out infinite;
}

/* ---------- Footer ---------- */
.foot { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; padding: 14px 20px 28px; color: var(--faint); font-size: 12px; }
kbd { font: 11px Inter, sans-serif; padding: 2px 6px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); margin-right: 4px; }

@keyframes blink { 50% { border-color: transparent; } }
@keyframes breathe { 50% { opacity: .3; } }
@keyframes qpulse { 50% { box-shadow: inset 0 0 0 3px transparent; } }
@keyframes qpulse-on { 50% { box-shadow: inset 0 0 0 3px transparent, 0 0 0 3px var(--accent-soft), 0 0 16px var(--accent-soft); } }

/* ---------- Single-screen landscape (iPad landscape, laptops) ----------
   Three columns that fill the viewport: metronome | pads | cues over setlist.
   Nothing scrolls except the cue and setlist lists inside their cards. */
@media (min-width: 1000px) and (min-height: 600px) and (min-aspect-ratio: 5/4) {
  body { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
  .topbar { position: static; flex: none; padding-top: 8px; padding-bottom: 8px; }
  .play { width: 46px; height: 46px; }
  .foot { display: none; }
  .tempo-row .tap { height: 40px; }
  .seg button { min-height: 40px; }
  .grid {
    flex: 1; min-height: 0; width: 100%; max-width: 1600px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) minmax(0, 0.95fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px; padding: 12px max(16px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-bottom));
  }
  .card { min-height: 0; padding: 14px 16px; gap: 12px; overflow: hidden; }
  .metro { grid-column: 1; grid-row: 1 / 3; justify-content: space-between; }
  .pads { grid-column: 2; grid-row: 1 / 3; }
  .clips { grid-column: 3; grid-row: 1; }
  .setlist { grid-column: 3; grid-row: 2; }

  /* Dial shrinks with screen height so the controls below always fit. */
  .dial-wrap { width: min(100%, 320px, calc(100dvh - 420px)); min-width: 150px; container-type: inline-size; }
  .bpm { font-size: 24cqi; }
  .bpm-label { font-size: max(10px, 4.4cqi); margin-top: 2px; }
  .metro-opts { gap: 12px; flex-wrap: nowrap; }
  .metro-opts .seg button { min-width: 40px; padding: 6px 8px; }
  .stepper span { min-width: 36px; }
  .accents { height: 50px; }

  /* Keys stretch to fill whatever height the pad card has left. */
  .keys { flex: 1; min-height: 0; grid-auto-rows: minmax(0, 1fr); gap: 8px; }
  .key { aspect-ratio: auto; min-height: 44px; }
  .pad-opts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; flex: none; }
  .pad-opts .seg { display: flex; }
  .pad-opts .seg button { flex: 1; padding: 6px 4px; min-width: 0; }

  .clip-grid, .songs { flex: 1; min-height: 0; overflow-y: auto; align-content: start; overscroll-behavior: contain; }
  .clip-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
  .clip { min-height: 74px; padding: 10px; }
  .empty { padding: 12px 10px; font-size: 12px; }
}

@media (min-width: 1000px) and (max-width: 1320px) and (min-height: 600px) and (min-aspect-ratio: 5/4) {
  .brand span { display: none; }
  /* Quant label becomes a small caption above the segment. */
  .transport .field { flex-direction: column; align-items: center; gap: 2px; }
  #quantLabel { font-size: 10px; line-height: 1; text-transform: uppercase; letter-spacing: .08em; }
  .topbar { gap: 14px; }
  .master input { width: 80px; }
  input.mini { width: 96px; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .transport .field { flex-direction: column; align-items: center; gap: 2px; }
  .transport .field label { font-size: 10px; line-height: 1; text-transform: uppercase; letter-spacing: .08em; }
  .foot { display: none; }
}
/* Portrait tablet: two columns so pads and setlist are on the first screen. */
@media (min-width: 700px) and (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .metro { grid-column: 1; grid-row: 1; }
  .setlist { grid-column: 1; grid-row: 2; }
  .pads { grid-column: 2; grid-row: 1 / span 2; }
  .clips { grid-column: 1 / -1; grid-row: 3; }
  .dial-wrap { width: min(100%, 240px); }
  .keys { grid-template-columns: repeat(3, 1fr); }
  .key { aspect-ratio: 1.8; }
}
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; gap: 10px 14px; padding: 10px 16px; }
  .brand { font-size: 15px; }
  .transport { order: 3; width: 100%; justify-content: space-between; margin: 0; }
  .master input { width: 80px; }
  .master { margin-left: auto; }
  .grid { padding: 12px 16px; gap: 12px; }
  .card { padding: 16px; gap: 16px; }
  .keys { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .tempo-row { gap: 8px; }
  .tap { padding: 0 14px; }
  input.mini { width: 96px; }
}

/* ---------- Top bar additions ---------- */
.top-tools { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  position: relative; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  color: var(--muted); background: var(--surface-2);
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
#lockBtn .i-locked, #lockBtn[aria-pressed="true"] .i-unlocked { display: none; }
#lockBtn[aria-pressed="true"] .i-locked { display: block; }
#lockBtn[aria-pressed="true"] { background: var(--queued-soft); color: var(--queued-text); }
#lockBtn .hold-ring { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; }
#lockBtn.holding .hold-ring { box-shadow: inset 0 0 0 3px var(--queued); animation: hold 1s linear forwards; }
@keyframes hold { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

.now {
  display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1 1 260px; max-width: 420px;
  background: var(--surface-2); border-radius: 14px; padding: 4px;
}
.now-nav {
  width: 44px; height: 44px; flex: none; border-radius: 10px; display: grid; place-items: center;
  background: var(--surface); color: var(--text);
}
.now-nav:disabled { opacity: .35; cursor: default; }
.now-nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.now-text { flex: 1; min-width: 0; text-align: center; line-height: 1.2; }
.now-title { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-title.queued { color: var(--queued-text); }
.now-sub { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.pad-on .now-sub { color: var(--text); font-weight: 600; }

/* ---------- Buttons ---------- */
.chip {
  min-height: 44px; padding: 5px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid transparent;
}
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.pill { height: 44px; min-height: 44px; padding: 0 12px; border-radius: 22px; background: var(--surface-2); font-size: 13px; font-weight: 600; flex: none; font-variant-numeric: tabular-nums; }
.tempo-row .tap { flex: 1; }
.stop-btn {
  min-height: 44px; padding: 7px 14px; border-radius: 9px; font-size: 13px; font-weight: 700;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
body.pad-on .stop-btn { background: var(--danger); color: var(--danger-ink); border-color: var(--danger); }
.danger-btn { min-height: 44px; padding: 8px 14px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--danger-text); background: transparent; border: 1px solid var(--danger); }

/* Tap-to-type tempo */
.bpm-input {
  width: 70%; font-size: clamp(36px, 7vw, 56px); font-weight: 700; text-align: center;
  background: var(--surface); border: 2px solid var(--accent); border-radius: 12px; color: var(--text);
  -moz-appearance: textfield;
}
.bpm-input::-webkit-inner-spin-button, .bpm-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.bpm[hidden], .bpm-input[hidden] { display: none; }

/* ---------- Full-screen beat flash ---------- */
.flash {
  position: fixed; inset: 0; z-index: 50; pointer-events: none; opacity: 0;
  display: grid; place-items: center; background: var(--accent);
}
.flash.accent { background: #fff; }
:root[data-theme="light"] .flash.accent { background: var(--text); }
.flash.go { animation: beatflash .22s ease-out; }
.flash.count.go { animation-duration: .45s; }
.flash span { font-size: 40vmin; font-weight: 800; color: var(--bg); line-height: 1; }
@keyframes beatflash { from { opacity: .55; } to { opacity: 0; } }

/* ---------- Cue tiles ---------- */
.clip { --clip: transparent; }
.clip.tinted { box-shadow: inset 4px 0 0 var(--clip); background: color-mix(in srgb, var(--clip) 14%, var(--surface-2)); }
.clip-top { display: flex; gap: 8px; align-items: flex-start; min-width: 0; }
.clip .num { font-size: 11px; font-weight: 700; color: var(--faint); min-width: 10px; padding-top: 2px; font-variant-numeric: tabular-nums; }
.clip .mode { font-weight: 600; }
.clip .mode.loop { color: var(--play-text); }
.clip .edit { padding: 10px 12px; margin: -8px -6px -8px 0; border-radius: 8px; color: var(--faint); font-size: 16px; line-height: 1; }
/* Tinted tiles come after .clip.queued in the cascade, so restate the ring with the tint stripe. */
.clip.tinted.queued { background: var(--queued-soft); box-shadow: inset 4px 0 0 var(--clip), inset 0 0 0 3px var(--queued); animation-name: qpulse-tint; }
@keyframes qpulse-tint { 50% { box-shadow: inset 4px 0 0 var(--clip), inset 0 0 0 3px transparent; } }

/* ---------- Setlist rows ---------- */
.song { padding-left: 6px; }
.song::before { display: none; }
.song .handle {
  cursor: grab; color: var(--faint); padding: 8px 6px; touch-action: none; user-select: none;
  font-size: 14px; letter-spacing: -2px; line-height: 1;
  min-width: 44px; min-height: 44px; margin: -10px 0; display: inline-grid; place-items: center;
}
.song .edit { color: var(--faint); padding: 4px 8px; border-radius: 8px; min-width: 44px; min-height: 44px; margin: -10px -4px; display: inline-grid; place-items: center; }
.song.dragging { opacity: .85; border-color: var(--accent); box-shadow: var(--shadow); }

/* ---------- Dialog sheets ---------- */
.sheet {
  border: 1px solid var(--line); border-radius: 18px; padding: 0; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(0,0,0,.5); backdrop-filter: blur(3px); }
.sheet form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.sheet h3 { margin: 0; font-size: 17px; }
.sheet .row { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 500; flex: 1; min-width: 0; }
.sheet .row2 { display: flex; gap: 12px; }
.sheet input:not([type=range]), .sheet select {
  background-color: var(--surface-2); border: 1px solid var(--faint); border-radius: 9px; padding: 9px 10px;
  font-size: 15px; color: var(--text); width: 100%;
}
.sheet select { padding-right: 28px; }
.sheet .seg { display: flex; }
.sheet .seg button { flex: 1; }
.sheet-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.sheet-actions .spacer { flex: 1; }
.hint { margin: 0; font-size: 12px; color: var(--faint); font-weight: 400; line-height: 1.45; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 32px; height: 32px; border-radius: 50%; background: var(--sw);
  border: 2px solid var(--line); position: relative; overflow: hidden;
}
.swatch[data-c=""]::after { content: ""; position: absolute; left: -4px; right: -4px; top: 50%; border-top: 2px solid var(--faint); transform: rotate(-45deg); }
.swatch[aria-checked="true"] { outline: 2px solid var(--text); outline-offset: 2px; }

/* ---------- Lock mode ---------- */
.lock-banner {
  position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40;
  background: var(--queued); color: #1a1205; font-size: 13px; font-weight: 700; padding: 7px 14px; border-radius: 999px;
  box-shadow: var(--shadow); pointer-events: none;
}
.lock-banner[hidden] { display: none; }
/* iOS suspended the audio context: big tap target at top centre, away from the lock banner. */
.audio-resume {
  position: fixed; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 48px); left: 50%; transform: translateX(-50%); z-index: 45;
  display: inline-flex; align-items: center; min-height: 44px; padding: 10px 18px; border-radius: 999px;
  background: var(--danger); color: var(--danger-ink); font-size: 14px; font-weight: 700; white-space: nowrap;
  box-shadow: 0 0 0 4px var(--danger-soft), var(--shadow);
}
.audio-resume[hidden] { display: none; }
body.locked .grid, body.locked .topbar .transport .field, body.locked .master, body.locked #settingsBtn { pointer-events: none; }
body.locked .keys, body.locked #padStop, body.locked .clip-grid, body.locked .songs .song { pointer-events: auto; }
body.locked .clip .edit, body.locked .song .edit, body.locked .song .handle { visibility: hidden; }
body.locked .metro > :not(.card-head):not(.dial-wrap),
body.locked .pad-opts, body.locked .card-head .head-tools > :not(#padStop),
body.locked #songAdd, body.locked .topbar .transport .field, body.locked .master, body.locked #settingsBtn { opacity: .4; }

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; row-gap: 10px; column-gap: 14px; }
  .master input { width: 80px; }
  .now { order: 2; flex-basis: 100%; max-width: none; }
  .now-title { font-size: 20px; }
}
@media (max-width: 600px) {
  .topbar { position: static; } /* too tall to pin on a phone */
  .top-tools { margin-left: auto; }
  .now-title { font-size: 17px; }
  .tempo-row .pill { padding: 0 8px; }
}

/* ---------- Hover (mouse only) and touch press feedback ----------
   iPad keeps :hover stuck on the last tapped element, so hover styles only apply to real pointers. */
@media (hover: hover) and (pointer: fine) {
  .seg button:hover { color: var(--text); }
  .btn:not(.primary):hover { background: var(--surface-3); }
  .ghost:hover { color: var(--text); background: var(--surface-2); }
  .round:hover, .pill:hover, .stepper button:hover { background: var(--surface-3); }
  .key:not(.on):not(.queued):hover { background: var(--surface-3); }
  .clip:not(.playing):not(.queued):not(.tinted):hover { background: var(--surface-3); }
  .clip .tools span:hover { background: rgba(255,255,255,.06); color: var(--text); }
  .clip .edit:hover, .song .edit:hover { background: var(--surface-3); color: var(--text); }
  .song:not(.current):not(.queued):hover { background: var(--surface-3); }
  .song .del:hover { color: var(--danger-text); background: var(--danger-soft); }
  .icon-btn:hover { color: var(--text); }
}
.seg button:active, .btn:not(.primary):active, .ghost:active, .chip:active, .round:active, .pill:active,
.stepper button:active, .icon-btn:active, .now-nav:active, .clip .edit:active, .song .edit:active,
.key:not(.on):not(.queued):active, .song:not(.current):not(.queued):active { background: var(--surface-3); }

/* ---------- Reduced motion ---------- */
@keyframes beatflash-soft { from { opacity: .18; } to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .flash.go { animation-name: beatflash-soft; }
  .dial-center.pulse { transform: none; }
  .key.on::after { animation: none; }
  .key.queued, .clip.queued, .song.queued { animation: none; }
}
