/* Dark, high-contrast, readable at performance distance. An instrument
   companion, not an admin dashboard.

   Event kind is never carried by colour alone — each state also has a glyph and
   a word, so the view survives both a colour-blind reader and a washed-out
   laptop screen on a dark stage. */

:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #14181d;
  --panel-2: #1b2027;
  --line: #2a313a;
  --text: #e8edf3;
  --dim: #8b96a4;
  --hit: #f4f7fb;
  --accent: #ffd166;
  --ghost: #6fd3c7;
  --muted: #ff8b6b;
  --ok: #7ee081;
  --warn: #ffd166;
  --bad: #ff7a6b;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--mono);
  -webkit-font-smoothing: antialiased;
}

/* --- top bar --------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand-name { font-weight: 700; letter-spacing: 0.16em; }
.brand-sub { color: var(--dim); margin-left: 10px; letter-spacing: 0.06em; }

.tabs { display: flex; gap: 6px; margin-right: auto; }

.tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--dim);
  font: inherit;
  letter-spacing: 0.08em;
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
}
.tab.is-current { color: var(--text); border-color: var(--line); background: var(--panel-2); }
.tab:disabled { opacity: 0.35; cursor: not-allowed; }

.link { display: flex; align-items: center; gap: 10px; }

.pill {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  letter-spacing: 0.1em;
  font-size: 12px;
  color: var(--dim);
}
/* Status carries a border weight change as well as a hue. */
.pill[data-state="CONNECTED"] { color: var(--ok); border-color: var(--ok); }
.pill[data-state="STALE"],
.pill[data-state="CONNECTING"],
.pill[data-state="RECONNECTING"] { color: var(--warn); border-color: var(--warn); }
.pill[data-state="DISCONNECTED"] { color: var(--dim); }

.btn {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 16px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--dim); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-quiet { color: var(--dim); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.hint { margin: 12px 20px 0; color: var(--dim); min-height: 1.2em; }

.log {
  margin: 12px 20px 0;
  padding: 12px;
  max-height: 200px;
  overflow: auto;
  background: #05070a;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--dim);
  font-size: 12px;
  white-space: pre-wrap;
}

/* --- live view -------------------------------------------------------- */

.live { padding: 18px 20px 40px; }

.section-label {
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.18em;
  margin: 26px 0 8px;
}

.live-head {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-label { color: var(--dim); font-size: 11px; letter-spacing: 0.18em; }
.stat-value { font-size: 38px; line-height: 1.1; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-note { color: var(--accent); font-size: 12px; min-height: 1.2em; }
.transport { color: var(--dim); font-size: 26px; }
.transport.is-playing { color: var(--ok); }
.flags { font-size: 13px; color: var(--dim); padding-top: 10px; letter-spacing: 0.06em; }

/* --- step ruler ------------------------------------------------------- */

.ruler, .lane-steps {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  gap: 4px;
}

.ruler-cell {
  text-align: center;
  font-size: 11px;
  color: var(--dim);
  padding: 6px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}
.ruler-cell.beat { color: var(--text); border-color: var(--dim); }
.ruler-cell.is-playhead { background: var(--text); color: #000; border-color: var(--text); font-weight: 700; }

/* --- lanes ------------------------------------------------------------ */

.lanes { display: flex; flex-direction: column; gap: 6px; }

.lane {
  display: grid;
  grid-template-columns: 130px 130px 1fr;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.lane.is-muted { opacity: 0.75; border-style: dashed; }
.lane.is-idle { opacity: 0.5; }

.lane-name { letter-spacing: 0.12em; font-size: 13px; }
.badge {
  display: inline-block;
  margin-left: 8px;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--dim);
}
.badge.badge-muted { color: var(--muted); }

/* The hit indicator. --decay is set per frame; shape and word carry meaning,
   opacity only carries recency. */
.hit {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  opacity: calc(0.15 + 0.85 * var(--decay, 0));
}
.hit-glyph { font-size: 20px; line-height: 1; }
.hit-label { font-size: 11px; letter-spacing: 0.14em; }

.hit[data-kind="trig"]   { color: var(--hit);    border-color: var(--hit);    background: rgba(244, 247, 251, 0.10); }
.hit[data-kind="accent"] { color: var(--accent); border-color: var(--accent); background: rgba(255, 209, 102, 0.14); font-weight: 700; }
.hit[data-kind="ghost"]  { color: var(--ghost);  border-color: var(--ghost);  border-style: dashed; }
.hit[data-kind="muted"]  { color: var(--muted);  border-color: var(--muted);  border-style: dotted; }
.hit[data-kind=""]       { opacity: 0; }

/* Programmed steps, drawn quietly: orientation only, never the headline. */
.lane-cell {
  height: 16px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: transparent;
}
.lane-cell.on { background: var(--dim); border-color: var(--dim); }
.lane-cell.accent { background: var(--accent); border-color: var(--accent); }
.lane-cell.at-playhead { outline: 1px solid var(--text); outline-offset: 1px; }

/* --- knobs ------------------------------------------------------------ */

.pots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.pot {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.pot-name { color: var(--dim); font-size: 11px; letter-spacing: 0.18em; }
.pot-track { height: 8px; margin: 10px 0 6px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.pot-fill { height: 100%; background: var(--text); }
.pot-value { font-variant-numeric: tabular-nums; font-size: 13px; }

.live-note { color: var(--dim); font-size: 12px; margin-top: 28px; }

/* A drum machine monitor animates constantly by nature; honour the request to
   stop transitions, but keep the state changes themselves visible. */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  /* Drop the fade, keep the on/off: data-kind is cleared once an event decays,
     so the empty-kind rule below still hides it. */
  .hit { opacity: 1; }
  .hit[data-kind=""] { opacity: 0; }
}

@media (max-width: 720px) {
  .lane { grid-template-columns: 100px 110px; }
  .lane-steps { grid-column: 1 / -1; }
}

/* --- editor ----------------------------------------------------------- */

.editor { padding: 18px 20px 40px; }

.edit-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.btn.is-playing { color: var(--ok); border-color: var(--ok); }

.pattern-picker { display: flex; gap: 4px; }

.pat {
  font: inherit;
  width: 34px;
  padding: 6px 0;
  color: var(--dim);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
.pat.is-current { color: #000; background: var(--text); border-color: var(--text); font-weight: 700; }
/* A queued pattern launches on the next bar — dashed, not merely tinted. */
.pat.is-pending { color: var(--accent); border-color: var(--accent); border-style: dashed; }
.pat:disabled { opacity: 0.4; cursor: not-allowed; }

.notice { min-height: 1.3em; margin: 12px 0 4px; font-size: 13px; color: var(--dim); }
.notice[data-kind="error"] { color: var(--bad); }
.notice[data-kind="info"] { color: var(--text); }

.grid { display: flex; flex-direction: column; gap: 6px; }

.grid-row {
  display: grid;
  grid-template-columns: 150px 1fr 190px;
  align-items: center;
  gap: 12px;
}

.grid-cells { display: grid; grid-template-columns: repeat(16, 1fr); gap: 4px; }

.head-cell {
  text-align: center;
  font-size: 11px;
  color: var(--dim);
  padding: 4px 0;
  border-radius: 4px;
}
.head-cell.beat { color: var(--text); }
.head-cell.is-playhead { background: var(--text); color: #000; font-weight: 700; }

.mute {
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.08em;
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
.mute.is-muted { color: var(--muted); border-color: var(--muted); border-style: dashed; }
.mute:disabled { opacity: 0.4; cursor: not-allowed; }

.cell {
  height: 34px;
  padding: 0;
  font: inherit;
  font-size: 13px;
  color: #000;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
.cell:hover:not(:disabled) { border-color: var(--dim); }
.cell.on { background: var(--text); border-color: var(--text); }
.cell.accent { background: var(--accent); border-color: var(--accent); font-weight: 700; }
.cell.at-playhead { outline: 2px solid var(--dim); outline-offset: 1px; }
.cell.is-cursor { box-shadow: inset 0 0 0 2px var(--ghost); }
/* Pending: sent, not yet confirmed by the device. Striped rather than merely
   faded, so it is unmistakably "in flight" and not just a dim cell. */
.cell.is-pending {
  background-image: repeating-linear-gradient(45deg,
    rgba(255, 209, 102, 0.85) 0 4px, rgba(0, 0, 0, 0) 4px 8px);
  border-color: var(--accent);
}
.cell:disabled { opacity: 0.45; cursor: not-allowed; }

.grid-ops { display: flex; gap: 4px; }

.op {
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.06em;
  padding: 5px 9px;
  color: var(--dim);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
.op:hover:not(:disabled) { color: var(--text); border-color: var(--dim); }
.op:disabled { opacity: 0.35; cursor: not-allowed; }

@media (max-width: 900px) {
  .grid-row { grid-template-columns: 120px 1fr; }
  .grid-ops { grid-column: 2; justify-content: flex-end; }
}

/* --- library ---------------------------------------------------------- */

.library { padding: 18px 20px 60px; }

.lib-bar, .set-bar, .load-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.lib-bar { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.set-bar { margin: 18px 0; }
.load-bar { margin: 18px 0 8px; }

.save-state { margin-left: auto; font-size: 12px; letter-spacing: 0.1em; color: var(--dim); }
.save-state[data-unsaved="true"] { color: var(--accent); }

.set-select, .slot-pick {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
}
.slot-pick { width: 100%; margin-top: 8px; }

.field { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; }
.field-label { font-size: 10px; letter-spacing: 0.14em; color: var(--dim); }
.field-input {
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 7px;
  min-width: 0;
  flex: 1;
}

/* The slot map: eight slots, always visible. The library is unlimited; the
   instrument is not, and this is where that limit becomes the unit of work. */
.slot-map {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.slot {
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: var(--radius);
}
/* State is carried by the border, the word in .slot-state, and nothing that
   depends on colour alone. */
.slot[data-state="empty"]   { border-left-color: var(--line); opacity: 0.72; }
.slot[data-state="same"]    { border-left-color: var(--ok); }
.slot[data-state="differs"] { border-left-color: var(--accent); }
.slot[data-state="unknown"] { border-left-color: var(--dim); border-style: dashed; }

.slot-index { font-size: 10px; letter-spacing: 0.18em; color: var(--dim); }
.slot-name { font-size: 15px; margin: 4px 0 2px; }
.slot-state { font-size: 11px; letter-spacing: 0.08em; color: var(--dim); }
.slot[data-state="differs"] .slot-state { color: var(--accent); font-weight: 700; }
.slot[data-state="same"] .slot-state { color: var(--ok); }

.load-state { font-size: 12px; color: var(--dim); }
.load-state[data-partial="true"] { color: var(--bad); font-weight: 700; }

.confirm, .recover {
  margin: 12px 0;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}
.recover { border-color: var(--bad); }
.confirm-title, .recover-title { margin: 0 0 8px; font-size: 14px; }
.confirm-list { margin: 0 0 10px; padding-left: 20px; font-size: 12px; color: var(--dim); }
.confirm-warn { color: var(--accent); font-size: 13px; margin: 0 0 10px; }
.confirm-actions { display: flex; gap: 8px; }
.recover .btn { margin-right: 8px; }

.pattern-list { display: flex; flex-direction: column; gap: 8px; }

.pattern-card {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.pattern-card .field:first-child { flex: 1 1 220px; }

.empty-note { color: var(--dim); font-size: 13px; max-width: 62ch; }
