:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel2: #1c2330;
  --border: #2a3340;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #3b82f6;
  --accent2: #8b5cf6;
  --good: #10b981;
  --warn: #f59e0b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: radial-gradient(1200px 600px at 70% -10%, #1b2540 0%, var(--bg) 55%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

.hidden { display: none !important; }
code { background: #00000055; padding: 1px 5px; border-radius: 4px; font-size: .85em; }

/* ---- top bar ---- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  background: #0d111799; backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 5; gap: 12px; flex-wrap: wrap;
}
.brand { font-size: 1.05rem; }
.brand .tag {
  font-size: .7rem; color: var(--muted); border: 1px solid var(--border);
  padding: 2px 7px; border-radius: 20px; margin-left: 6px;
}
.status { font-size: .82rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.status b { color: var(--text); }
.status .sep { opacity: .4; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.off { background: #6b7280; }
.dot.on { background: var(--good); box-shadow: 0 0 8px var(--good); }
.dot.warn { background: var(--warn); }

/* ---- panels ---- */
.panel { max-width: 1080px; margin: 0 auto; padding: 22px 18px; }
.join h1 { font-size: 2rem; margin: 18px 0 8px; }
.join .lead { color: var(--muted); max-width: 680px; line-height: 1.55; }
.form {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px; align-items: end; margin: 22px 0 8px; max-width: 760px;
}
label { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); }
input, select, button { font: inherit; }
input[type=text], input:not([type]), select, input[type=number] {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 10px 12px; outline: none;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
button { cursor: pointer; border-radius: 8px; border: 1px solid var(--border); background: var(--panel2); color: var(--text); padding: 10px 16px; }
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: none; font-weight: 600; }
button.primary.big { font-size: 1.1rem; padding: 16px 26px; }
button.ghost { background: transparent; }
button:hover { filter: brightness(1.1); }
.hint, .legend { color: var(--muted); font-size: .8rem; }
.hint { margin-top: 18px; }

/* ---- jam controls ---- */
.row { margin: 14px 0; }
.controls {
  display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-end;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
}
.control { display: flex; flex-direction: column; gap: 6px; font-size: .8rem; color: var(--muted); }
.control label { flex-direction: row; gap: 6px; align-items: center; }
.control b { color: var(--text); }
.control input[type=range] { width: 150px; accent-color: var(--accent); }
.control.metro .bpmwrap { font-size: .8rem; }
.control.metro input[type=number] { width: 64px; padding: 5px 8px; }
.midi-status { font-size: .8rem; }

/* forgiving controls */
.control.forgive { background: #11233b; border: 1px solid #1e3a5f; border-radius: 10px; padding: 8px 12px; }
.control.forgive > label { color: var(--text); font-weight: 600; }
.forgive-sub { display: flex; gap: 14px; margin-top: 8px; }
.forgive-sub label { gap: 4px; }
.forgive-sub select { padding: 5px 8px; }
.forgive-sub.disabled { opacity: .4; pointer-events: none; }

.error { color: #fca5a5; background: #3a1414; border: 1px solid #5b1d1d; border-radius: 8px; padding: 9px 12px; font-size: .85rem; }

/* AI bandmate control */
.control.band { background: #0e2622; border: 1px solid #1e4a43; border-radius: 10px; padding: 8px 12px; }
.control.band > label { color: var(--text); font-weight: 600; }
.control.band select { padding: 5px 8px; margin-top: 6px; }

/* ---- main split ---- */
.main { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: start; }
.peers, .stage { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.peers h3 { margin: 0 0 10px; font-size: .9rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
#peerList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
#peerList li { display: flex; align-items: center; gap: 9px; font-size: .9rem; }
#peerList .pcolor { width: 11px; height: 11px; border-radius: 50%; flex: none; }
#peerList .pinst { color: var(--muted); font-size: .78rem; margin-left: auto; }
#peerList .me { font-weight: 600; }

/* ---- keyboard ---- */
.keyboard { position: relative; height: 170px; display: flex; user-select: none; touch-action: none; }
.key {
  position: relative; border: 1px solid #00000066; border-radius: 0 0 6px 6px; cursor: pointer;
}
.key.white { background: linear-gradient(#fafafa, #e9e9ef); flex: 1; z-index: 1; }
.key.black {
  background: linear-gradient(#2b2b32, #0c0c10); width: 26px; height: 62%;
  margin: 0 -13px; z-index: 2; border-radius: 0 0 5px 5px;
}
.key .lbl { position: absolute; bottom: 6px; left: 0; right: 0; text-align: center; font-size: .62rem; color: #8a8a93; pointer-events: none; }
.key.black .lbl { color: #c9c9d2; }
.key.active { filter: brightness(1.05); box-shadow: inset 0 0 0 2px currentColor, 0 0 14px -2px currentColor; }

/* ---- drum pads ---- */
.drumpads { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 12px; }
.pad {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 12px;
  height: 90px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; gap: 6px; font-weight: 600; touch-action: none;
}
.pad .key-hint { font-size: .72rem; color: var(--muted); font-weight: 400; }
.pad.active { box-shadow: inset 0 0 0 2px currentColor, 0 0 16px -3px currentColor; }

.legend { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 12px; }

/* ---- session recorder ---- */
.session { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.session-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.sec-title { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; display: inline-flex; align-items: center; gap: 7px; }
.recdot { width: 10px; height: 10px; border-radius: 50%; background: #6b7280; display: inline-block; }
.recdot.rec { background: #ef4444; box-shadow: 0 0 10px #ef4444; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
#recBtn.armed { color: #fca5a5; border-color: #5b1d1d; }
.recinfo { font-size: .78rem; color: var(--muted); margin-left: auto; font-family: ui-monospace, Menlo, monospace; }

.tracklist { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.trackrow { display: flex; align-items: center; gap: 8px; background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }
.trackrow .tdot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.trackrow .tname { font-size: .85rem; }
.trackrow .tcount { font-size: .72rem; color: var(--muted); margin-left: auto; }
.trackrow .tbtn { padding: 3px 9px; font-size: .75rem; line-height: 1; }
.trackrow .tbtn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.trackrow .tinst { padding: 3px 6px; font-size: .75rem; }
.trackrow .tdel:hover { color: #fca5a5; }

.roll { width: 100%; display: block; background: #0a0e14; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }

/* ---- log ---- */
.logbox {
  height: 110px; overflow-y: auto; background: #0a0e14; border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font-family: ui-monospace, Menlo, monospace; font-size: .76rem; color: var(--muted);
}
.logbox div { margin: 2px 0; }

/* ---- audio gate ---- */
.gate {
  position: fixed; inset: 0; background: #0d1117ee; display: flex; align-items: center; justify-content: center; z-index: 50;
}

@media (max-width: 720px) {
  .main { grid-template-columns: 1fr; }
  .join h1 { font-size: 1.5rem; }
  .keyboard { height: 140px; }
}
